Sellerrefund.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 Sellerrefund extends BaseSeller
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerrefund.lang.php');
  18. $this->getRefundStateArray();
  19. }
  20. /**
  21. * 退款记录列表页
  22. *
  23. */
  24. public function index()
  25. {
  26. $refundreturn_model = model('refundreturn');
  27. $condition = array();
  28. $condition[] = array('store_id', '=', session('store_id'));
  29. $condition[] = array('refund_type', '=', '1'); //类型:1为退款,2为退货
  30. $keyword_type = array('order_sn', 'refund_sn', 'buyer_name');
  31. $key = input('key');
  32. $type = input('type');
  33. if (trim($key) != '' && in_array($type, $keyword_type)) {
  34. $condition[] = array($type, 'like', '%' . $key . '%');
  35. }
  36. $add_time_from = input('add_time_from');
  37. $add_time_to = input('add_time_to');
  38. if (trim($add_time_from) != '') {
  39. $add_time_from = strtotime($add_time_from);
  40. if ($add_time_from !== false) {
  41. $condition[] = array('add_time', '>=', $add_time_from);
  42. }
  43. }
  44. if (trim($add_time_to) != '') {
  45. $add_time_to = strtotime($add_time_to) + 86399;
  46. if ($add_time_to !== false) {
  47. $condition[] = array('add_time', '<=', $add_time_to);
  48. }
  49. }
  50. $seller_state = intval(input('state'));
  51. if ($seller_state > 0) {
  52. $condition[] = array('seller_state', '=', $seller_state);
  53. }
  54. $order_lock = intval(input('lock'));
  55. if ($order_lock != 1) {
  56. $order_lock = 2;
  57. }
  58. $condition[] = array('order_lock', '=', $order_lock);
  59. $refund_list = $refundreturn_model->getRefundList($condition, 10);
  60. $page = $refundreturn_model->page_info->render();
  61. View::assign('refund_list', $refund_list);
  62. View::assign('show_page', $page);
  63. /* 设置卖家当前菜单 */
  64. $this->setSellerCurMenu('seller_refund');
  65. /* 设置卖家当前栏目 */
  66. $this->setSellerCurItem($order_lock);
  67. return View::fetch($this->template_dir . 'index');
  68. }
  69. /**
  70. * 退款审核页
  71. *
  72. */
  73. public function edit()
  74. {
  75. $refundreturn_model = model('refundreturn');
  76. $condition = array();
  77. $condition[] = array('store_id', '=', session('store_id'));
  78. $condition[] = array('refund_id', '=', intval(input('param.refund_id')));
  79. $condition[] = array('refund_type', '=', 1);
  80. $refund_list = $refundreturn_model->getRefundList($condition);
  81. $refund = $refund_list[0];
  82. if (!request()->isPost()) {
  83. View::assign('refund', $refund);
  84. $info['buyer'] = array();
  85. if (!empty($refund['pic_info'])) {
  86. $info = unserialize($refund['pic_info']);
  87. }
  88. View::assign('pic_list', $info['buyer']);
  89. $member_model = model('member');
  90. $member = $member_model->getMemberInfoByID($refund['buyer_id']);
  91. View::assign('member', $member);
  92. $condition = array();
  93. $condition[] = array('order_id', '=', $refund['order_id']);
  94. $order = $refundreturn_model->getRightOrderList($condition, $refund['order_goods_id']);
  95. View::assign('order', $order);
  96. View::assign('store', $order['extend_store']);
  97. View::assign('order_common', $order['extend_order_common']);
  98. View::assign('goods_list', $order['goods_list']);
  99. /* 设置卖家当前菜单 */
  100. $this->setSellerCurMenu('seller_refund');
  101. /* 设置卖家当前栏目 */
  102. $this->setSellerCurItem('');
  103. return View::fetch($this->template_dir . 'edit');
  104. } else {
  105. if ($refund['seller_state'] != '1') { //检查状态,防止页面刷新不及时造成数据错误
  106. ds_json_encode(10001, lang('param_error'));
  107. }
  108. $order_id = $refund['order_id'];
  109. $refund_array = array();
  110. $refund_array['seller_time'] = TIMESTAMP;
  111. $refund_array['seller_state'] = input('post.seller_state'); //卖家处理状态:1为待审核,2为同意,3为不同意
  112. $refund_array['seller_message'] = input('post.seller_message');
  113. if ($refund_array['seller_state'] == '3') {
  114. $refund_array['refund_state'] = '3'; //状态:1为处理中,2为待管理员处理,3为已完成
  115. } else {
  116. $refund_array['seller_state'] = '2';
  117. $refund_array['refund_state'] = '2';
  118. }
  119. $state = $refundreturn_model->editRefundreturn($condition, $refund_array);
  120. if ($state) {
  121. if ($refund_array['seller_state'] == '3') {
  122. if ($refund['order_lock'] == '2') {
  123. $refundreturn_model->editOrderUnlock($order_id); //订单解锁
  124. }
  125. //自提点订单解锁
  126. $chain_order_model = model('chain_order');
  127. $chain_order_model->editChainOrderUnlock($order_id);
  128. }
  129. $this->recordSellerlog(lang('refund_processing') . $refund['refund_sn']);
  130. // 发送买家消息
  131. $param = array();
  132. $param['code'] = 'refund_return_notice';
  133. $param['member_id'] = $refund['buyer_id'];
  134. $param['ali_param'] = array(
  135. 'refund_sn' => $refund['refund_sn']
  136. );
  137. $param['ten_param'] = array(
  138. $refund['refund_sn']
  139. );
  140. $param['param'] = array_merge($param['ali_param'], array(
  141. 'refund_url' => HOME_SITE_URL . '/Memberrefund/view?refund_id=' . $refund['refund_id'],
  142. ));
  143. //微信模板消息
  144. $param['weixin_param'] = array(
  145. 'url' => config('ds_config.h5_site_url') . '/pages/member/' . ($refund['refund_type'] == 1 ? 'refund/RefundView' : 'return/ReturnView') . '?refund_id=' . $refund['refund_id'],
  146. 'data' => array(
  147. "keyword1" => array(
  148. "value" => $refund['order_sn'],
  149. "color" => "#333"
  150. ),
  151. "keyword2" => array(
  152. "value" => $refund['refund_amount'],
  153. "color" => "#333"
  154. )
  155. ),
  156. );
  157. model('cron')->addCron(array('cron_exetime' => TIMESTAMP, 'cron_type' => 'sendMemberMsg', 'cron_value' => serialize($param)));
  158. ds_json_encode(10000, lang('ds_common_save_succ'));
  159. } else {
  160. ds_json_encode(10001, lang('ds_common_save_fail'));
  161. }
  162. }
  163. }
  164. /**
  165. * 退款记录查看页
  166. *
  167. */
  168. public function view()
  169. {
  170. $refundreturn_model = model('refundreturn');
  171. $condition = array();
  172. $condition[] = array('refund_type', '=', 1);
  173. $condition[] = array('store_id', '=', session('store_id'));
  174. $condition[] = array('refund_id', '=', intval(input('param.refund_id')));
  175. $refund_list = $refundreturn_model->getRefundList($condition);
  176. $refund = $refund_list[0];
  177. View::assign('refund', $refund);
  178. $info['buyer'] = array();
  179. if (!empty($refund['pic_info'])) {
  180. $info = unserialize($refund['pic_info']);
  181. }
  182. View::assign('pic_list', $info['buyer']);
  183. $member_model = model('member');
  184. $member = $member_model->getMemberInfoByID($refund['buyer_id']);
  185. View::assign('member', $member);
  186. $condition = array();
  187. $condition[] = array('order_id', '=', $refund['order_id']);
  188. $order = $refundreturn_model->getRightOrderList($condition, $refund['order_goods_id']);
  189. View::assign('order', $order);
  190. View::assign('store', $order['extend_store']);
  191. View::assign('order_common', $order['extend_order_common']);
  192. View::assign('goods_list', $order['goods_list']);
  193. /* 设置卖家当前菜单 */
  194. $this->setSellerCurMenu('seller_refund');
  195. /* 设置卖家当前栏目 */
  196. $this->setSellerCurItem('');
  197. return View::fetch($this->template_dir . 'view');
  198. }
  199. function getRefundStateArray($type = 'all')
  200. {
  201. $state_array = array(
  202. '1' => lang('refund_state_confirm'),
  203. '2' => lang('refund_state_yes'),
  204. '3' => lang('refund_state_no')
  205. ); //卖家处理状态:1为待审核,2为同意,3为不同意
  206. View::assign('state_array', $state_array);
  207. $admin_array = array(
  208. '1' => lang('in_processing'),
  209. '2' => lang('to_processed'),
  210. '3' => lang('has_been_completed'),
  211. '4' => lang('refund_state_no')
  212. ); //确认状态:1为买家或卖家处理中,2为待平台管理员处理,3为退款退货已完成
  213. View::assign('admin_array', $admin_array);
  214. $state_data = array(
  215. 'seller' => $state_array,
  216. 'admin' => $admin_array
  217. );
  218. if ($type == 'all') {
  219. return $state_data; //返回所有
  220. }
  221. return $state_data[$type];
  222. }
  223. /**
  224. * 用户中心右边,小导航
  225. *
  226. * @param string $menu_type 导航类型
  227. * @param string $menu_key 当前导航的menu_key
  228. * @return
  229. */
  230. function getSellerItemList()
  231. {
  232. $menu_array = array(
  233. array(
  234. 'name' => '2',
  235. 'text' => lang('before_refund'),
  236. 'url' => (string) url('Sellerrefund/index', ['lock' => 2])
  237. ),
  238. array(
  239. 'name' => '1',
  240. 'text' => lang('after_refund'),
  241. 'url' => (string) url('Sellerrefund/index', ['lock' => 1])
  242. ),
  243. );
  244. return $menu_array;
  245. }
  246. }