Membervrrefund.php 7.5 KB

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