StoreOrderController.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\api\controller\v1\admin;
  12. use app\Request;
  13. use app\services\order\DeliveryServiceServices;
  14. use app\services\order\StoreOrderCartInfoServices;
  15. use app\services\order\StoreOrderCreateServices;
  16. use app\services\order\StoreOrderDeliveryServices;
  17. use app\services\order\StoreOrderEconomizeServices;
  18. use app\services\order\StoreOrderRefundServices;
  19. use app\services\order\StoreOrderServices;
  20. use app\services\order\StoreOrderWapServices;
  21. use app\services\order\StoreOrderWriteOffServices;
  22. use app\services\pay\OrderOfflineServices;
  23. use app\services\serve\ServeServices;
  24. use app\services\system\store\SystemStoreServices;
  25. use app\services\user\UserServices;
  26. use app\services\shipping\ExpressServices;
  27. /**
  28. * 订单类
  29. * Class StoreOrderController
  30. * @package app\api\controller\admin\order
  31. */
  32. class StoreOrderController
  33. {
  34. /**
  35. * @var StoreOrderWapServices
  36. */
  37. protected $service;
  38. /**
  39. * StoreOrderController constructor.
  40. * @param StoreOrderWapServices $services
  41. */
  42. public function __construct(StoreOrderWapServices $services)
  43. {
  44. $this->service = $services;
  45. }
  46. /**
  47. * 订单 查看物流
  48. * @param StoreOrderCartInfoServices $services
  49. * @param ExpressServices $expressServices
  50. * @param $uni
  51. * @param string $type
  52. * @return mixed
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\DbException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. */
  57. public function express(StoreOrderServices $orderServices, StoreOrderCartInfoServices $services, ExpressServices $expressServices, $uni, $type = '')
  58. {
  59. if ($type == 'refund') {
  60. /** @var StoreOrderRefundServices $refundService */
  61. $refundService = app()->make(StoreOrderRefundServices::class);
  62. $order = $refundService->refundDetail($uni);
  63. $express = $order['refund_express'];
  64. $cacheName = $uni . $express;
  65. $orderInfo = [];
  66. $info = [];
  67. $cartNew = [];
  68. foreach ($order['cart_info'] as $k => $cart) {
  69. $cartNew['cart_num'] = $cart['cart_num'];
  70. $cartNew['truePrice'] = $cart['truePrice'];
  71. $cartNew['postage_price'] = $cart['postage_price'];
  72. $cartNew['productInfo']['image'] = $cart['productInfo']['image'];
  73. $cartNew['productInfo']['store_name'] = $cart['productInfo']['store_name'];
  74. $cartNew['productInfo']['unit_name'] = $cart['productInfo']['unit_name'] ?? '';
  75. array_push($info, $cartNew);
  76. unset($cart);
  77. }
  78. $orderInfo['cartInfo'] = $info;
  79. $orderInfo['delivery_id'] = $express;
  80. $orderInfo['delivery_name'] = $order['refund_express_name'];
  81. $orderInfo['delivery_code'] = '';
  82. } else {
  83. if (!$uni || !($order = $orderServices->getUserOrderDetail($uni, 0, []))) {
  84. return app('json')->fail(410173);
  85. }
  86. if ($type != 'refund' && ($order['delivery_type'] != 'express' || !$order['delivery_id'])) {
  87. return app('json')->fail(410206);
  88. }
  89. $express = $type == 'refund' ? $order['refund_express'] : $order['delivery_id'];
  90. $cacheName = $uni . $express;
  91. $orderInfo = [];
  92. $cartInfo = $services->getCartColunm(['oid' => $order['id']], 'cart_info', 'unique');
  93. $info = [];
  94. $cartNew = [];
  95. foreach ($cartInfo as $k => $cart) {
  96. $cart = json_decode($cart, true);
  97. $cartNew['cart_num'] = $cart['cart_num'];
  98. $cartNew['truePrice'] = $cart['truePrice'];
  99. $cartNew['postage_price'] = $cart['postage_price'];
  100. $cartNew['productInfo']['image'] = $cart['productInfo']['image'];
  101. $cartNew['productInfo']['store_name'] = $cart['productInfo']['store_name'];
  102. $cartNew['productInfo']['unit_name'] = $cart['productInfo']['unit_name'] ?? '';
  103. array_push($info, $cartNew);
  104. unset($cart);
  105. }
  106. $orderInfo['delivery_id'] = $express;
  107. $orderInfo['delivery_name'] = $type == 'refund' ? '用户退回' : $order['delivery_name'];;
  108. $orderInfo['delivery_code'] = $type == 'refund' ? '' : $order['delivery_code'];
  109. $orderInfo['delivery_type'] = $order['delivery_type'];
  110. $orderInfo['user_address'] = $order['user_address'];
  111. $orderInfo['user_mark'] = $order['mark'];
  112. $orderInfo['cartInfo'] = $info;
  113. }
  114. return app('json')->success([
  115. 'order' => $orderInfo,
  116. 'express' => [
  117. 'result' => ['list' => $expressServices->query($cacheName, $orderInfo['delivery_id'], $orderInfo['delivery_code'], $order['user_phone'])
  118. ]
  119. ]
  120. ]);
  121. }
  122. /**
  123. * 订单数据统计
  124. * @param StoreOrderServices $services
  125. * @return mixed
  126. */
  127. public function statistics(StoreOrderServices $services)
  128. {
  129. $dataCount = $services->getOrderData();
  130. $dataPrice = $this->service->getOrderTimeData();
  131. $data = array_merge($dataCount, $dataPrice);
  132. return app('json')->success($data);
  133. }
  134. /**
  135. * 订单每月统计数据
  136. * @param Request $request
  137. * @return mixed
  138. */
  139. public function data(Request $request)
  140. {
  141. [$start, $stop] = $request->getMore([
  142. ['start', 0],
  143. ['stop', 0]
  144. ], true);
  145. return app('json')->success($this->service->getOrderDataPriceCount(['time' => [$start, $stop]]));
  146. }
  147. /**
  148. * 订单列表
  149. * @param Request $request
  150. * @return mixed
  151. * @throws \think\db\exception\DataNotFoundException
  152. * @throws \think\db\exception\DbException
  153. * @throws \think\db\exception\ModelNotFoundException
  154. */
  155. public function lst(Request $request)
  156. {
  157. $where = $request->getMore([
  158. ['status', ''],
  159. ['is_del', 0],
  160. ['data', '', '', 'time'],
  161. ['type', ''],
  162. ['field_key', ''],
  163. ['field_value', ''],
  164. ['keywords', '', '', 'real_name']
  165. ]);
  166. $where['is_system_del'] = 0;
  167. if (!in_array($where['status'], [-1, -2, -3])) {
  168. $where['pid'] = 0;
  169. }
  170. return app('json')->success($this->service->getWapAdminOrderList($where));
  171. }
  172. /**
  173. * 订单详情
  174. * @param Request $request
  175. * @param StoreOrderServices $services
  176. * @param UserServices $userServices
  177. * @param $orderId
  178. * @return mixed
  179. * @throws \think\db\exception\DataNotFoundException
  180. * @throws \think\db\exception\DbException
  181. * @throws \think\db\exception\ModelNotFoundException
  182. */
  183. public function detail(Request $request, StoreOrderServices $services, UserServices $userServices, $orderId)
  184. {
  185. $economizeServices = app()->make(StoreOrderEconomizeServices::class);
  186. $orderData = $services->getUserOrderByKey($economizeServices, $orderId, 0);
  187. $orderData['nickname'] = $userServices->value(['uid' => $orderData['uid']], 'nickname');
  188. return app('json')->success($orderData);
  189. }
  190. /**
  191. * 订单发货获取订单信息
  192. * @param UserServices $userServices
  193. * @param $orderId
  194. * @return mixed
  195. */
  196. public function delivery_gain(UserServices $userServices, $orderId)
  197. {
  198. $order = $this->service->getOne(['order_id' => $orderId], 'real_name,user_phone,user_address,order_id,uid,status,paid,id');
  199. if (!$order) return app('json')->fail(410173);
  200. if ($order['paid']) {
  201. $order['nickname'] = $userServices->value(['uid' => $order['uid']], 'nickname');
  202. $order['config_export_open'] = (bool)((int)sys_config('config_export_open'));
  203. $order = $order->hidden(['uid', 'status', 'paid'])->toArray();
  204. return app('json')->success($order);
  205. }
  206. return app('json')->fail(100016);
  207. }
  208. /**
  209. * 订单发货
  210. * @param Request $request
  211. * @param StoreOrderDeliveryServices $services
  212. * @param $id
  213. * @return mixed
  214. */
  215. public function delivery_keep(Request $request, StoreOrderDeliveryServices $services, $id)
  216. {
  217. $data = $request->postMore([
  218. ['type', 1],
  219. ['delivery_name', ''],//快递公司id
  220. ['delivery_id', ''],//快递单号
  221. ['delivery_code', ''],//快递公司编码
  222. ['delivery_type', ''],//快递公司名称
  223. ['express_record_type', 2],//发货记录类型
  224. ['express_temp_id', ""],//电子面单模板
  225. ['to_name', ''],//寄件人姓名
  226. ['to_tel', ''],//寄件人电话
  227. ['to_addr', ''],//寄件人地址
  228. ['sh_delivery_name', ''],//送货人姓名
  229. ['sh_delivery_id', ''],//送货人电话
  230. ['sh_delivery_uid', ''],//送货人ID
  231. ['fictitious_content', ''],//虚拟发货内容
  232. ['pickup_time', []]
  233. ]);
  234. if ($data['delivery_type']) {
  235. $data['delivery_name'] = $data['delivery_type'];
  236. unset($data['delivery_type']);
  237. }
  238. $services->delivery((int)$id, $data);
  239. return app('json')->success(410273);
  240. }
  241. /**
  242. * 订单改价
  243. * @param Request $request
  244. * @param StoreOrderServices $services
  245. * @return mixed
  246. * @throws \Exception
  247. */
  248. public function price(Request $request, StoreOrderServices $services)
  249. {
  250. [$order_id, $price] = $request->postMore([
  251. ['order_id', ''],
  252. ['price', '']
  253. ], true);
  254. $order = $this->service->getOne(['order_id' => $order_id], 'id,user_phone,id,paid,pay_price,order_id,total_price,total_postage,pay_postage,gain_integral');
  255. if (!$order) return app('json')->fail(410173);
  256. if ($order['paid']) {
  257. return app('json')->fail(410174);
  258. }
  259. if ($price === '') return app('json')->fail(410175);
  260. if ($price < 0) return app('json')->fail(410176);
  261. if ($order['pay_price'] == $price) return app('json')->success(100001, ['order_id' => $order_id]);
  262. $order_id = $services->updateOrder($order['id'], ['total_price' => $order['total_price'], 'pay_price' => $price]);
  263. return app('json')->success(100001, ['order_id' => $order_id]);
  264. }
  265. /**
  266. * 订单备注
  267. * @param Request $request
  268. * @return mixed
  269. */
  270. public function remark(Request $request)
  271. {
  272. [$order_id, $remark] = $request->postMore([
  273. ['order_id', ''],
  274. ['remark', '']
  275. ], true);
  276. $order = $this->service->getOne(['order_id' => $order_id], 'id,remark');
  277. if (!$order) return app('json')->fail(410173);
  278. if (!strlen(trim($remark))) return app('json')->fail(410177);
  279. $order->remark = $remark;
  280. if (!$order->save())
  281. return app('json')->fail(100025);
  282. return app('json')->success(100024);
  283. }
  284. /**
  285. * 订单交易额/订单数量时间统计
  286. * @param Request $request
  287. * @return bool
  288. */
  289. public function time(Request $request)
  290. {
  291. list($start, $stop, $type) = $request->getMore([
  292. ['start', strtotime(date('Y-m'))],
  293. ['stop', time()],
  294. ['type', 1]
  295. ], true);
  296. $start = strtotime(date('Y-m-d 00:00:00', (int)$start));
  297. $stop = strtotime(date('Y-m-d 23:59:59', (int)$stop));
  298. if ($start > $stop) {
  299. $middle = $stop;
  300. $stop = $start;
  301. $start = $middle;
  302. }
  303. $space = bcsub($stop, $start, 0);//间隔时间段
  304. $front = bcsub($start, $space, 0) - 1;//第一个时间段
  305. /** @var StoreOrderServices $orderService */
  306. $orderService = app()->make(StoreOrderServices::class);
  307. $order_where = [
  308. 'pid' => 0,
  309. 'paid' => 1,
  310. 'refund_status' => [0, 3],
  311. 'is_del' => 0,
  312. 'is_system_del' => 0
  313. ];
  314. if ($type == 1) {//销售额
  315. $frontPrice = $orderService->sum($order_where + ['time' => [$front, $start - 1]], 'pay_price', true);
  316. $afterPrice = $orderService->sum($order_where + ['time' => [$start, $stop]], 'pay_price', true);
  317. $chartInfo = $orderService->chartTimePrice($start, $stop);
  318. $data['chart'] = $chartInfo;//营业额图表数据
  319. $data['time'] = $afterPrice;//时间区间营业额
  320. $increase = (float)bcsub((string)$afterPrice, (string)$frontPrice, 2); //同比上个时间区间增长营业额
  321. $growthRate = abs($increase);
  322. if ($growthRate == 0) $data['growth_rate'] = 0;
  323. else if ($frontPrice == 0) $data['growth_rate'] = (int)bcmul($growthRate, 100, 0);
  324. else $data['growth_rate'] = (int)bcmul((string)bcdiv((string)$growthRate, (string)$frontPrice, 2), '100', 0);//时间区间增长率
  325. $data['increase_time'] = abs($increase); //同比上个时间区间增长营业额
  326. $data['increase_time_status'] = $increase >= 0 ? 1 : 2; //同比上个时间区间增长营业额增长 1 减少 2
  327. } else {//订单数
  328. $frontNumber = $orderService->count($order_where + ['time' => [$front, $start - 1]]);
  329. $afterNumber = $orderService->count($order_where + ['time' => [$start, $stop]]);
  330. $chartInfo = $orderService->chartTimeNumber($start, $stop);
  331. $data['chart'] = $chartInfo;//订单数图表数据
  332. $data['time'] = $afterNumber;//时间区间订单数
  333. $increase = $afterNumber - $frontNumber; //同比上个时间区间增长订单数
  334. $growthRate = abs($increase);
  335. if ($growthRate == 0) $data['growth_rate'] = 0;
  336. else if ($frontNumber == 0) $data['growth_rate'] = (int)bcmul($growthRate, 100, 0);
  337. else $data['growth_rate'] = (int)bcmul((string)bcdiv((string)$growthRate, (string)$frontNumber, 2), '100', 0);//时间区间增长率
  338. $data['increase_time'] = abs($increase); //同比上个时间区间增长营业额
  339. $data['increase_time_status'] = $increase >= 0 ? 1 : 2; //同比上个时间区间增长营业额增长 1 减少 2
  340. }
  341. return app('json')->success($data);
  342. }
  343. /**
  344. * 订单支付
  345. * @param Request $request
  346. * @param OrderOfflineServices $services
  347. * @return mixed
  348. */
  349. public function offline(Request $request, OrderOfflineServices $services)
  350. {
  351. [$orderId] = $request->postMore([['order_id', '']], true);
  352. $orderInfo = $this->service->getOne(['order_id' => $orderId], 'id');
  353. if (!$orderInfo) return app('json')->fail(100100);
  354. $id = $orderInfo->id;
  355. $services->orderOffline((int)$id);
  356. return app('json')->success(100010);
  357. }
  358. /**
  359. * 订单退款
  360. * @param Request $request
  361. * @param StoreOrderRefundServices $services
  362. * @param StoreOrderServices $orderServices
  363. * @param StoreOrderCartInfoServices $storeOrderCartInfoServices
  364. * @param StoreOrderCreateServices $storeOrderCreateServices
  365. * @return mixed
  366. * @throws \think\db\exception\DataNotFoundException
  367. * @throws \think\db\exception\DbException
  368. * @throws \think\db\exception\ModelNotFoundException
  369. */
  370. public function refund(Request $request, StoreOrderRefundServices $services, StoreOrderServices $orderServices, StoreOrderCartInfoServices $storeOrderCartInfoServices, StoreOrderCreateServices $storeOrderCreateServices)
  371. {
  372. list($orderId, $price, $type) = $request->postMore([
  373. ['order_id', ''],
  374. ['price', '0'],
  375. ['type', 1],
  376. ], true);
  377. if (!strlen(trim($orderId))) return app('json')->fail(100100);
  378. //退款订单详情
  379. $orderRefund = $services->getOne(['order_id' => $orderId]);
  380. $is_admin = 0;
  381. if (!$orderRefund) {
  382. //主动退款主订单详情
  383. $orderRefund = $orderServices->getOne(['order_id' => $orderId]);
  384. $is_admin = 1;
  385. if ($services->count(['store_order_id' => $orderRefund['id'], 'refund_type' => [0, 1, 2, 4, 5], 'is_cancel' => 0, 'is_del' => 0])) {
  386. return app('json')->fail(410178);
  387. }
  388. }
  389. if (!$is_admin) {
  390. if (!$orderRefund) {
  391. return app('json')->fail(100026);
  392. }
  393. if ($orderRefund['is_cancel'] == 1) {
  394. return app('json')->fail(410179);
  395. }
  396. $orderInfo = $this->service->get((int)$orderRefund['store_order_id']);
  397. if (!$orderInfo) {
  398. return app('json')->fail(100026);
  399. }
  400. if (!in_array($orderRefund['refund_type'], [1, 2, 5])) {
  401. return app('json')->fail(410180);
  402. }
  403. if ($type == 1) {
  404. $data['refund_type'] = 6;
  405. } else if ($type == 2) {
  406. $data['refund_type'] = 3;
  407. } else {
  408. return app('json')->fail(410181);
  409. }
  410. $data['refunded_time'] = time();
  411. //拒绝退款
  412. if ($type == 2) {
  413. $services->refuseRefund((int)$orderRefund['id'], $data, $orderRefund);
  414. return app('json')->success(410182);
  415. } else {
  416. if ($orderRefund['refund_price'] == $orderInfo['refunded_price']) return app('json')->fail(410183);
  417. if (!$price) {
  418. return app('json')->fail(410184);
  419. }
  420. $data['refunded_price'] = bcadd($price, $orderRefund['refunded_price'], 2);
  421. $bj = bccomp((float)$orderRefund['refund_price'], (float)$data['refunded_price'], 2);
  422. if ($bj < 0) {
  423. return app('json')->fail(410185);
  424. }
  425. $refundData['pay_price'] = $orderInfo['pay_price'];
  426. $refundData['refund_price'] = $price;
  427. //修改订单退款状态
  428. if ($services->agreeRefund((int)$orderRefund['id'], $refundData)) {
  429. $services->update((int)$orderRefund['id'], $data);
  430. return app('json')->success(410186);
  431. } else {
  432. $services->storeProductOrderRefundYFasle((int)$orderInfo['id'], $price);
  433. return app('json')->fail(410187);
  434. }
  435. }
  436. } else {
  437. $order = $orderRefund;
  438. $data['refund_price'] = $price;
  439. $data['type'] = $type;
  440. $id = $order['id'];
  441. //0元退款
  442. if ($order['pay_price'] == 0 && in_array($order['refund_status'], [0, 1])) {
  443. $refund_price = 0;
  444. } else {
  445. if ($order['pay_price'] == $order['refund_price']) {
  446. return app('json')->fail(410183);
  447. }
  448. if (!$data['refund_price']) {
  449. return app('json')->fail(410184);
  450. }
  451. $refund_price = $data['refund_price'];
  452. $data['refund_price'] = bcadd($data['refund_price'], $order['refund_price'], 2);
  453. $bj = bccomp((string)$order['pay_price'], (string)$data['refund_price'], 2);
  454. if ($bj < 0) {
  455. return app('json')->fail(410185);
  456. }
  457. }
  458. if ($data['type'] == 1) {
  459. $data['refund_status'] = 2;
  460. $data['refund_type'] = 6;
  461. } else if ($data['type'] == 2) {
  462. $data['refund_status'] = 0;
  463. $data['refund_type'] = 3;
  464. }
  465. $type = $data['type'];
  466. //拒绝退款
  467. if ($type == 2) {
  468. $this->service->update((int)$order['id'], ['refund_status' => 0, 'refund_type' => 3]);
  469. return app('json')->success(410182);
  470. } else {
  471. unset($data['type']);
  472. $refund_data['pay_price'] = $order['pay_price'];
  473. $refund_data['refund_price'] = $refund_price;
  474. //主动退款清楚原本退款单
  475. $services->delete(['store_order_id' => $id]);
  476. //生成退款订单
  477. $refundOrderData['uid'] = $order['uid'];
  478. $refundOrderData['store_id'] = $order['store_id'];
  479. $refundOrderData['store_order_id'] = $id;
  480. $refundOrderData['refund_num'] = $order['total_num'];
  481. $refundOrderData['refund_type'] = $data['refund_type'];
  482. $refundOrderData['refund_price'] = $order['pay_price'];
  483. $refundOrderData['refunded_price'] = $refund_price;
  484. $refundOrderData['refunded_reason'] = '管理员手动退款';
  485. $refundOrderData['order_id'] = $storeOrderCreateServices->getNewOrderId('');
  486. $refundOrderData['refunded_time'] = time();
  487. $refundOrderData['add_time'] = time();
  488. $cartInfos = $storeOrderCartInfoServices->getCartColunm(['oid' => $id], 'id,cart_id,cart_num,cart_info');
  489. foreach ($cartInfos as &$cartInfo) {
  490. $cartInfo['cart_info'] = is_string($cartInfo['cart_info']) ? json_decode($cartInfo['cart_info'], true) : $cartInfo['cart_info'];
  491. }
  492. $refundOrderData['cart_info'] = json_encode(array_column($cartInfos, 'cart_info'));
  493. $res = $services->save($refundOrderData);
  494. //修改订单退款状态
  495. if ($services->agreeRefund((int)$res->id, $refund_data)) {
  496. $this->service->update($id, $data);
  497. return app('json')->success(410186);
  498. } else {
  499. $services->storeProductOrderRefundYFasle((int)$id, $refund_price);
  500. return app('json')->fail(410187);
  501. }
  502. }
  503. }
  504. }
  505. /**
  506. * 门店核销
  507. * @param Request $request
  508. * @param StoreOrderWriteOffServices $services
  509. * @return mixed
  510. * @throws \think\db\exception\DataNotFoundException
  511. * @throws \think\db\exception\DbException
  512. * @throws \think\db\exception\ModelNotFoundException
  513. */
  514. public function order_verific(Request $request, StoreOrderWriteOffServices $services)
  515. {
  516. list($verifyCode, $isConfirm) = $request->postMore([
  517. ['verify_code', ''],
  518. ['is_confirm', 0]
  519. ], true);
  520. if (!$verifyCode) return app('json')->fail(410188);
  521. $uid = $request->uid();
  522. $orderInfo = $services->writeOffOrder($verifyCode, (int)$isConfirm, $uid);
  523. if ($isConfirm == 0) {
  524. return app('json')->success($orderInfo);
  525. }
  526. return app('json')->success(410189);
  527. }
  528. /**
  529. * 获取所有配送员列表
  530. * @param DeliveryServiceServices $services
  531. * @return mixed
  532. */
  533. public function getDeliveryAll(DeliveryServiceServices $services)
  534. {
  535. $list = $services->getDeliveryList();
  536. return app('json')->success($list['list']);
  537. }
  538. /**
  539. * 获取配置信息
  540. * @return mixed
  541. */
  542. public function getDeliveryInfo()
  543. {
  544. return app('json')->success([
  545. 'express_temp_id' => sys_config('config_export_temp_id'),
  546. 'to_name' => sys_config('config_export_to_name'),
  547. 'id' => sys_config('config_export_id'),
  548. 'to_tel' => sys_config('config_export_to_tel'),
  549. 'to_add' => sys_config('config_export_to_address')
  550. ]);
  551. }
  552. /**
  553. * 获取面单信息
  554. * @param Request $request
  555. * @param ServeServices $services
  556. * @return mixed
  557. */
  558. public function getExportTemp(Request $request, ServeServices $services)
  559. {
  560. [$com] = $request->getMore([
  561. ['com', ''],
  562. ], true);
  563. return app('json')->success($services->express()->temp($com));
  564. }
  565. /**
  566. * 物流公司
  567. * @param ExpressServices $services
  568. * @return mixed
  569. */
  570. public function getExportAll(ExpressServices $services)
  571. {
  572. return app('json')->success($services->expressList());
  573. }
  574. /**
  575. * 移动端订单管理退款列表
  576. * @param Request $request
  577. * @param StoreOrderRefundServices $services
  578. * @return mixed
  579. */
  580. public function refundOrderList(Request $request, StoreOrderRefundServices $services)
  581. {
  582. $where = $request->getMore([
  583. ['order_id', ''],
  584. ['time', ''],
  585. ['refund_type', 0],
  586. ['keywords', ''],
  587. ]);
  588. $where['is_cancel'] = 0;
  589. $data = $services->refundList($where)['list'];
  590. return app('json')->success($data);
  591. }
  592. /**
  593. * 订单详情
  594. * @param StoreOrderRefundServices $services
  595. * @param $uni
  596. * @return mixed
  597. */
  598. public function refundOrderDetail(StoreOrderRefundServices $services, $uni)
  599. {
  600. $data = $services->refundDetail($uni);
  601. return app('json')->success($data);
  602. }
  603. /**
  604. * 退款备注
  605. * @param StoreOrderRefundServices $services
  606. * @param Request $request
  607. * @return mixed
  608. */
  609. public function refundRemark(StoreOrderRefundServices $services, Request $request)
  610. {
  611. [$remark, $order_id] = $request->postMore([
  612. ['remark', ''],
  613. ['order_id', ''],
  614. ], true);
  615. if (!$remark)
  616. return app('json')->fail(410177);
  617. if (!$order_id)
  618. return app('json')->fail(100100);
  619. if (!$order = $services->get(['order_id' => $order_id])) {
  620. return app('json')->fail(410173);
  621. }
  622. $order->remark = $remark;
  623. if ($order->save()) {
  624. return app('json')->success(100024);
  625. } else
  626. return app('json')->fail(100025);
  627. }
  628. /**
  629. * 同意退货
  630. * @param StoreOrderRefundServices $services
  631. * @param Request $request
  632. * @return mixed
  633. */
  634. public function agreeExpress(StoreOrderRefundServices $services, Request $request)
  635. {
  636. [$id] = $request->postMore([
  637. ['id', ''],
  638. ], true);
  639. $services->agreeExpress($id);
  640. return app('json')->success(100010);
  641. }
  642. /**
  643. * 获取门店信息
  644. * @param Request $request
  645. * @return mixed
  646. * @throws \think\db\exception\DataNotFoundException
  647. * @throws \think\db\exception\DbException
  648. * @throws \think\db\exception\ModelNotFoundException
  649. */
  650. public function get_store_info(Request $request)
  651. {
  652. $uid = $request->uid();
  653. /** @var SystemStoreServices $storeServices */
  654. $storeServices = app()->make(SystemStoreServices::class);
  655. // 根据uid获取门店信息
  656. $storeInfo = $storeServices->getOne(['uid' => $uid]);
  657. if ($storeInfo) {
  658. $info = $storeServices->getStoreDispose($storeInfo['id']);
  659. return app('json')->success(compact('info'));
  660. }
  661. return app('json')->success(['info' => null]);
  662. }
  663. /**
  664. * 保存门店信息
  665. * @param Request $request
  666. * @return mixed
  667. */
  668. public function save_store(Request $request)
  669. {
  670. $uid = $request->uid();
  671. $data = $request->postMore([
  672. ['name', ''],
  673. ['introduction', ''],
  674. ['image', ''],
  675. ['oblong_image', ''],
  676. ['phone', ''],
  677. ['address', ''],
  678. ['detailed_address', ''],
  679. ['latlng', ''],
  680. ['day_time', []],
  681. ]);
  682. /** @var SystemStoreServices $storeServices */
  683. $storeServices = app()->make(SystemStoreServices::class);
  684. // 检查同uid是否已有门店
  685. $existingStore = $storeServices->getOne(['uid' => $uid]);
  686. $storeId = $existingStore ? $existingStore['id'] : 0;
  687. // 处理数据
  688. $data['uid'] = $uid;
  689. $data['address'] = implode(',', $data['address']);
  690. $data['latlng'] = explode(',', $data['latlng']);
  691. if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) {
  692. return app('json')->fail(400125);
  693. }
  694. $data['latitude'] = $data['latlng'][0];
  695. $data['longitude'] = $data['latlng'][1];
  696. $data['day_time'] = implode(' - ', $data['day_time']);
  697. unset($data['latlng']);
  698. if ($data['image'] && strstr($data['image'], 'http') === false) {
  699. $site_url = sys_config('site_url');
  700. $data['image'] = $site_url . $data['image'];
  701. }
  702. $storeServices->saveStore((int)$storeId, $data);
  703. return app('json')->success(100014);
  704. }
  705. }