ScratchOrderController.php 31 KB

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