LocalDeliveryController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers;
  8. use app\constants\OptionSetting;
  9. use app\jobs\LgCashJob;
  10. use app\models\Cash;
  11. use app\models\DeliveryInfo;
  12. use app\models\District;
  13. use app\models\Lg;
  14. use app\models\LocalDeliveryCash;
  15. use app\models\LocalDeliveryCourier;
  16. use app\models\LocalDeliveryCourierComment;
  17. use app\models\LocalDeliveryCourierCommentExt;
  18. use app\models\LocalDeliveryCourierTag;
  19. use app\models\LocalDeliveryLog;
  20. use app\models\Option;
  21. use app\models\Order;
  22. use app\models\Store;
  23. use app\models\User;
  24. use app\models\WechatConfig;
  25. use app\modules\admin\models\CourierForm;
  26. use app\modules\admin\models\DeliveryOrderForm;
  27. use app\modules\admin\models\FreightForm;
  28. use app\utils\Alipay\Alipay;
  29. use app\utils\LgApi;
  30. use app\utils\Notice\NoticeSend;
  31. use Spatie\SimpleExcel\SimpleExcelWriter;
  32. use yii\helpers\Json;
  33. /**
  34. * @file LocalDeliveryController
  35. * @editor Created by vscode
  36. * @author WPing丶
  37. * @date 2023/06/29
  38. * @time 09:14:30
  39. *
  40. * 备注:同城配送
  41. */
  42. class LocalDeliveryController extends BaseController
  43. {
  44. /**
  45. * 模块名:actionGetCourier
  46. * 代码描述:获取配送员列表
  47. * 作者:WPing丶
  48. * 请求方式:GET
  49. * 创建时间:2023/06/29 9:15:54
  50. * @param int id
  51. * @param string str
  52. * @param bool bool
  53. */
  54. public function actionGetCourier()
  55. {
  56. $param = get_params();
  57. $form = new CourierForm();
  58. $form->scenario = $form::SCENARIO_LIST;
  59. $form->attributes = $param;
  60. return $this->asJson($form->searchCourier());
  61. }
  62. /**
  63. * 模块名:actionAddCourier
  64. * 代码描述:新增配送员
  65. * 作者:WPing丶
  66. * 请求方式:GET
  67. * 创建时间:2023/06/25 15:51:06
  68. * @param int id
  69. * @param string str
  70. * @param bool bool
  71. */
  72. public function actionAddCourier()
  73. {
  74. $param = post_params();
  75. $form = new CourierForm();
  76. $form->scenario = $form::SCENARIO_ADD;
  77. $form->attributes = $param;
  78. $res = $form->saveCourier();
  79. return $this->asJson($res);
  80. }
  81. /**
  82. * 模块名:actionEditCourier
  83. * 代码描述:编辑配送员
  84. * 作者:WPing丶
  85. * 请求方式:GET
  86. * 创建时间:2023/06/25 14:27:38
  87. * @param int id
  88. * @param string str
  89. * @param bool bool
  90. */
  91. public function actionEditCourier()
  92. {
  93. $param = post_params();
  94. $form = new CourierForm();
  95. $form->scenario = $form::SCENARIO_EDIT;
  96. $form->attributes = $param;
  97. $res = $form->saveCourier();
  98. return $this->asJson($res);
  99. }
  100. /**
  101. * 模块名:actionDelCourier
  102. * 代码描述:删除配送员
  103. * 作者:WPing丶
  104. * 请求方式:GET
  105. * 创建时间:2023/06/25 19:59:22
  106. * @param int id
  107. * @param string str
  108. * @param bool bool
  109. */
  110. public function actionDelCourier()
  111. {
  112. //主键id用key标识并进行获取
  113. $param = get_params('key');
  114. $form = new CourierForm();
  115. $form->scenario = $form::SCENARIO_DEL;
  116. $form->id = $param;
  117. $res = $form->delCourier();
  118. return $this->asJson($res);
  119. }
  120. /**
  121. * 模块名:actionDelCourier
  122. * 代码描述:审核配送员
  123. * 作者:WPing丶
  124. * 请求方式:GET
  125. * 创建时间:2023/06/25 19:59:22
  126. * @param int id
  127. * @param string str
  128. * @param bool bool
  129. */
  130. public function actionApplyCourier()
  131. {
  132. //主键id用key标识并进行获取
  133. $param = get_params('key');
  134. $state = get_params('state');
  135. $form = new CourierForm();
  136. // $form->scenario = $form::SCENARIO_APPLY;
  137. $form->id = $param;
  138. $form->state = $state;
  139. $res = $form->applyCourier();
  140. return $this->asJson($res);
  141. }
  142. /**
  143. * 模块名:actionGetFreight
  144. * 代码描述:获取计价规则列表
  145. * 作者:WPing丶
  146. * 请求方式:GET
  147. * 创建时间:2023/06/29 9:15:54
  148. * @param int id
  149. * @param string str
  150. * @param bool bool
  151. */
  152. public function actionGetFreight()
  153. {
  154. $param = get_params();
  155. $form = new FreightForm();
  156. $form->scenario = $form::SCENARIO_LIST;
  157. $form->attributes = $param;
  158. $form->store_id = get_store_id();
  159. return $this->asJson($form->searchFreight(input_params('type', 0)));
  160. }
  161. /**
  162. * 模块名:actionAddFreight
  163. * 代码描述:新增计价规则
  164. * 作者:WPing丶
  165. * 请求方式:GET
  166. * 创建时间:2023/06/25 15:51:06
  167. * @param int id
  168. * @param string str
  169. * @param bool bool
  170. */
  171. public function actionAddFreight()
  172. {
  173. $param = post_params();
  174. $form = new FreightForm();
  175. $form->scenario = $form::SCENARIO_ADD;
  176. $form->attributes = $param;
  177. $form->store_id = get_store_id();
  178. $res = $form->saveFreight(input_params('type', 0));
  179. return $this->asJson($res);
  180. }
  181. /**
  182. * 模块名:actionEditFreight
  183. * 代码描述:编辑计价规则
  184. * 作者:WPing丶
  185. * 请求方式:GET
  186. * 创建时间:2023/06/25 14:27:38
  187. * @param int id
  188. * @param string str
  189. * @param bool bool
  190. */
  191. public function actionEditFreight()
  192. {
  193. $param = post_params();
  194. $form = new FreightForm();
  195. $form->scenario = $form::SCENARIO_EDIT;
  196. $form->attributes = $param;
  197. $form->store_id = get_store_id();
  198. $res = $form->saveFreight(input_params('type', 0));
  199. return $this->asJson($res);
  200. }
  201. /**
  202. * 模块名:actionDelFreight
  203. * 代码描述:删除计价规则
  204. * 作者:WPing丶
  205. * 请求方式:GET
  206. * 创建时间:2023/06/25 19:59:22
  207. * @param int id
  208. * @param string str
  209. * @param bool bool
  210. */
  211. public function actionDelFreight()
  212. {
  213. //主键id用key标识并进行获取
  214. $param = get_params('key');
  215. $form = new FreightForm();
  216. $form->scenario = $form::SCENARIO_DEL;
  217. $form->id = $param;
  218. $res = $form->delFreight();
  219. return $this->asJson($res);
  220. }
  221. /**
  222. * 模块名:actionDelFreight
  223. * 代码描述:启用or关闭计价规则
  224. * 作者:WPing丶
  225. * 请求方式:GET
  226. * 创建时间:2023/06/25 19:59:22
  227. * @param int id
  228. * @param string str
  229. * @param bool bool
  230. */
  231. public function actionApplyFreight()
  232. {
  233. //主键id用key标识并进行获取
  234. $param = get_params('key');
  235. $is_enable = get_params('is_enable');
  236. $is_scan = get_params('is_scan');
  237. $form = new FreightForm();
  238. // $form->scenario = $form::SCENARIO_APPLY;
  239. $form->id = $param;
  240. $form->is_enable = $is_enable;
  241. $form->is_scan = $is_scan;
  242. $res = $form->applyFreight();
  243. return $this->asJson($res);
  244. }
  245. /**
  246. * 模块名:actionSetting
  247. * 代码描述:基础设置
  248. * 作者:WPing丶
  249. * 请求方式:GET
  250. * 创建时间:2023/07/01 10:48:17
  251. * @param int id
  252. * @param string str
  253. * @param bool bool
  254. */
  255. public function actionGetSetting()
  256. {
  257. $store_id = get_store_id();
  258. $values = Option::find()->where([
  259. 'store_id' => $store_id,
  260. 'group' => OptionSetting::LOCAL_DELIVERY_GROUP_NAME, 'name' => OptionSetting::LOCAL_DELIVERY_SETTING
  261. ])->select('value')->One();
  262. if ($values) {
  263. $data = json_decode($values->value, true);
  264. } else {
  265. $data = null;
  266. }
  267. return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $data]);
  268. }
  269. /**
  270. * 模块名:actionSetSetting
  271. * 代码描述:编辑基础设置
  272. * 作者:WPing丶
  273. * 请求方式:GET
  274. * 创建时间:2023/07/01 10:48:17
  275. * @param int id
  276. * @param string str
  277. * @param bool bool
  278. */
  279. public function actionSetSetting($store_id = 0)
  280. {
  281. $store_id = $store_id ?: get_store_id();
  282. $localDeliveryOption = Option::findOne([
  283. 'store_id' => $store_id, 'group' => OptionSetting::LOCAL_DELIVERY_GROUP_NAME,
  284. 'name' => OptionSetting::LOCAL_DELIVERY_SETTING
  285. ]);
  286. if (!$localDeliveryOption) {
  287. $localDeliveryOption = new Option();
  288. }
  289. $data = post_params();
  290. if (!is_numeric($data['min_money']) || !is_numeric($data['cash_max_day'])) {
  291. return $this->asJson(['code' => 1, 'msg' => '金额字段请输入数字']);
  292. }
  293. $data = [
  294. 'send_type' => [
  295. 'text' => '发单方式',
  296. 'value' => $data['send_type']
  297. ],
  298. 'delivery_type' => [
  299. 'text' => '骑手绑定模式',
  300. 'value' => 'store'//$data['delivery_type']
  301. ],
  302. 'default_time' => [
  303. 'text' => '配送默认时间',
  304. 'value' => $data['default_time']
  305. ],
  306. 'default_cost' => [
  307. 'text' => '骑手佣金',
  308. 'value' => $data['default_cost']
  309. ],
  310. 'pay_type' => [
  311. 'text' => '提现方式',
  312. 'value' => $data['pay_type']
  313. ],
  314. 'min_money' => [
  315. 'text' => '最小提现额度',
  316. 'value' => $data['min_money']
  317. ],
  318. 'cash_max_day' => [
  319. 'text' => '每天最大提现额度',
  320. 'value' => $data['cash_max_day']
  321. ],
  322. 'cash_service_charge' => [
  323. 'text' => '提现手续费',
  324. 'value' => floatval($data['cash_service_charge'])
  325. ],
  326. 'confirm_type' => [
  327. 'text' => '送达即签收',
  328. 'value' => $data['confirm_type']
  329. ],
  330. ];
  331. //商盟固定store_id
  332. $localDeliveryOption->store_id = $store_id;
  333. $localDeliveryOption->group = OptionSetting::LOCAL_DELIVERY_GROUP_NAME;
  334. $localDeliveryOption->name = OptionSetting::LOCAL_DELIVERY_SETTING;
  335. $localDeliveryOption->value = json_encode($data);
  336. if (!$localDeliveryOption->isNewRecord) {
  337. $localDeliveryOption->updated_at = time();
  338. }
  339. if (!$localDeliveryOption->save()) {
  340. foreach ($localDeliveryOption->errors as $error) {
  341. return $this->asJson([
  342. 'code' => 1,
  343. 'msg' => $error,
  344. ]);
  345. }
  346. }
  347. return $this->asJson([
  348. 'code' => 0,
  349. 'msg' => '保存成功'
  350. ]);
  351. }
  352. /**
  353. * 模块名:actionGetOrderList
  354. * 代码描述:获取同城订单列表
  355. * 作者:WPing丶
  356. * 请求方式:GET
  357. * 创建时间:2023/07/05 14:25:32
  358. */
  359. public function actionGetOrderList()
  360. {
  361. $param = get_params();
  362. $form = new DeliveryOrderForm();
  363. $form->attributes = $param;
  364. return $this->asJson($form->search());
  365. }
  366. /**
  367. * 模块名:actionSendOrder
  368. * 代码描述:订单分配配送员
  369. * 作者:WPing丶
  370. * 请求方式:GET
  371. * 创建时间:2023/07/06 09:23:59
  372. */
  373. public function actionSendOrder()
  374. {
  375. $order_id = get_params('order_id'); //订单ID
  376. $rider_id = get_params('rider_id'); //骑手ID
  377. $courier = LocalDeliveryCourier::findOne(['id' => $rider_id, 'is_delete' => 0, 'state' => 2, 'status' => 1]);
  378. if (!$courier) {
  379. return $this->asJson([
  380. 'code' => 1,
  381. 'msg' => '骑手不存在或已离线,请重新选择',
  382. ]);
  383. }
  384. $now_num = DeliveryInfo::find()->alias('di')
  385. ->leftJoin(['o' => Order::tableName()], 'di.order_no = o.order_no')
  386. ->where(['o.trade_status' => 2, 'is_local' => 1, 'rider_id' => $rider_id])
  387. ->count();
  388. if ($courier->max_num != 0 && $now_num >= $courier->max_num) {
  389. return $this->asJson([
  390. 'code' => 1,
  391. 'msg' => '骑手(' . $courier->real_name . ')当前配送订单已达到上限,请分配其他骑手',
  392. ]);
  393. }
  394. $t = \Yii::$app->db->beginTransaction(); //开始事务
  395. $order = Order::findOne($order_id);
  396. $delivery_info = DeliveryInfo::findOne(['order_no' => $order->order_no]);
  397. $delivery_info->rider_id = $rider_id;
  398. $delivery_info->rider_name = $courier->real_name;
  399. $delivery_info->rider_mobile = $courier->mobile;
  400. $delivery_info->local_status = DeliveryInfo::LOCAL_STATUS_WAITING;
  401. if (!$delivery_info->save()) {
  402. $t->rollBack(); //事务回滚
  403. return $this->asJson([
  404. 'code' => 1,
  405. 'msg' => current($delivery_info->getFirstErrors()),
  406. ]);
  407. }
  408. $order->send_time = time();
  409. $order->trade_status = 2;
  410. if (!$order->save()) {
  411. $t->rollBack(); //事务回滚
  412. return $this->asJson([
  413. 'code' => 1,
  414. 'msg' => current($delivery_info->getFirstErrors()),
  415. ]);
  416. }
  417. $t->commit(); //事务执行
  418. return $this->asJson([
  419. 'code' => 0,
  420. 'msg' => '操作成功',
  421. ]);
  422. }
  423. /**
  424. * 模块名:actionCashList
  425. * 代码描述:提现记录
  426. * 作者:WPing丶
  427. * 请求方式:POST
  428. * 创建时间:2023/07/11 11:04:47
  429. * @param int id
  430. * @param string str
  431. * @param bool bool
  432. */
  433. public function actionCashList()
  434. {
  435. $store_id = get_store_id();
  436. $status = get_params('status');
  437. $query = LocalDeliveryCash::find()->where(['is_delete' => 0]);
  438. if ($status > -1) { //状态,0:待审核,1:待打款,2:审核驳回, 3:已打款
  439. $query->andWhere(['status' => $status]);
  440. }
  441. if ($store_id > 0) {
  442. $query->andWhere(['store_id' => $store_id]);
  443. }
  444. $query->orderBy('id DESC');
  445. $pagination = pagination_make($query);
  446. $list = $pagination['list'];
  447. foreach ($list as &$value) {
  448. $value['created_at'] = $value['created_at'] > 0 ? date('Y-m-d H:i:s', $value['created_at']) : '';
  449. $value['updated_at'] = $value['updated_at'] > 0 ? date('Y-m-d H:i:s', $value['updated_at']) : '';
  450. $value['pay_time'] = $value['pay_time'] > 0 ? date('Y-m-d H:i:s', $value['pay_time']) : '';
  451. $value['apply_time'] = $value['apply_time'] > 0 ? date('Y-m-d H:i:s', $value['apply_time']) : '';
  452. $value['actual_price'] = sprintf("%.2f", ($value['price'] - $value['service_charge']));
  453. }
  454. return $this->asJson([
  455. 'code' => 0,
  456. 'msg' => 'success',
  457. 'data' => [
  458. 'data' => $list,
  459. 'pageNo' => $pagination['pageNo'],
  460. 'totalCount' => $pagination['totalCount']
  461. ]
  462. ]);
  463. }
  464. /**
  465. * 模块名:actionConfirm
  466. * 代码描述:提现审核
  467. * 作者:WPing丶
  468. * 请求方式:GET
  469. * 创建时间:2023/07/12 14:47:15
  470. * @param int id 记录ID
  471. * @param int status 1=通过 2=拒绝 3=确认打款
  472. */
  473. public function actionAudit()
  474. {
  475. $id = get_params('id');
  476. $status = get_params('status');
  477. $cash = LocalDeliveryCash::find()->where(['is_delete' => 0, 'id' => $id])->andWhere(['or',['status' => LocalDeliveryCash::CASH_STATUS_WAIT],['status' => LocalDeliveryCash::CASH_STATUS_PASS]])->one();
  478. if (!$cash) {
  479. return $this->asJson([
  480. 'code' => 1,
  481. 'msg' => '记录不存在'
  482. ]);
  483. }
  484. // 拒绝
  485. if ($status == LocalDeliveryCash::CASH_STATUS_FAIL) {
  486. $t = \Yii::$app->db->beginTransaction(); //开始事务
  487. $log = LocalDeliveryLog::saveLog($cash->saas_user_id, $cash->price, 1, 1, 0, "提现驳回,返还佣金", 1);
  488. if (!$log) {
  489. $t->rollBack();
  490. return $this->asJson([
  491. 'code' => 1,
  492. 'msg' => '返还佣金失败'
  493. ]);
  494. }
  495. $cash->status = LocalDeliveryCash::CASH_STATUS_FAIL;
  496. $cash->apply_time = time();
  497. if (!$cash->save()) {
  498. $t->rollBack();
  499. return $this->asJson([
  500. 'code' => 1,
  501. 'msg' => implode(';', array_values($cash->firstErrors))
  502. ]);
  503. }
  504. $t->commit();
  505. return $this->asJson([
  506. 'code' => 0,
  507. 'msg' => '操作成功'
  508. ]);
  509. }
  510. // 通过
  511. if ($status == LocalDeliveryCash::CASH_STATUS_PASS) {
  512. $cash->status = LocalDeliveryCash::CASH_STATUS_PASS;
  513. $cash->apply_time = time();
  514. if (!$cash->save()) {
  515. return $this->asJson([
  516. 'code' => 1,
  517. 'msg' => implode(';', array_values($cash->firstErrors))
  518. ]);
  519. }
  520. return $this->asJson([
  521. 'code' => 0,
  522. 'msg' => '操作成功'
  523. ]);
  524. }
  525. // 手动打款
  526. if ($status == LocalDeliveryCash::CASH_STATUS_REMIT) {
  527. $cash->status = LocalDeliveryCash::CASH_STATUS_REMIT;
  528. $cash->pay_time = time();
  529. $cash->pay_type = 2;
  530. if (!$cash->save()) {
  531. return $this->asJson([
  532. 'code' => 1,
  533. 'msg' => implode(';', array_values($cash->firstErrors))
  534. ]);
  535. }
  536. return $this->asJson([
  537. 'code' => 0,
  538. 'msg' => '操作成功'
  539. ]);
  540. }elseif ($status == LocalDeliveryCash::CASH_STATUS_LG){
  541. if ($cash->type == 4){
  542. $user = User::findOne($cash->user_id);
  543. $saas = \app\models\SaasUser::findOne(['mobile' => $user->binding]);
  544. $lg_info = Lg::find()->where(['user_id'=>$saas->id,'status'=>1,'is_delete'=>0])->one();
  545. $lgApi = new LgApi($cash->store_id);
  546. //灵工提现
  547. $post_data = [
  548. 'store_id' => $cash->store_id,
  549. 'outTradeNo' => $cash->order_no,//唯一批次号
  550. 'accNo' => bcmul($cash->price,100),
  551. 'amt' => bcmul($cash->price,100),
  552. 'name' => $lg_info->name,
  553. 'certCard' => $lg_info->cert_card//身份证号
  554. ];
  555. $result = $lgApi->FlexiblePay($post_data);
  556. if (isset($result['status']) && $result['status'] == 999) {
  557. return $this->asJson($result);
  558. }
  559. $cash->status = 6;//灵工待打款
  560. $cash->save();
  561. //灵工提现接口调用后消息队列查询状态
  562. \queue_push(new LgCashJob(['id'=>$cash->id,'store_id'=>$cash->store_id,'type'=>12,'retry' => 5]), 60);
  563. return $this->asJson([
  564. 'code' => 0,
  565. 'msg' => '成功'
  566. ]);
  567. }
  568. }
  569. return $this->asJson([
  570. 'code' => 1,
  571. 'msg' => '操作异常'
  572. ]);
  573. }
  574. /**
  575. * 模块名:actionAccountLogList
  576. * 代码描述:佣金明细
  577. * 作者:WPing丶
  578. * 请求方式:GET
  579. * 创建时间:2023/07/12 09:03:52
  580. * @param int id
  581. * @param string str
  582. * @param bool bool
  583. */
  584. public function actionAccountLogList()
  585. {
  586. $start_time = get_params('start_time');
  587. $end_time = get_params('end_time');
  588. $type = get_params('type');
  589. $saas_user_id = get_params('saas_user_id');
  590. $query = LocalDeliveryLog::find()->alias('l')->where(['l.saas_user_id' => $saas_user_id]);
  591. if ($start_time) {
  592. $query->andWhere(['>=', 'l.created_at', strtotime($start_time . ' 00:00:00')]);
  593. }
  594. if ($end_time) {
  595. $query->andWhere(['<=', 'l.created_at', strtotime($end_time . ' 23:59:59')]);
  596. }
  597. if ($type > 0) {
  598. $query->andWhere(['l.type' => $type]);
  599. }
  600. $query->orderBy('l.id DESC');
  601. $pagination = pagination_make($query);
  602. $list = $pagination['list'];
  603. return $this->asJson([
  604. 'code' => 0,
  605. 'msg' => 'success',
  606. 'data' => [
  607. 'data' => $list,
  608. 'pageNo' => $pagination['pageNo'],
  609. 'totalCount' => $pagination['totalCount']
  610. ],
  611. ]);
  612. }
  613. /**
  614. * 模块名:actionAccountLogList
  615. * 代码描述:骑手评价记录
  616. * 请求方式:GET
  617. * 创建时间:2024/03/19 09:35:52
  618. * @param string name
  619. * @param string start_time
  620. * @param string end_time
  621. */
  622. public function actionGetCourierComment() {
  623. $name = get_params('name');
  624. $start_time = get_params('start_time');
  625. $end_time = get_params('end_time');
  626. $store_id = get_store_id();
  627. $query = LocalDeliveryCourierComment::find()->alias('cc')
  628. ->leftJoin(['c' => LocalDeliveryCourier::tableName()], 'cc.rider_id = c.id')
  629. ->where(['c.is_delete' => 0, 'cc.store_id' => $store_id]);
  630. if ($name) {
  631. $query->andWhere(['LIKE', 'c.real_name', $name]);
  632. }
  633. if ($start_time) {
  634. $start_time = strtotime($start_time);
  635. $query->andWhere(['>=', 'cc.created_at', $start_time]);
  636. }
  637. if ($end_time) {
  638. $end_time = strtotime($end_time);
  639. $query->andWhere(['<=', 'cc.created_at', $end_time]);
  640. }
  641. $query->select('cc.id, c.real_name name, cc.star, cc.desc, cc.is_show, cc.created_at')->orderBy('id desc');
  642. $pagination = pagination_make($query);
  643. $list = $pagination['list'];
  644. foreach ($list as &$item) {
  645. $item['is_show'] = intval($item['is_show']);
  646. $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
  647. $commentExt = LocalDeliveryCourierCommentExt::find()->where(['comment_id' => $item['id'], 'is_delete' => 0])->select('tag_id')->column();
  648. $content_arr = ['用户'.$item['star'].'星评价'];
  649. if (!empty($commentExt)) {
  650. $content_arr = LocalDeliveryCourierTag::find()->where(['id' => $commentExt])->select('tag')->column();
  651. }
  652. $item['desc'] = implode(' ', $content_arr);
  653. }
  654. return $this->asJson([
  655. 'code' => 0,
  656. 'msg' => 'success',
  657. 'data' => [
  658. 'data' => $list,
  659. 'pageNo' => $pagination['pageNo'],
  660. 'totalCount' => $pagination['totalCount']
  661. ],
  662. ]);
  663. }
  664. /**
  665. * 模块名:actionAccountLogList
  666. * 代码描述:修改骑手评价记录状态
  667. * 请求方式:GET
  668. * 创建时间:2024/03/19 09:35:52
  669. * @param string name
  670. * @param string start_time
  671. * @param string end_time
  672. */
  673. public function actionSetCourierCommentStatus() {
  674. $id = get_params('id');
  675. $is_show = get_params('is_show');
  676. $store_id = get_store_id();
  677. $localDeliveryCourierComment = LocalDeliveryCourierComment::findOne($id);
  678. if (empty($localDeliveryCourierComment)) {
  679. return $this->asJson([
  680. 'code' => 1,
  681. 'msg' => '操作异常'
  682. ]);
  683. }
  684. if (!in_array($is_show, [0, 1])) {
  685. return $this->asJson([
  686. 'code' => 1,
  687. 'msg' => '操作异常'
  688. ]);
  689. }
  690. $localDeliveryCourierComment->is_show = $is_show;
  691. if (!$localDeliveryCourierComment->save()) {
  692. return $this->asJson([
  693. 'code' => 1,
  694. 'msg' => '操作失败' . json_encode($localDeliveryCourierComment->errors)
  695. ]);
  696. }
  697. return $this->asJson([
  698. 'code' => 0,
  699. 'msg' => '操作成功'
  700. ]);
  701. }
  702. //流水对账清单
  703. public function actionBillCheckList() {
  704. $isExport = get_params('isExport');
  705. $start_time = get_params('start_time');
  706. $end_time = get_params('end_time');
  707. $search_key = get_params('search_key');
  708. $query = DeliveryInfo::find()->alias('di')->leftJoin(['s' => Store::tableName()], 'di.store_id = s.id')
  709. ->where(['di.local_status' => 3, 'di.is_store_delivery_type' => 0, 'di.is_local' => 1, 'di.is_delete' => 0])->select([
  710. 'di.id',
  711. 'di.order_no',
  712. 'di.store_id',
  713. 'store_name' => 's.name',
  714. 'store_mobile' => 's.contact_tel',
  715. 'di.fee',
  716. 'di.rider_name',
  717. 'di.rider_mobile',
  718. 'di.confirm_time',
  719. ])->orderBy('id desc');
  720. if ($start_time) {
  721. $query->andWhere(['>=', 'confirm_time', strtotime($start_time)]);
  722. }
  723. if ($end_time) {
  724. $query->andWhere(['<=', 'confirm_time', strtotime($end_time)]);
  725. }
  726. if ($search_key) {
  727. $query->andWhere(['LIKE', 's.name', $search_key]);
  728. }
  729. if ($isExport) {
  730. $list = $query->asArray()->all();
  731. } else {
  732. $pagination = pagination_make($query);
  733. $list = $pagination['list'];
  734. }
  735. foreach ($list as $index => &$item) {
  736. $store = Store::findOne($item['store_id']);
  737. unset($list[$index]['store_id']);
  738. $item['store_name'] = $store->name ?: '';
  739. $item['store_mobile'] = $store->contact_tel;
  740. $order = Order::findOne(['order_no' => $item['order_no'], 'is_delete' => 0]);
  741. $item['created_at'] = date('Y-m-d H:i:s', $order->created_at);
  742. $item['delivery_time'] = date('Y-m-d H:i:s', $order->delivery_time);
  743. $item['confirm_time'] = date('Y-m-d H:i:s', $item['confirm_time']);
  744. }
  745. if ($isExport) {
  746. $export_field = [
  747. [
  748. 'id' => 'ID',
  749. 'order_no' => '订单号',
  750. 'store_name' => '商城名称',
  751. 'store_mobile' => '商城手机号',
  752. 'fee' => '配送费',
  753. 'rider_name' => '骑手名称',
  754. 'rider_mobile' => '骑手手机号',
  755. 'confirm_time' => '送达时间',
  756. 'created_at' => '下单时间',
  757. 'delivery_time' => '预计送达时间',
  758. ]
  759. ];
  760. $file_name = '财务列表';
  761. $data = array_merge($export_field, $list);
  762. return SimpleExcelWriter::streamDownload($file_name . time() . '.xlsx')
  763. ->noHeaderRow()
  764. ->addRows($data)
  765. ->toBrowser();
  766. }
  767. return $this->asJson([
  768. 'code' => 0,
  769. 'msg' => '',
  770. 'data' => [
  771. 'data' => $list,
  772. 'pageNo' => $pagination['pageNo'],
  773. 'totalCount' => $pagination['totalCount']
  774. ]
  775. ]);
  776. }
  777. }