StoreOrderController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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\user\UserServices;
  25. use app\services\shipping\ExpressServices;
  26. /**
  27. * 订单类
  28. * Class StoreOrderController
  29. * @package app\api\controller\admin\order
  30. */
  31. class StoreOrderController
  32. {
  33. /**
  34. * @var StoreOrderWapServices
  35. */
  36. protected $service;
  37. /**
  38. * StoreOrderController constructor.
  39. * @param StoreOrderWapServices $services
  40. */
  41. public function __construct(StoreOrderWapServices $services)
  42. {
  43. $this->service = $services;
  44. }
  45. /**
  46. * 订单 查看物流
  47. * @param StoreOrderCartInfoServices $services
  48. * @param ExpressServices $expressServices
  49. * @param $uni
  50. * @param string $type
  51. * @return mixed
  52. * @throws \think\db\exception\DataNotFoundException
  53. * @throws \think\db\exception\DbException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. */
  56. public function express(StoreOrderServices $orderServices, StoreOrderCartInfoServices $services, ExpressServices $expressServices, $uni, $type = '')
  57. {
  58. if ($type == 'refund') {
  59. /** @var StoreOrderRefundServices $refundService */
  60. $refundService = app()->make(StoreOrderRefundServices::class);
  61. $order = $refundService->refundDetail($uni);
  62. $express = $order['refund_express'];
  63. $cacheName = $uni . $express;
  64. $orderInfo = [];
  65. $info = [];
  66. $cartNew = [];
  67. foreach ($order['cart_info'] as $k => $cart) {
  68. $cartNew['cart_num'] = $cart['cart_num'];
  69. $cartNew['truePrice'] = $cart['truePrice'];
  70. $cartNew['postage_price'] = $cart['postage_price'];
  71. $cartNew['productInfo']['image'] = $cart['productInfo']['image'];
  72. $cartNew['productInfo']['store_name'] = $cart['productInfo']['store_name'];
  73. $cartNew['productInfo']['unit_name'] = $cart['productInfo']['unit_name'] ?? '';
  74. array_push($info, $cartNew);
  75. unset($cart);
  76. }
  77. $orderInfo['cartInfo'] = $info;
  78. $orderInfo['delivery_id'] = $express;
  79. $orderInfo['delivery_name'] = $order['refund_express_name'];
  80. $orderInfo['delivery_code'] = '';
  81. } else {
  82. if (!$uni || !($order = $orderServices->getUserOrderDetail($uni, 0, []))) {
  83. return app('json')->fail(410173);
  84. }
  85. if ($type != 'refund' && ($order['delivery_type'] != 'express' || !$order['delivery_id'])) {
  86. return app('json')->fail(410206);
  87. }
  88. $express = $type == 'refund' ? $order['refund_express'] : $order['delivery_id'];
  89. $cacheName = $uni . $express;
  90. $orderInfo = [];
  91. $cartInfo = $services->getCartColunm(['oid' => $order['id']], 'cart_info', 'unique');
  92. $info = [];
  93. $cartNew = [];
  94. foreach ($cartInfo as $k => $cart) {
  95. $cart = json_decode($cart, true);
  96. $cartNew['cart_num'] = $cart['cart_num'];
  97. $cartNew['truePrice'] = $cart['truePrice'];
  98. $cartNew['postage_price'] = $cart['postage_price'];
  99. $cartNew['productInfo']['image'] = $cart['productInfo']['image'];
  100. $cartNew['productInfo']['store_name'] = $cart['productInfo']['store_name'];
  101. $cartNew['productInfo']['unit_name'] = $cart['productInfo']['unit_name'] ?? '';
  102. array_push($info, $cartNew);
  103. unset($cart);
  104. }
  105. $orderInfo['delivery_id'] = $express;
  106. $orderInfo['delivery_name'] = $type == 'refund' ? '用户退回' : $order['delivery_name'];;
  107. $orderInfo['delivery_code'] = $type == 'refund' ? '' : $order['delivery_code'];
  108. $orderInfo['delivery_type'] = $order['delivery_type'];
  109. $orderInfo['user_address'] = $order['user_address'];
  110. $orderInfo['user_mark'] = $order['mark'];
  111. $orderInfo['cartInfo'] = $info;
  112. }
  113. return app('json')->success([
  114. 'order' => $orderInfo,
  115. 'express' => [
  116. 'result' => ['list' => $expressServices->query($cacheName, $orderInfo['delivery_id'], $orderInfo['delivery_code'], $order['user_phone'])
  117. ]
  118. ]
  119. ]);
  120. }
  121. /**
  122. * 订单数据统计
  123. * @param StoreOrderServices $services
  124. * @return mixed
  125. */
  126. public function statistics(StoreOrderServices $services)
  127. {
  128. $dataCount = $services->getOrderData();
  129. $dataPrice = $this->service->getOrderTimeData();
  130. $data = array_merge($dataCount, $dataPrice);
  131. return app('json')->success($data);
  132. }
  133. /**
  134. * 订单每月统计数据
  135. * @param Request $request
  136. * @return mixed
  137. */
  138. public function data(Request $request)
  139. {
  140. [$start, $stop] = $request->getMore([
  141. ['start', 0],
  142. ['stop', 0]
  143. ], true);
  144. return app('json')->success($this->service->getOrderDataPriceCount(['time' => [$start, $stop]]));
  145. }
  146. /**
  147. * 订单列表
  148. * @param Request $request
  149. * @return mixed
  150. * @throws \think\db\exception\DataNotFoundException
  151. * @throws \think\db\exception\DbException
  152. * @throws \think\db\exception\ModelNotFoundException
  153. */
  154. public function lst(Request $request)
  155. {
  156. $where = $request->getMore([
  157. ['status', ''],
  158. ['is_del', 0],
  159. ['data', '', '', 'time'],
  160. ['type', ''],
  161. ['field_key', ''],
  162. ['field_value', ''],
  163. ['keywords', '', '', 'real_name']
  164. ]);
  165. $where['is_system_del'] = 0;
  166. if (!in_array($where['status'], [-1, -2, -3])) {
  167. $where['pid'] = 0;
  168. }
  169. return app('json')->success($this->service->getWapAdminOrderList($where));
  170. }
  171. /**
  172. * 订单详情
  173. * @param Request $request
  174. * @param StoreOrderServices $services
  175. * @param UserServices $userServices
  176. * @param $orderId
  177. * @return mixed
  178. * @throws \think\db\exception\DataNotFoundException
  179. * @throws \think\db\exception\DbException
  180. * @throws \think\db\exception\ModelNotFoundException
  181. */
  182. public function detail(Request $request, StoreOrderServices $services, UserServices $userServices, $orderId)
  183. {
  184. $economizeServices = app()->make(StoreOrderEconomizeServices::class);
  185. $orderData = $services->getUserOrderByKey($economizeServices, $orderId, 0);
  186. $orderData['nickname'] = $userServices->value(['uid' => $orderData['uid']], 'nickname');
  187. return app('json')->success($orderData);
  188. }
  189. /**
  190. * 订单发货获取订单信息
  191. * @param UserServices $userServices
  192. * @param $orderId
  193. * @return mixed
  194. */
  195. public function delivery_gain(UserServices $userServices, $orderId)
  196. {
  197. $order = $this->service->getOne(['order_id' => $orderId], 'real_name,user_phone,user_address,order_id,uid,status,paid,id');
  198. if (!$order) return app('json')->fail(410173);
  199. if ($order['paid']) {
  200. $order['nickname'] = $userServices->value(['uid' => $order['uid']], 'nickname');
  201. $order['config_export_open'] = (bool)((int)sys_config('config_export_open'));
  202. $order = $order->hidden(['uid', 'status', 'paid'])->toArray();
  203. return app('json')->success($order);
  204. }
  205. return app('json')->fail(100016);
  206. }
  207. /**
  208. * 订单发货
  209. * @param Request $request
  210. * @param StoreOrderDeliveryServices $services
  211. * @param $id
  212. * @return mixed
  213. */
  214. public function delivery_keep(Request $request, StoreOrderDeliveryServices $services, $id)
  215. {
  216. $data = $request->postMore([
  217. ['type', 1],
  218. ['delivery_name', ''],//快递公司id
  219. ['delivery_id', ''],//快递单号
  220. ['delivery_code', ''],//快递公司编码
  221. ['delivery_type', ''],//快递公司名称
  222. ['express_record_type', 2],//发货记录类型
  223. ['express_temp_id', ""],//电子面单模板
  224. ['to_name', ''],//寄件人姓名
  225. ['to_tel', ''],//寄件人电话
  226. ['to_addr', ''],//寄件人地址
  227. ['sh_delivery_name', ''],//送货人姓名
  228. ['sh_delivery_id', ''],//送货人电话
  229. ['sh_delivery_uid', ''],//送货人ID
  230. ['fictitious_content', ''],//虚拟发货内容
  231. ['pickup_time', []]
  232. ]);
  233. if ($data['delivery_type']) {
  234. $data['delivery_name'] = $data['delivery_type'];
  235. unset($data['delivery_type']);
  236. }
  237. $services->delivery((int)$id, $data);
  238. return app('json')->success(410273);
  239. }
  240. /**
  241. * 订单改价
  242. * @param Request $request
  243. * @param StoreOrderServices $services
  244. * @return mixed
  245. * @throws \Exception
  246. */
  247. public function price(Request $request, StoreOrderServices $services)
  248. {
  249. [$order_id, $price] = $request->postMore([
  250. ['order_id', ''],
  251. ['price', '']
  252. ], true);
  253. $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');
  254. if (!$order) return app('json')->fail(410173);
  255. if ($order['paid']) {
  256. return app('json')->fail(410174);
  257. }
  258. if ($price === '') return app('json')->fail(410175);
  259. if ($price < 0) return app('json')->fail(410176);
  260. if ($order['pay_price'] == $price) return app('json')->success(100001, ['order_id' => $order_id]);
  261. $order_id = $services->updateOrder($order['id'], ['total_price' => $order['total_price'], 'pay_price' => $price]);
  262. return app('json')->success(100001, ['order_id' => $order_id]);
  263. }
  264. /**
  265. * 订单备注
  266. * @param Request $request
  267. * @return mixed
  268. */
  269. public function remark(Request $request)
  270. {
  271. [$order_id, $remark] = $request->postMore([
  272. ['order_id', ''],
  273. ['remark', '']
  274. ], true);
  275. $order = $this->service->getOne(['order_id' => $order_id], 'id,remark');
  276. if (!$order) return app('json')->fail(410173);
  277. if (!strlen(trim($remark))) return app('json')->fail(410177);
  278. $order->remark = $remark;
  279. if (!$order->save())
  280. return app('json')->fail(100025);
  281. return app('json')->success(100024);
  282. }
  283. /**
  284. * 订单交易额/订单数量时间统计
  285. * @param Request $request
  286. * @return bool
  287. */
  288. public function time(Request $request)
  289. {
  290. list($start, $stop, $type) = $request->getMore([
  291. ['start', strtotime(date('Y-m'))],
  292. ['stop', time()],
  293. ['type', 1]
  294. ], true);
  295. $start = strtotime(date('Y-m-d 00:00:00', (int)$start));
  296. $stop = strtotime(date('Y-m-d 23:59:59', (int)$stop));
  297. if ($start > $stop) {
  298. $middle = $stop;
  299. $stop = $start;
  300. $start = $middle;
  301. }
  302. $space = bcsub($stop, $start, 0);//间隔时间段
  303. $front = bcsub($start, $space, 0) - 1;//第一个时间段
  304. /** @var StoreOrderServices $orderService */
  305. $orderService = app()->make(StoreOrderServices::class);
  306. $order_where = [
  307. 'pid' => 0,
  308. 'paid' => 1,
  309. 'refund_status' => [0, 3],
  310. 'is_del' => 0,
  311. 'is_system_del' => 0
  312. ];
  313. if ($type == 1) {//销售额
  314. $frontPrice = $orderService->sum($order_where + ['time' => [$front, $start - 1]], 'pay_price', true);
  315. $afterPrice = $orderService->sum($order_where + ['time' => [$start, $stop]], 'pay_price', true);
  316. $chartInfo = $orderService->chartTimePrice($start, $stop);
  317. $data['chart'] = $chartInfo;//营业额图表数据
  318. $data['time'] = $afterPrice;//时间区间营业额
  319. $increase = (float)bcsub((string)$afterPrice, (string)$frontPrice, 2); //同比上个时间区间增长营业额
  320. $growthRate = abs($increase);
  321. if ($growthRate == 0) $data['growth_rate'] = 0;
  322. else if ($frontPrice == 0) $data['growth_rate'] = (int)bcmul($growthRate, 100, 0);
  323. else $data['growth_rate'] = (int)bcmul((string)bcdiv((string)$growthRate, (string)$frontPrice, 2), '100', 0);//时间区间增长率
  324. $data['increase_time'] = abs($increase); //同比上个时间区间增长营业额
  325. $data['increase_time_status'] = $increase >= 0 ? 1 : 2; //同比上个时间区间增长营业额增长 1 减少 2
  326. } else {//订单数
  327. $frontNumber = $orderService->count($order_where + ['time' => [$front, $start - 1]]);
  328. $afterNumber = $orderService->count($order_where + ['time' => [$start, $stop]]);
  329. $chartInfo = $orderService->chartTimeNumber($start, $stop);
  330. $data['chart'] = $chartInfo;//订单数图表数据
  331. $data['time'] = $afterNumber;//时间区间订单数
  332. $increase = $afterNumber - $frontNumber; //同比上个时间区间增长订单数
  333. $growthRate = abs($increase);
  334. if ($growthRate == 0) $data['growth_rate'] = 0;
  335. else if ($frontNumber == 0) $data['growth_rate'] = (int)bcmul($growthRate, 100, 0);
  336. else $data['growth_rate'] = (int)bcmul((string)bcdiv((string)$growthRate, (string)$frontNumber, 2), '100', 0);//时间区间增长率
  337. $data['increase_time'] = abs($increase); //同比上个时间区间增长营业额
  338. $data['increase_time_status'] = $increase >= 0 ? 1 : 2; //同比上个时间区间增长营业额增长 1 减少 2
  339. }
  340. return app('json')->success($data);
  341. }
  342. /**
  343. * 订单支付
  344. * @param Request $request
  345. * @param OrderOfflineServices $services
  346. * @return mixed
  347. */
  348. public function offline(Request $request, OrderOfflineServices $services)
  349. {
  350. [$orderId] = $request->postMore([['order_id', '']], true);
  351. $orderInfo = $this->service->getOne(['order_id' => $orderId], 'id');
  352. if (!$orderInfo) return app('json')->fail(100100);
  353. $id = $orderInfo->id;
  354. $services->orderOffline((int)$id);
  355. return app('json')->success(100010);
  356. }
  357. /**
  358. * 订单退款
  359. * @param Request $request
  360. * @param StoreOrderRefundServices $services
  361. * @param StoreOrderServices $orderServices
  362. * @param StoreOrderCartInfoServices $storeOrderCartInfoServices
  363. * @param StoreOrderCreateServices $storeOrderCreateServices
  364. * @return mixed
  365. * @throws \think\db\exception\DataNotFoundException
  366. * @throws \think\db\exception\DbException
  367. * @throws \think\db\exception\ModelNotFoundException
  368. */
  369. public function refund(Request $request, StoreOrderRefundServices $services, StoreOrderServices $orderServices, StoreOrderCartInfoServices $storeOrderCartInfoServices, StoreOrderCreateServices $storeOrderCreateServices)
  370. {
  371. list($orderId, $price, $type) = $request->postMore([
  372. ['order_id', ''],
  373. ['price', '0'],
  374. ['type', 1],
  375. ], true);
  376. if (!strlen(trim($orderId))) return app('json')->fail(100100);
  377. //退款订单详情
  378. $orderRefund = $services->getOne(['order_id' => $orderId]);
  379. $is_admin = 0;
  380. if (!$orderRefund) {
  381. //主动退款主订单详情
  382. $orderRefund = $orderServices->getOne(['order_id' => $orderId]);
  383. $is_admin = 1;
  384. if ($services->count(['store_order_id' => $orderRefund['id'], 'refund_type' => [0, 1, 2, 4, 5], 'is_cancel' => 0, 'is_del' => 0])) {
  385. return app('json')->fail(410178);
  386. }
  387. }
  388. if (!$is_admin) {
  389. if (!$orderRefund) {
  390. return app('json')->fail(100026);
  391. }
  392. if ($orderRefund['is_cancel'] == 1) {
  393. return app('json')->fail(410179);
  394. }
  395. $orderInfo = $this->service->get((int)$orderRefund['store_order_id']);
  396. if (!$orderInfo) {
  397. return app('json')->fail(100026);
  398. }
  399. if (!in_array($orderRefund['refund_type'], [1, 2, 5])) {
  400. return app('json')->fail(410180);
  401. }
  402. if ($type == 1) {
  403. $data['refund_type'] = 6;
  404. } else if ($type == 2) {
  405. $data['refund_type'] = 3;
  406. } else {
  407. return app('json')->fail(410181);
  408. }
  409. $data['refunded_time'] = time();
  410. //拒绝退款
  411. if ($type == 2) {
  412. $services->refuseRefund((int)$orderRefund['id'], $data, $orderRefund);
  413. return app('json')->success(410182);
  414. } else {
  415. if ($orderRefund['refund_price'] == $orderInfo['refunded_price']) return app('json')->fail(410183);
  416. if (!$price) {
  417. return app('json')->fail(410184);
  418. }
  419. $data['refunded_price'] = bcadd($price, $orderRefund['refunded_price'], 2);
  420. $bj = bccomp((float)$orderRefund['refund_price'], (float)$data['refunded_price'], 2);
  421. if ($bj < 0) {
  422. return app('json')->fail(410185);
  423. }
  424. $refundData['pay_price'] = $orderInfo['pay_price'];
  425. $refundData['refund_price'] = $price;
  426. $refundData['order_id'] = $orderId;
  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. $refund_data['order_id'] = $refundOrderData['order_id'];
  495. //修改订单退款状态
  496. if ($services->agreeRefund((int)$res->id, $refund_data)) {
  497. $this->service->update($id, $data);
  498. return app('json')->success(410186);
  499. } else {
  500. $services->storeProductOrderRefundYFasle((int)$id, $refund_price);
  501. return app('json')->fail(410187);
  502. }
  503. }
  504. }
  505. }
  506. /**
  507. * 门店核销
  508. * @param Request $request
  509. * @param StoreOrderWriteOffServices $services
  510. * @return mixed
  511. * @throws \think\db\exception\DataNotFoundException
  512. * @throws \think\db\exception\DbException
  513. * @throws \think\db\exception\ModelNotFoundException
  514. */
  515. public function order_verific(Request $request, StoreOrderWriteOffServices $services)
  516. {
  517. list($verifyCode, $isConfirm) = $request->postMore([
  518. ['verify_code', ''],
  519. ['is_confirm', 0]
  520. ], true);
  521. if (!$verifyCode) return app('json')->fail(410188);
  522. $uid = $request->uid();
  523. $orderInfo = $services->writeOffOrder($verifyCode, (int)$isConfirm, $uid);
  524. if ($isConfirm == 0) {
  525. return app('json')->success($orderInfo);
  526. }
  527. return app('json')->success(410189);
  528. }
  529. /**
  530. * 获取所有配送员列表
  531. * @param DeliveryServiceServices $services
  532. * @return mixed
  533. */
  534. public function getDeliveryAll(DeliveryServiceServices $services)
  535. {
  536. $list = $services->getDeliveryList();
  537. return app('json')->success($list['list']);
  538. }
  539. /**
  540. * 获取配置信息
  541. * @return mixed
  542. */
  543. public function getDeliveryInfo()
  544. {
  545. return app('json')->success([
  546. 'express_temp_id' => sys_config('config_export_temp_id'),
  547. 'to_name' => sys_config('config_export_to_name'),
  548. 'id' => sys_config('config_export_id'),
  549. 'to_tel' => sys_config('config_export_to_tel'),
  550. 'to_add' => sys_config('config_export_to_address')
  551. ]);
  552. }
  553. /**
  554. * 获取面单信息
  555. * @param Request $request
  556. * @param ServeServices $services
  557. * @return mixed
  558. */
  559. public function getExportTemp(Request $request, ServeServices $services)
  560. {
  561. [$com] = $request->getMore([
  562. ['com', ''],
  563. ], true);
  564. return app('json')->success($services->express()->temp($com));
  565. }
  566. /**
  567. * 物流公司
  568. * @param ExpressServices $services
  569. * @return mixed
  570. */
  571. public function getExportAll(ExpressServices $services)
  572. {
  573. return app('json')->success($services->expressList());
  574. }
  575. /**
  576. * 移动端订单管理退款列表
  577. * @param Request $request
  578. * @param StoreOrderRefundServices $services
  579. * @return mixed
  580. */
  581. public function refundOrderList(Request $request, StoreOrderRefundServices $services)
  582. {
  583. $where = $request->getMore([
  584. ['order_id', ''],
  585. ['time', ''],
  586. ['refund_type', 0],
  587. ['keywords', '', '', 'real_name'],
  588. ]);
  589. $where['is_cancel'] = 0;
  590. $data = $services->refundList($where)['list'];
  591. return app('json')->success($data);
  592. }
  593. /**
  594. * 订单详情
  595. * @param StoreOrderRefundServices $services
  596. * @param $uni
  597. * @return mixed
  598. */
  599. public function refundOrderDetail(StoreOrderRefundServices $services, $uni)
  600. {
  601. $data = $services->refundDetail($uni);
  602. return app('json')->success($data);
  603. }
  604. /**
  605. * 退款备注
  606. * @param StoreOrderRefundServices $services
  607. * @param Request $request
  608. * @return mixed
  609. */
  610. public function refundRemark(StoreOrderRefundServices $services, Request $request)
  611. {
  612. [$remark, $order_id] = $request->postMore([
  613. ['remark', ''],
  614. ['order_id', ''],
  615. ], true);
  616. if (!$remark)
  617. return app('json')->fail(410177);
  618. if (!$order_id)
  619. return app('json')->fail(100100);
  620. if (!$order = $services->get(['order_id' => $order_id])) {
  621. return app('json')->fail(410173);
  622. }
  623. $order->remark = $remark;
  624. if ($order->save()) {
  625. return app('json')->success(100024);
  626. } else
  627. return app('json')->fail(100025);
  628. }
  629. /**
  630. * 同意退货
  631. * @param StoreOrderRefundServices $services
  632. * @param Request $request
  633. * @return mixed
  634. */
  635. public function agreeExpress(StoreOrderRefundServices $services, Request $request)
  636. {
  637. [$id] = $request->postMore([
  638. ['id', ''],
  639. ], true);
  640. $services->agreeExpress($id);
  641. return app('json')->success(100010);
  642. }
  643. }