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