Membervrrefund.php 7.7 KB

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