Membervrrefund.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Membervrrefund extends BaseMember
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize(); // TODO: Change the autogenerated stub
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberrefund.lang.php');
  18. $this->getRefundStateArray();
  19. }
  20. /**
  21. * 向模板页面输出退款状态
  22. *
  23. * @param
  24. * @return array
  25. */
  26. public function getRefundStateArray($type = 'all')
  27. {
  28. $admin_array = array(
  29. '1' => lang('refund_state_confirm'),
  30. '2' => lang('refund_state_yes'),
  31. '3' => lang('refund_state_no')
  32. ); //退款状态:1为待审核,2为同意,3为不同意
  33. View::assign('admin_array', $admin_array);
  34. $state_data = array(
  35. 'admin' => $admin_array
  36. );
  37. if ($type == 'all')
  38. return $state_data; //返回所有
  39. return $state_data[$type];
  40. }
  41. /**
  42. * 添加兑换码退款
  43. *
  44. */
  45. public function add_refund()
  46. {
  47. $vrrefund_model = model('vrrefund');
  48. $order_id = intval(input('param.order_id'));
  49. if ($order_id < 1) { //参数验证
  50. ds_json_encode(10001, lang('param_error'));
  51. }
  52. $condition = array();
  53. $condition[] = array('buyer_id', '=', session('member_id'));
  54. $condition[] = array('order_id', '=', $order_id);
  55. $order_info = $vrrefund_model->getRightVrorderList($condition, $order_id);
  56. View::assign('store', $order_info['store']);
  57. View::assign('code_list', $order_info['code_list']);
  58. $order = $order_info['order_info'];
  59. View::assign('order', $order);
  60. if (!$order['if_refund']) { //检查状态,防止页面刷新不及时造成数据错误
  61. ds_json_encode(10001, lang('param_error'));
  62. }
  63. if (request()->isPost() && $order['if_refund']) {
  64. $code_list = $order['code_list'];
  65. $refund_array = array();
  66. $goods_num = 0; //兑换码数量
  67. $refund_amount = 0; //退款金额
  68. $redeemcode_sn = '';
  69. $rec_id_array = input('post.rec_id/a');
  70. if (!empty($rec_id_array) && is_array($rec_id_array)) { //选择退款的兑换码
  71. foreach ($rec_id_array as $key => $value) {
  72. $code = $code_list[$value];
  73. if (!empty($code)) {
  74. $goods_num += 1;
  75. $refund_amount += $code['pay_price']; //实际支付金额
  76. $redeemcode_sn .= $code['vr_code'] . ','; //兑换码编号
  77. }
  78. }
  79. }
  80. if ($goods_num < 1) {
  81. ds_json_encode(10001, lang('param_error'));
  82. }
  83. $refund_array['redeemcode_sn'] = rtrim($redeemcode_sn, ',');
  84. $refund_array['admin_state'] = '1'; //状态:1为待审核,2为同意,3为不同意
  85. $refund_array['refund_amount'] = ds_price_format($refund_amount);
  86. $refund_array['goods_num'] = $goods_num;
  87. $refund_array['buyer_message'] = input('post.buyer_message');
  88. $refund_array['add_time'] = TIMESTAMP;
  89. $state = $vrrefund_model->addVrrefund($refund_array, $order);
  90. if ($state) {
  91. ds_json_encode(10000, lang('ds_common_save_succ'));
  92. } else {
  93. ds_json_encode(10001, lang('ds_common_save_fail'));
  94. }
  95. } else {
  96. $this->setMemberCurMenu('member_refund');
  97. $this->setMemberCurItem('add_refund');
  98. return View::fetch($this->template_dir . 'member_vr_refund_add');
  99. }
  100. }
  101. /**
  102. * 退款记录列表页
  103. *
  104. */
  105. public function index()
  106. {
  107. $condition = array();
  108. $condition[] = array('buyer_id', '=', session('member_id'));
  109. $keyword_type = array('order_sn', 'refund_sn', 'goods_name');
  110. if (trim(input('param.key')) != '' && in_array(input('param.type'), $keyword_type)) {
  111. $type = input('param.type');
  112. $condition[] = array($type, 'like', '%' . input('param.key') . '%');
  113. }
  114. if (trim(input('param.add_time_from')) != '') {
  115. $add_time_from = strtotime(input('param.add_time_from'));
  116. if ($add_time_from !== false) {
  117. $condition[] = array('add_time', '>=', $add_time_from);
  118. }
  119. }
  120. if (trim(input('param.add_time_to')) != '') {
  121. $add_time_to = strtotime(input('param.add_time_to'));
  122. if ($add_time_to !== false) {
  123. $add_time_to = $add_time_to + 86399;
  124. $condition[] = array('add_time', '<=', $add_time_to);
  125. }
  126. }
  127. $vrrefund_model = model('vrrefund');
  128. $refund_list = $vrrefund_model->getVrrefundList($condition, 10);
  129. View::assign('refund_list', $refund_list);
  130. View::assign('show_page', $vrrefund_model->page_info->render());
  131. $store_list = $vrrefund_model->getVrrefundStoreList($refund_list);
  132. View::assign('store_list', $store_list);
  133. $this->setMemberCurItem('buyer_vr_refund');
  134. $this->setMemberCurMenu('membervrrefund');
  135. return View::fetch($this->template_dir . 'member_vr_refund');
  136. }
  137. /**
  138. * 退款记录查看
  139. *
  140. */
  141. public function view()
  142. {
  143. $vrrefund_model = model('vrrefund');
  144. $condition = array();
  145. $condition[] = array('buyer_id', '=', session('member_id'));
  146. $condition[] = array('refund_id', '=', intval(input('param.refund_id')));
  147. $refund_list = $vrrefund_model->getVrrefundList($condition);
  148. $refund = $refund_list[0];
  149. View::assign('refund', $refund);
  150. $code_array = explode(',', $refund['redeemcode_sn']);
  151. View::assign('code_array', $code_array);
  152. $condition = array();
  153. $condition[] = array('order_id', '=', $refund['order_id']);
  154. $order_info = $vrrefund_model->getRightVrorderList($condition, $refund['order_id']);
  155. View::assign('store', $order_info['store']);
  156. View::assign('code_list', $order_info['code_list']);
  157. View::assign('order', $order_info['order_info']);
  158. $this->setMemberCurMenu('membervrrefund');
  159. $this->setMemberCurItem('view');
  160. return View::fetch($this->template_dir . 'member_vr_refund_view');
  161. }
  162. protected function getMemberItemList()
  163. {
  164. $menu_array = array(
  165. array(
  166. 'name' => 'buyer_refund', 'text' => lang('ds_member_path_buyer_refund'),
  167. 'url' => (string)url('Memberrefund/index')
  168. ), array(
  169. 'name' => 'buyer_return', 'text' => lang('ds_member_path_buyer_return'),
  170. 'url' => (string)url('Memberreturn/index')
  171. ), array(
  172. 'name' => 'buyer_vr_refund', 'text' => lang('refund_virtual_currency_code'), 'url' => (string)url('Membervrrefund/index')
  173. )
  174. );
  175. return $menu_array;
  176. }
  177. }