StoreOrderController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <?php
  2. namespace addons\Mch\backend\controllers;
  3. use addons\Mch\common\models\Mch;
  4. use addons\Printer\common\models\Printer;
  5. use common\enums\DownloadEnum;
  6. use common\enums\ExpressEnum;
  7. use common\enums\MarketingTypeEnum;
  8. use common\enums\OrderStatusEnum;
  9. use common\enums\PayTypeEnum;
  10. use common\enums\RefundStatusEnum;
  11. use common\enums\RefundTypeEnum;
  12. use common\enums\ShippingTypeEnum;
  13. use common\enums\StatusEnum;
  14. use common\helpers\csv\CsvExportHelper;
  15. use common\models\common\CapitalLog;
  16. use common\models\common\Express;
  17. use common\models\common\MallSetting;
  18. use common\models\mall\MallAddons;
  19. use common\models\order\Order;
  20. use common\models\order\OrderAction;
  21. use common\models\order\OrderDetail;
  22. use common\models\order\OrderExpress;
  23. use common\models\order\OrderExpressLog;
  24. use common\models\user\User;
  25. use yii\helpers\Json;
  26. use common\models\elasticsearch\order\OrderAction as OrderActionEs;
  27. use common\models\order\OrderRefund;
  28. use common\models\user\UserLevel;
  29. class StoreOrderController extends BaseController
  30. {
  31. /**
  32. * @name:
  33. * @msg: 订单列表
  34. * @param {*}
  35. * @return {*}
  36. */
  37. public function actionIndex()
  38. {
  39. if (!\Yii::$app->request->isAjax) {
  40. return $this->render('/store-order/index');
  41. }
  42. if (\Yii::$app->request->isGet) {
  43. //商品列表筛选
  44. $get = \Yii::$app->request->get();
  45. $order_status_list = OrderStatusEnum::getMap();
  46. $payment_type_list = PayTypeEnum::getMap();
  47. $shipping_type_list = ShippingTypeEnum::getMap();
  48. $rules = [
  49. [['order_status'], 'in', 'range' => array_keys($order_status_list)],
  50. [['payment_type'], 'in', 'range' => array_keys($payment_type_list)],
  51. [['shipping_type'], 'in', 'range' => array_keys($shipping_type_list)],
  52. [['start', 'end'], 'datetime', 'format' => 'php:Y-m-d H:i:s'],
  53. [['order_no', 'mobile', 'order_id', 'marketing_type'], 'safe'],
  54. [['type', 'type_value', 'keyword'], 'string'],
  55. // ['mobile', 'match', 'pattern' => '/^1\d{10}$/', 'message' => '请输入正确的手机号码'],
  56. ];
  57. $res = \Yii::$app->services->validate->validate($get, $rules);
  58. if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  59. // 查询参数
  60. $where[] = ['=', 'mall_id', $this->mall_id];
  61. $where[] = ['>=', 'status', StatusEnum::DISABLED];
  62. $where[] = ['store_id'=>0];
  63. if(isset($get['order_id']))$where[] = ['in', 'id', explode(',',$get['order_id'])];
  64. ($get['payment_type'] ?? false) && $where[] = ['=', 'payment_type', $get['payment_type']];
  65. ($get['shipping_type'] ?? false) && $where[] = ['=', 'shipping_type', $get['shipping_type']];
  66. if(isset($get['order_status'])&&$get['order_status'] != 999){
  67. $where[] = ['=', 'order_status', $get['order_status']];
  68. }
  69. ($get['order_no'] ?? false) && $where[] = ['=', 'order_no', $get['order_no']];
  70. ($get['start'] ?? false) && $where[] = ['>=', 'created_at', strtotime($get['start'])];
  71. ($get['end'] ?? false) && $where[] = ['<=', 'created_at', strtotime($get['end'])];
  72. if($get['type_value'] ?? false){
  73. switch($get['type']){
  74. case 'mobile':
  75. $uids = User::find()->select('id')->where(['like','mobile',$get['type_value'].'%',false])->column();
  76. !empty($uids) && $where[] = ['in', 'user_id', $uids];
  77. break;
  78. case 'user_id':
  79. $where[] = ['in', 'user_id', $get['type_value']];
  80. break;
  81. default:
  82. }
  83. }
  84. $where[]=['!=','mch_id',0];
  85. //查找多商户门店
  86. if (!empty($get['keyword'])) {
  87. $mch_info = Mch::lists([
  88. 'where' => [
  89. ['mall_id' => $this->mall_id],
  90. ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
  91. ['or', ['like', 'store_name', $get['keyword']], ['like', 'shop_mobile', $get['keyword']]],
  92. ],
  93. ]);
  94. if (!empty($mch_info)) {
  95. $mch_ids = array_column($mch_info, 'id');
  96. $where[] = ['mch_id' => $mch_ids];
  97. } else {
  98. $where[] = ['mch_id' => []];
  99. }
  100. }
  101. if (!empty($get['marketing_type'])) {
  102. $where[] = ['marketing_type' => $get['marketing_type']];
  103. }
  104. $with = ['base_user', 'detail', 'mch'];
  105. $order = "id desc";
  106. $params = compact('where', 'with', 'order', 'alias');
  107. $page_data = Order::listPage($params);
  108. if ($page_data === false) return $this->error(Order::getStaticError());
  109. $compact_params = array_keys($page_data);
  110. extract($page_data);
  111. if(MallAddons::isInstall($this->mall_id,'Printer')){
  112. $mch_ids = array_column($page_data['list'],'mch_id');
  113. $printer_list = Printer::lists([
  114. 'where' => [
  115. ['mall_id'=> $this->mall_id],
  116. ['mch_id'=>$mch_ids],
  117. ['printer_type'=>3],
  118. ['status'=>StatusEnum::ENABLED]
  119. ],
  120. 'index'=>'mch_id'
  121. ]);
  122. }
  123. foreach ($list as &$order) {
  124. $order_expresses = OrderExpress::getOrderExpresses([['order_id' => $order['id']]]);
  125. foreach ($order['detail'] as &$detail) {
  126. // 物流信息
  127. $detail['express'] = '';
  128. foreach ($order_expresses as $record) {
  129. $order_detail_ids = empty($record['order_detail_ids']) ? [] : json_decode($record['order_detail_ids'], true);
  130. if (is_string($order_detail_ids)) $order_detail_ids = [];
  131. if (in_array($detail['id'], $order_detail_ids)) {
  132. $detail['express'] = $record['express_name'] . ' | ' . $record['express_no'];
  133. if ($record['shipping_type'] == 0) $detail['express'] = '--';
  134. }
  135. }
  136. }
  137. $order['Printer']['is_show_printer'] = 0;
  138. if(isset($printer_list[$order['mch_id']])){
  139. $order['Printer']['is_show_printer'] = 1;
  140. }
  141. }
  142. $export_list = Order::fieldsList();
  143. $export_list['mch_id'] = '商户名称';
  144. $marketing_type_map = MarketingTypeEnum::getMap();
  145. return $this->success('操作成功', compact($compact_params, 'order_status_list', 'payment_type_list', 'shipping_type_list', 'export_list', 'marketing_type_map'));
  146. }
  147. if(\Yii::$app->request->post('flag') == 'EXPORT'){
  148. $post = \Yii::$app->request->post();
  149. $post['mall_id'] = $this->mall_id;
  150. $post['mch_id'] = -1;
  151. $filename = '商户订单列表-' . date('YmdHis').'_'.rand(10000,99999);
  152. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_ORDERS,Order::class,'exportHandle',$post, 0);
  153. if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError());
  154. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  155. }
  156. }
  157. /**
  158. * @name:
  159. * @msg: 订单详情
  160. * @param {*}
  161. * @return {*}
  162. */
  163. public function actionDetail()
  164. {
  165. if (\Yii::$app->request->isAjax) {
  166. if (\Yii::$app->request->isGet) {
  167. //商品列表筛选
  168. $get = \Yii::$app->request->get();
  169. $order_status_list = OrderStatusEnum::getMap();
  170. $payment_type_list = PayTypeEnum::getMap();
  171. $shipping_type_list = ShippingTypeEnum::getMap();
  172. $rules = [[['id'], 'required']];
  173. $res = \Yii::$app->services->validate->validate($get, $rules);
  174. $where = [['mall_id' => $this->mall_id]];
  175. $where[] = ['=', 'id', $get['id']];
  176. $where[] = ['>=', 'status', StatusEnum::DISABLED];
  177. $with = [
  178. 'base_user',
  179. 'express',
  180. 'express_log',
  181. 'detail'
  182. ];
  183. $params = compact('where', 'with');
  184. $order = Order::getOne($where, true, $with);
  185. if ($order === false) return $this->error(Order::getStaticError());
  186. $express_log = [];
  187. if ($order['express_log']) {
  188. foreach ($order['express_log'] as $item) {
  189. $item['status'] = ExpressEnum::getStatusMap($item['express_status']);
  190. $express_log[$item['order_express_id']] = $item;
  191. }
  192. }
  193. if (!empty($order['express'])) {
  194. foreach ($order['express'] as &$key) {
  195. if (!empty($express_log[$key['id']])) {
  196. $express_list = Json::decode($express_log[$key['id']]['list']);
  197. $key['now_state'] = $express_log[$key['id']]['status'];
  198. $key['express_log'] = is_null($express_list) ? '' : array_reverse($express_list['Traces']);
  199. }
  200. }
  201. }
  202. if (!empty($order['detail'])) {
  203. foreach ($order['detail'] as &$detail) {
  204. if (!empty($detail['attr_groups_format'])) {
  205. $attr_groups_format = json_decode($detail['attr_groups_format'], true);
  206. $attr_list = $attr_groups_format[$detail['sign_id']];
  207. $attr_group_name_list = array_column($attr_list, 'attr_group_name');
  208. $attr_name_list = array_column($attr_list, 'attr_name');
  209. $detail['attr_list'] = [];
  210. foreach ($attr_group_name_list as $index => $attr_group_name) {
  211. $detail['attr_list'][] = $attr_group_name . ':' . $attr_name_list[$index];
  212. }
  213. }
  214. }
  215. }
  216. $temp_step_arr = OrderStatusEnum::setpArrMap($order['order_status']); // 订单状态跟踪
  217. $step_arr = [];
  218. if(!empty($temp_step_arr)){
  219. foreach ($temp_step_arr as $k=>$v){
  220. if(!in_array($v['field'],['deposite_pay_time','final_payment_time'])){
  221. $step_arr[] = $v;
  222. }
  223. }
  224. }
  225. $order_action = OrderAction::getOrderAction([['order_id' => $get['id']]]);
  226. $marketing_type_map = MarketingTypeEnum::getMap();
  227. return $this->success('操作成功', compact('order', 'order_status_list', 'payment_type_list', 'shipping_type_list', 'step_arr', 'order_action', 'marketing_type_map'));
  228. }
  229. }
  230. return $this->render($this->action->id);
  231. }
  232. /**
  233. * @name:
  234. * @msg: 修改订单价格
  235. * @param {*}
  236. * @return {*}
  237. */
  238. public function actionChangePrice()
  239. {
  240. // 商品操作
  241. $form = \Yii::$app->request->post();
  242. $rules = [[['id', 'shipping_money'], 'required'], [['id'], 'integer'], [['shipping_money'], 'number'], ['detail', 'safe']];
  243. $res = \Yii::$app->services->validate->validate($form, $rules);
  244. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  245. $form['mall_id'] = $this->mall['id'];
  246. $form['mch_id'] = $this->admin->mch_id;
  247. $form['operator_id'] = $this->admin->id;
  248. $form['operator_name'] = $this->admin->account;
  249. $res = Order::ChangePrice($form);
  250. if ($res === false) return $this->error(Order::getStaticError());
  251. return $this->success();
  252. }
  253. /**
  254. * @name:
  255. * @msg: 订单支付
  256. * @param {*}
  257. * @return {*}
  258. */
  259. public function actionPay()
  260. {
  261. // 商品操作
  262. $form = \Yii::$app->request->post();
  263. $rules = [[['id'], 'required'], [['id'], 'integer']];
  264. $res = \Yii::$app->services->validate->validate($form, $rules);
  265. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  266. $form['mall_id'] = $this->mall['id'];
  267. $form['mch_id'] = $this->admin->mch_id;
  268. $form['operator_id'] = $this->admin->id;
  269. $form['operator_name'] = $this->admin->account;
  270. $res = Order::pay($form, PayTypeEnum::OFFLINE);
  271. if ($res === false) return $this->error(Order::getStaticError());
  272. return $this->success();
  273. }
  274. /**
  275. * @name:
  276. * @msg: 关闭订单
  277. * @param {*}
  278. * @return {*}
  279. */
  280. public function actionClose()
  281. {
  282. // 商品操作
  283. $form = \Yii::$app->request->post();
  284. $rules = [[['id'], 'required'], [['id'], 'integer']];
  285. $res = \Yii::$app->services->validate->validate($form, $rules);
  286. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  287. $form['mall_id'] = $this->mall['id'];
  288. $form['mch_id'] = $this->admin->mch_id;
  289. $form['operator_id'] = $this->admin->id;
  290. $form['operator_name'] = $this->admin->account;
  291. $res = Order::close($form);
  292. if ($res === false) return $this->error(Order::getStaticError());
  293. return $this->success();
  294. }
  295. public function actionDel()
  296. {
  297. // 商品操作
  298. $form = \Yii::$app->request->post();
  299. $rules = [[['id'], 'required'], [['id'], 'integer']];
  300. $res = \Yii::$app->services->validate->validate($form, $rules);
  301. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  302. $form['mall_id'] = $this->mall_id;
  303. $form['mch_id'] = $this->admin->mch_id;
  304. $form['operator_id'] = $this->admin->id;
  305. $form['operator_name'] = $this->admin->account;
  306. $form['is_admin'] = 1;
  307. $res = Order::del($form);
  308. if ($res === false) return $this->error(Order::getStaticError());
  309. return $this->success();
  310. }
  311. /**
  312. * @name:
  313. * @msg: 修改订单备注
  314. * @param {*}
  315. * @return {*}
  316. */
  317. public function actionRemark()
  318. {
  319. $form = \Yii::$app->request->post();
  320. $rules = [[['id'], 'required'], [['id'], 'integer'], [['remark', 'seller_remark'], 'string']];
  321. $res = \Yii::$app->services->validate->validate($form, $rules);
  322. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  323. $form['mall_id'] = $this->mall['id'];
  324. $form['mch_id'] = $this->admin->mch_id;
  325. $form['operator_id'] = $this->admin->id;
  326. $form['operator_name'] = $this->admin->account;
  327. $res = Order::remark($form);
  328. if ($res === false) return $this->error(Order::getStaticError());
  329. return $this->success();
  330. }
  331. /**
  332. * @name:
  333. * @msg: 修改订单收货地址
  334. * @param {*}
  335. * @return {*}
  336. */
  337. public function actionChangeAddress()
  338. {
  339. $form = \Yii::$app->request->post();
  340. $rules = [
  341. [['id', 'receiver_name', 'mobile', 'province', 'city', 'area', 'address', 'region_name'], 'required'],
  342. [['id', 'province', 'city', 'area', 'zip'], 'integer'],
  343. [['address', 'region_name', 'receiver_name', 'mobile'], 'string']
  344. ];
  345. $res = \Yii::$app->services->validate->validate($form, $rules);
  346. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  347. $form['mall_id'] = $this->mall['id'];
  348. $form['mch_id'] = $this->admin->mch_id;
  349. $form['operator_id'] = $this->admin->id;
  350. $form['operator_name'] = $this->admin->account;
  351. $form['is_admin'] = 1;
  352. $res = Order::changeAddress($form);
  353. if ($res === false) return $this->error(Order::getStaticError());
  354. return $this->success();
  355. }
  356. /**
  357. * @name:
  358. * @msg: 发货
  359. * @param {*}
  360. * @return {*}
  361. */
  362. public function actionShipping()
  363. {
  364. if (\Yii::$app->request->isAjax) {
  365. if (\Yii::$app->request->isGet) {
  366. // 获取订单发货信息
  367. $jd_mch_code = MallSetting::conf($this->mall_id, 'logistics.jd_mch_code');
  368. $express_list = Express::getExpresses([], [], true, '*');
  369. return $this->success('请求成功', compact('express_list', 'jd_mch_code'));
  370. } else {
  371. // 发货
  372. $form = \Yii::$app->request->post();
  373. $rules = [
  374. [['shipping_type', 'id'], 'required'],
  375. [['express_id', 'shipping_type', 'id'], 'integer'],
  376. [['express_name', 'express_no', 'memo'], 'string'],
  377. [['order_detail_ids'], 'each', 'rule' => ['integer']],
  378. [['shipping_change', 'customer_name'], 'safe']
  379. ];
  380. $res = \Yii::$app->services->validate->validate($form, $rules);
  381. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  382. $form['mall_id'] = $this->mall_id;
  383. $form['mch_id'] = $this->admin->mch_id;
  384. $form['operator_id'] = $this->admin->id;
  385. $form['operator_name'] = $this->admin->account;
  386. if (empty($form['shipping_change'])) {
  387. $res = OrderExpress::delivery($form); // 发货
  388. } else {
  389. $res = OrderExpress::shippingChange($form); // 修改物流
  390. }
  391. if ($res === false) return $this->error(OrderExpress::getStaticError());
  392. return $this->success('发货/修改物流成功');
  393. }
  394. }
  395. }
  396. /**
  397. * 收货
  398. * @param $id
  399. * @param string $member_id
  400. * @throws UnprocessableEntityHttpException
  401. * @throws \yii\web\NotFoundHttpException
  402. */
  403. public function actionTakeDelivery()
  404. {
  405. // 商品操作
  406. $form = \Yii::$app->request->post();
  407. $rules = [[['id'], 'required'], [['id'], 'integer']];
  408. $res = \Yii::$app->services->validate->validate($form, $rules);
  409. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  410. $form['mall_id'] = $this->mall['id'];
  411. $form['mch_id'] = $this->admin->mch_id;
  412. $form['operator_id'] = $this->admin->id;
  413. $form['operator_name'] = $this->admin->account;
  414. $res = Order::takeDelivery($form);
  415. if ($res === false) return $this->error(Order::getStaticError());
  416. return $this->success();
  417. }
  418. /**
  419. * @name:
  420. * @msg: 订单操作日志
  421. * @param {*}
  422. * @return {*}
  423. */
  424. public function actionOrderAction()
  425. {
  426. try {
  427. $request = \Yii::$app->request;
  428. if ($request->isAjax) {
  429. if ($request->isGet) {
  430. $params = \Yii::$app->request->get();
  431. $params['where'] = ['mall_id' => $this->mall_id];
  432. $params['is_page'] = true;
  433. $params['order'] = 'created_at desc';
  434. $list = OrderActionEs::getList($params);
  435. return $this->success('ok', $list);
  436. }
  437. }
  438. } catch (\Exception $e) {
  439. return $this->error($e->getMessage(), []);
  440. }
  441. return $this->render($this->action->id);
  442. }
  443. /**
  444. * @name:
  445. * @msg: 订单完成
  446. * @param {*}
  447. * @return {*}
  448. */
  449. public function actionSalesOrder()
  450. {
  451. // 商品操作
  452. $form = \Yii::$app->request->post();
  453. $rules = [[['id'], 'required'], [['id'], 'integer']];
  454. $res = \Yii::$app->services->validate->validate($form, $rules);
  455. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  456. $form['mall_id'] = $this->mall_id;
  457. $form['operator_id'] = $this->admin->id;
  458. $form['operator_name'] = $this->admin->account;
  459. $res = Order::complete($form);
  460. if ($res == false) return $this->error('操作订单失败:' . Order::getStaticError());
  461. return $this->success('操作成功');
  462. }
  463. /**
  464. * @name:
  465. * @msg: 分润明细
  466. * @param {*}
  467. * @return {*}
  468. */
  469. public function actionCommissionAndScoreList()
  470. {
  471. $params = \Yii::$app->request->get();
  472. $wallet_type = 'commission';
  473. if (!empty($params['wallet_type'])) $wallet_type = $params['wallet_type'];
  474. $condition['where'] = [['order_id' => $params['order_id']]];
  475. $condition['select'] = 'id';
  476. $order_detail_list = OrderDetail::lists($condition);
  477. $order_detail_ids = array_column($order_detail_list, 'id');
  478. $condition = [
  479. 'where' => [
  480. ['source_table' => 'order_detail'],
  481. ['source_table_id' => $order_detail_ids]
  482. ],
  483. ];
  484. CapitalLog::$capitalType = "{$wallet_type}";
  485. $list = CapitalLog::getList($condition, 0);
  486. $level = UserLevel::find()->select("name,level")->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])->asArray()->all();
  487. $level_data = array_column($level, 'name', 'level');
  488. CapitalLog::$capitalType = "{$wallet_type}_frozen";
  489. $condition['where'][] = ['status' => 0];
  490. $frozen_list = CapitalLog::getList($condition, 1);
  491. $list = array_merge($list, $frozen_list);
  492. return $this->success('操作成功', ['list' => $list, 'user_level' => $level_data]);
  493. }
  494. /**
  495. * @name:
  496. * @msg: 售后订单列表
  497. * @param {*}
  498. * @return {*}
  499. */
  500. public function actionRefundList()
  501. {
  502. if (!\Yii::$app->request->isAjax) {
  503. return $this->render('/store-order/refund');
  504. }
  505. if (\Yii::$app->request->isGet) {
  506. //商品列表筛选
  507. $get = \Yii::$app->request->get();
  508. $refund_status_list = RefundStatusEnum::getMap();
  509. $refund_type_list = RefundTypeEnum::getMap();
  510. $rules = [
  511. [['is_feedback'], 'integer'],
  512. [['keyword', 'order_no', 'type'], 'string'],
  513. [['type', 'order_no', 'keyword', 'refund_status'], 'safe'],
  514. ];
  515. $res = \Yii::$app->services->validate->validate($get, $rules);
  516. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  517. $where[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED];
  518. $where[] = ['!=', 'mch_id', 0];
  519. // 搜索查询
  520. !empty($get['order_no']) && $where[] = ['in', 'order_id', OrderRefund::getOidByOrderNo($this->mall_id, $get['order_no'])];
  521. if (isset($get['refund_status'])) {
  522. $where[] = ['=', 'refund_status', $get['refund_status']];
  523. } else {
  524. $where[] = ['in', 'refund_status', [RefundStatusEnum::APPLY, RefundStatusEnum::HANDEL, RefundStatusEnum::FINISH, RefundStatusEnum::RETURN_GOODS, RefundStatusEnum::EXCHANGE_GOODS, RefundStatusEnum::REFUSE]];
  525. }
  526. if (!empty($get['type']) && !empty($get['keyword'])) $where[] = OrderRefund::searchByKeyword($this->mall_id, $get['type'], $get['keyword']);
  527. $with = ['base_user', 'orderDetail', 'order'];
  528. $order = "id desc";
  529. $params = compact('where', 'with', 'order');
  530. $page_data = OrderRefund::listPage($params, false, true);
  531. if ($page_data === false) return $this->error(OrderRefund::getStaticError());
  532. $compact_params = array_keys($page_data);
  533. extract($page_data);
  534. foreach ($list as &$order) {
  535. foreach ($order['orderDetail'] as &$detail) {
  536. if (!empty($detail['attr_groups_format'])) {
  537. //规格
  538. $attr_groups_format = Json::decode($detail['attr_groups_format'], true);
  539. $attr_list = $attr_groups_format[$detail['sign_id']];
  540. $attr_group_name_list = array_column($attr_list, 'attr_group_name');
  541. $attr_name_list = array_column($attr_list, 'attr_name');
  542. $detail['attr_list'] = [];
  543. foreach ($attr_group_name_list as $index => $attr_group_name) {
  544. $detail['attr_list'][] = $attr_group_name . ':' . $attr_name_list[$index];
  545. }
  546. }
  547. }
  548. }
  549. return $this->success('操作成功', compact($compact_params, 'refund_status_list', 'refund_type_list'));
  550. }
  551. }
  552. /**
  553. * @name:
  554. * @msg: 售后订单详情
  555. * @param {*}
  556. * @return {*}
  557. */
  558. public function actionRefundDetail()
  559. {
  560. if (\Yii::$app->request->isAjax) {
  561. if (\Yii::$app->request->isGet) {
  562. //商品列表筛选
  563. $get = \Yii::$app->request->get();
  564. $order_status_list = OrderStatusEnum::getMap();
  565. $payment_type_list = PayTypeEnum::getMap();
  566. $feedback_type_list = OrderStatusEnum::getFeedbackMap();
  567. $address_list = \Yii::$app->services->setting->mall->get($this->mall_id, 'return_address.return_address');
  568. $address_list = $address_list ? json_decode($address_list, true) : [];
  569. $rules = [[['id'], 'required']];
  570. $res = \Yii::$app->services->validate->validate($get, $rules);
  571. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  572. $where = [['mall_id' => $this->mall_id]];
  573. $where[] = ['id' => $get['id']];
  574. $where[] = ['>=', 'status', StatusEnum::DISABLED];
  575. $with = ['base_user', 'order', 'orderDetail', 'marketing', 'step'];
  576. $refund = OrderRefund::getOne($where, true, $with);
  577. if ($refund === false) return $this->error(OrderRefund::getStaticError());
  578. foreach ($refund['orderDetail'] as $key => $detail) {
  579. if (!empty($detail['attr_groups_format'])) {
  580. $attr_groups_format = Json::decode($detail['attr_groups_format'], true);
  581. $attr_list = $attr_groups_format[$detail['sign_id']];
  582. $attr_group_name_list = array_column($attr_list, 'attr_group_name');
  583. $attr_name_list = array_column($attr_list, 'attr_name');
  584. $detail['attr_list'] = [];
  585. }
  586. }
  587. // 返还优惠内容
  588. if (!empty($refund['marketing'])) {
  589. $discount = [];
  590. $marketing = $refund['marketing'];
  591. if (!empty($marketing['deduct_score'])) {
  592. $score_name = \Yii::$app->services->setting->mall->get($this->mall_id, 'score.score_name');
  593. $discount[] = floatval($marketing['deduct_score']) . $score_name;
  594. }
  595. $refund['discount'] = implode('+', $discount);
  596. }
  597. $step_status = $refund['step'][0]['step_status'] ?? 0;
  598. $step_arr = RefundStatusEnum::stepNumArr(in_array($step_status, [RefundStatusEnum::STEP_NEGATIVE_1, RefundStatusEnum::STEP_NEGATIVE_2]) ? 1 : $refund['type']); // 进度条
  599. $step_text = RefundStatusEnum::getStepStatusText($step_status);
  600. return $this->success('操作成功', compact('refund', 'order_status_list', 'payment_type_list', 'feedback_type_list', 'step_arr', 'address_list', 'step_text'));
  601. }
  602. }
  603. return $this->render('/store-order/refund-detail');
  604. }
  605. }