StoreOrderController.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <?php
  2. namespace app\api\controller\admin;
  3. use app\Request;
  4. use app\models\user\{
  5. User, UserBill
  6. };
  7. use crmeb\repositories\OrderRepository;
  8. use crmeb\repositories\ShortLetterRepositories;
  9. use crmeb\services\{
  10. MiniProgramService, UtilService, WechatService
  11. };
  12. use app\models\store\{
  13. StoreCart, StoreOrder, StoreOrderStatus, StorePink, StoreService
  14. };
  15. use app\models\system\SystemStoreStaff;
  16. /**
  17. * 订单类
  18. * Class StoreOrderController
  19. * @package app\api\controller\admin\order
  20. */
  21. class StoreOrderController
  22. {
  23. /**
  24. * 订单数据统计
  25. * @param Request $request
  26. * @return mixed
  27. */
  28. public function statistics(Request $request)
  29. {
  30. $uid = $request->uid();
  31. if (!StoreService::orderServiceStatus($uid))
  32. return app('json')->fail('权限不足');
  33. $dataCount = StoreOrder::getOrderDataAdmin();
  34. $dataPrice = StoreOrder::getOrderTimeData();
  35. $data = array_merge($dataCount, $dataPrice);
  36. return app('json')->successful($data);
  37. }
  38. /**
  39. * 订单每月统计数据
  40. * @param Request $request
  41. * @return mixed
  42. */
  43. public function data(Request $request)
  44. {
  45. $uid = $request->uid();
  46. if (!StoreService::orderServiceStatus($uid))
  47. return app('json')->fail('权限不足');
  48. list($page, $limit, $start, $stop) = UtilService::getMore([
  49. ['page', 1],
  50. ['limit', 7],
  51. ['start', ''],
  52. ['stop', '']
  53. ], $request, true);
  54. if (!$limit) return app('json')->successful([]);
  55. $info = SystemStoreStaff::where('uid',$uid)->find()->toArray();
  56. $data = StoreOrder::getOrderDataPriceCount($page, $limit, $start, $stop);
  57. if ($data) return app('json')->successful($data->toArray());
  58. return app('json')->successful([]);
  59. }
  60. public function month(Request $request)
  61. {
  62. $uid = $request->uid();
  63. $month = input('month',date("Y-m"));
  64. $start = date("Y-m-d H:i:s",strtotime($month."-1"));
  65. $end = date("Y-m-d H:i:s",strtotime("+1 month",strtotime($start))-1);
  66. if (!StoreService::orderServiceStatus($uid))
  67. return app('json')->fail('权限不足');
  68. $info = SystemStoreStaff::where('uid',$uid)->find()->toArray();
  69. return app('json')->successful(StoreOrder::getordermonth($info['store_id'],$start,$end));
  70. }
  71. /**
  72. * 订单列表
  73. * @param Request $request
  74. * @return mixed
  75. */
  76. public function lst(Request $request)
  77. {
  78. $uid = $request->uid();
  79. if (!StoreService::orderServiceStatus($uid))
  80. return app('json')->fail('权限不足');
  81. $where = UtilService::getMore([
  82. ['status', ''],
  83. ['is_del', 0],
  84. ['data', ''],
  85. ['type', ''],
  86. ['order', ''],
  87. ['real_name',''],
  88. ['page', 0],
  89. ['limit', 0]
  90. ], $request);
  91. if (!$where['limit']) return app('json')->successful([]);
  92. $info = SystemStoreStaff::where('uid',$uid)->find()->toArray();
  93. $where['store_id'] = $info['store_id'];
  94. return app('json')->successful(StoreOrder::orderList($where));
  95. }
  96. /**
  97. * 订单详情
  98. * @param Request $request
  99. * @param $orderId
  100. * @return mixed
  101. * @throws \think\Exception
  102. * @throws \think\db\exception\DataNotFoundException
  103. * @throws \think\db\exception\ModelNotFoundException
  104. * @throws \think\exception\DbException
  105. */
  106. public function detail(Request $request, $orderId)
  107. {
  108. $uid = $request->uid();
  109. if ((!StoreService::orderServiceStatus($uid)) && !(SystemStoreStaff::verifyStatus($uid)))
  110. return app('json')->fail('权限不足');
  111. $order = StoreOrder::getAdminOrderDetail($orderId, 'id,uid,order_id,add_time,status,total_num,total_price,total_postage,pay_price,pay_postage,paid,refund_status,remark,pink_id,combination_id,mark,seckill_id,bargain_id,delivery_type,pay_type,real_name,user_phone,user_address,coupon_price,freight_price,delivery_name,delivery_type,delivery_id');
  112. if (!$order) return app('json')->fail('订单不存在');
  113. $order = $order->toArray();
  114. $nickname = User::getUserInfo($order['uid'], 'nickname')['nickname'];
  115. $orderInfo = StoreOrder::tidyAdminOrder([$order], true)[0];
  116. unset($orderInfo['uid'], $orderInfo['seckill_id'], $orderInfo['pink_id'], $orderInfo['combination_id'], $orderInfo['bargain_id'], $orderInfo['status'], $orderInfo['total_postage']);
  117. $orderInfo['nickname'] = $nickname;
  118. return app('json')->successful('ok', $orderInfo);
  119. }
  120. /**
  121. * 订单发货获取订单信息
  122. * @param Request $request
  123. * @param $orderId
  124. * @return mixed
  125. * @throws \think\Exception
  126. * @throws \think\db\exception\DataNotFoundException
  127. * @throws \think\db\exception\ModelNotFoundException
  128. * @throws \think\exception\DbException
  129. */
  130. public function delivery_gain(Request $request, $orderId)
  131. {
  132. $uid = $request->uid();
  133. if (!StoreService::orderServiceStatus($uid))
  134. return app('json')->fail('权限不足');
  135. $order = StoreOrder::getAdminOrderDetail($orderId, 'real_name,user_phone,user_address,order_id,uid,status,paid');
  136. if (!$order) return app('json')->fail('订单不存在');
  137. if ($order['paid']) {
  138. $order['nickname'] = User::getUserInfo($order['uid'], 'nickname')['nickname'];
  139. $order = $order->hidden(['uid', 'status', 'paid'])->toArray();
  140. return app('json')->successful('ok', $order);
  141. }
  142. return app('json')->fail('状态错误');
  143. }
  144. /**
  145. * 订单发货
  146. * @param Request $request
  147. * @return mixed
  148. * @throws \think\db\exception\DataNotFoundException
  149. * @throws \think\db\exception\ModelNotFoundException
  150. * @throws \think\exception\DbException
  151. */
  152. public function delivery_keep(Request $request)
  153. {
  154. $uid = $request->uid();
  155. if (!StoreService::orderServiceStatus($uid))
  156. return app('json')->fail('权限不足');
  157. list($order_id, $delivery_type, $delivery_name, $delivery_id) = UtilService::postMore([
  158. ['order_id', ''],
  159. ['delivery_type', 0],
  160. ['delivery_name', ''],
  161. ['delivery_id', ''],
  162. ], $request, true);
  163. $order = StoreOrder::getAdminOrderDetail($order_id, 'id,status,paid');
  164. if (!$order) return app('json')->fail('订单不存在');
  165. if (!$order['status'] && $order['paid']) {
  166. $deliveryTypeArr = ['send', 'express', 'fictitious'];
  167. if (!strlen(trim($delivery_type))) return app('json')->fail('请填写发货方式');
  168. if (!in_array($delivery_type, $deliveryTypeArr)) return app('json')->fail('发货方式错误');
  169. if ($delivery_type == 'express') {
  170. if (!strlen(trim($delivery_name))) return app('json')->fail('请选择快递公司');
  171. if (!strlen(trim($delivery_id))) return app('json')->fail('请填写快递单号');
  172. }
  173. if ($delivery_type == 'send') {
  174. if (!strlen(trim($delivery_name))) return app('json')->fail('请填写发货人');
  175. if (!strlen(trim($delivery_id))) return app('json')->fail('请填写发货手机号');
  176. }
  177. $data['status'] = 1;
  178. $data['delivery_type'] = $delivery_type;
  179. $data['delivery_name'] = $delivery_name;
  180. $data['delivery_id'] = $delivery_id;
  181. $res = StoreOrder::edit($data, $order['id'], 'id');
  182. if ($res) {
  183. if ($delivery_type == 'express') {
  184. StoreOrderStatus::status($order['id'], 'delivery_goods', '已发货 快递公司:' . $data['delivery_name'] . ' 快递单号:' . $data['delivery_id']);
  185. } else if ($delivery_type == 'send') {
  186. StoreOrderStatus::status($order['id'], 'delivery', '已配送 发货人:' . $delivery_name . ' 发货人电话:' . $delivery_id);
  187. } else if ($delivery_type == 'fictitious') {
  188. StoreOrderStatus::status($order['id'], 'delivery_fictitious', '虚拟产品已发货');
  189. }
  190. }
  191. event('StoreProductOrderDeliveryGoodsAfter', [$data, $order['id']]);
  192. return app('json')->successful('发货成功!');
  193. }
  194. return app('json')->fail('状态错误');
  195. }
  196. /**
  197. * 订单改价
  198. * @param Request $request
  199. * @return mixed
  200. * @throws \think\db\exception\DataNotFoundException
  201. * @throws \think\db\exception\ModelNotFoundException
  202. * @throws \think\exception\DbException
  203. */
  204. public function price(Request $request)
  205. {
  206. $uid = $request->uid();
  207. if (!StoreService::orderServiceStatus($uid))
  208. return app('json')->fail('权限不足');
  209. list($order_id, $price) = UtilService::postMore([
  210. ['order_id', ''],
  211. ['price', '']
  212. ], $request, true);
  213. $order = StoreOrder::getAdminOrderDetail($order_id, 'id,paid,user_phone,pay_price,order_id,total_price,total_postage,pay_postage,gain_integral');
  214. if (!$order) return app('json')->fail('订单不存在');
  215. $order = $order->toArray();
  216. if (!$order['paid']) {
  217. if ($price === '') return app('json')->fail('请填写实际支付金额');
  218. if ($price < 0) return app('json')->fail('实际支付金额不能小于0元');
  219. if ($order['pay_price'] == $price) return app('json')->successful('修改成功');
  220. $order['order_id'] = StoreOrder::changeOrderId($order['order_id']);
  221. if (!StoreOrder::edit(['pay_price' => $price, 'order_id' => $order['order_id']], $order['id'], 'id'))
  222. return app('json')->fail('状态错误');
  223. $order['pay_price'] = $price;
  224. event('StoreProductOrderEditAfter', [$order, $order['id']]);
  225. StoreOrderStatus::status($order['id'], 'order_edit', '修改实际支付金额' . $price);
  226. //改价短信提醒
  227. if ($price != $order['pay_price']) {
  228. $switch = sys_config('price_revision_switch') ? true : false;
  229. ShortLetterRepositories::send($switch, $order['user_phone'], ['order_id' => $order_id, 'pay_price' => $order['pay_price']], 'PRICE_REVISION_CODE');
  230. }
  231. return app('json')->successful('修改成功');
  232. }
  233. return app('json')->fail('状态错误');
  234. }
  235. /**
  236. * 订单备注
  237. * @param Request $request
  238. * @return mixed
  239. * @throws \think\db\exception\DataNotFoundException
  240. * @throws \think\db\exception\ModelNotFoundException
  241. * @throws \think\exception\DbException
  242. */
  243. public function remark(Request $request)
  244. {
  245. $uid = $request->uid();
  246. if (!StoreService::orderServiceStatus($uid))
  247. return app('json')->fail('权限不足');
  248. list($order_id, $remark) = UtilService::postMore([
  249. ['order_id', ''],
  250. ['remark', '']
  251. ], $request, true);
  252. $order = StoreOrder::getAdminOrderDetail($order_id, 'id');
  253. if (!$order) return app('json')->fail('订单不存在');
  254. $order = $order->toArray();
  255. if (!strlen(trim($remark))) return app('json')->fail('请填写备注内容');
  256. if (!StoreOrder::edit(['remark' => $remark], $order['id']))
  257. return app('json')->fail('备注失败');
  258. return app('json')->successful('备注成功');
  259. }
  260. /**
  261. * 订单交易额/订单数量时间统计
  262. * @param Request $request
  263. * @return bool
  264. */
  265. public function time(Request $request)
  266. {
  267. $uid = $request->uid();
  268. if (!StoreService::orderServiceStatus($uid))
  269. return app('json')->fail('权限不足');
  270. list($start, $stop, $type) = UtilService::getMore([
  271. ['start', strtotime(date('Y-m'))],
  272. ['stop', time()],
  273. ['type', 1]
  274. ], $request, true);
  275. if ($start == $stop) {
  276. return app('json')->fail('开始时间不能等于结束时间');
  277. }
  278. if ($start > $stop) {
  279. $middle = $stop;
  280. $stop = $start;
  281. $start = $middle;
  282. }
  283. $space = bcsub($stop, $start, 0);//间隔时间段
  284. $front = bcsub($start, $space, 0);//第一个时间段
  285. if ($type == 1) {//销售额
  286. $frontPrice = StoreOrder:: getOrderTimeBusinessVolumePrice($front, $start);
  287. $afterPrice = StoreOrder:: getOrderTimeBusinessVolumePrice($start, $stop);
  288. $chartInfo = StoreOrder::chartTimePrice($start, $stop);
  289. $data['chart'] = $chartInfo;//营业额图表数据
  290. $data['time'] = $afterPrice;//时间区间营业额
  291. $increase = (float)bcsub($afterPrice, $frontPrice, 2); //同比上个时间区间增长营业额
  292. $growthRate = abs($increase);
  293. if ($growthRate == 0) $data['growth_rate'] = 0;
  294. else if ($frontPrice == 0) $data['growth_rate'] = $growthRate;
  295. else $data['growth_rate'] = (int)bcmul(bcdiv($growthRate, $frontPrice, 2), 100, 0);//时间区间增长率
  296. $data['increase_time'] = abs($increase); //同比上个时间区间增长营业额
  297. $data['increase_time_status'] = $increase >= 0 ? 1 : 2; //同比上个时间区间增长营业额增长 1 减少 2
  298. } else {//订单数
  299. $frontNumber = StoreOrder:: getOrderTimeBusinessVolumeNumber($front, $start);
  300. $afterNumber = StoreOrder:: getOrderTimeBusinessVolumeNumber($start, $stop);
  301. $chartInfo = StoreOrder::chartTimeNumber($start, $stop);
  302. $data['chart'] = $chartInfo;//订单数图表数据
  303. $data['time'] = $afterNumber;//时间区间订单数
  304. $increase = (int)bcsub($afterNumber, $frontNumber, 0); //同比上个时间区间增长订单数
  305. $growthRate = abs($increase);
  306. if ($growthRate == 0) $data['growth_rate'] = 0;
  307. else if ($frontNumber == 0) $data['growth_rate'] = $growthRate;
  308. else $data['growth_rate'] = (int)bcmul(bcdiv($growthRate, $frontNumber, 2), 100, 0);//时间区间增长率
  309. $data['increase_time'] = abs($increase); //同比上个时间区间增长营业额
  310. $data['increase_time_status'] = $increase >= 0 ? 1 : 2; //同比上个时间区间增长营业额增长 1 减少 2
  311. }
  312. return app('json')->successful($data);
  313. }
  314. /**
  315. * 订单支付
  316. * @param Request $request
  317. * @return mixed
  318. * @throws \think\db\exception\DataNotFoundException
  319. * @throws \think\db\exception\ModelNotFoundException
  320. * @throws \think\exception\DbException
  321. */
  322. public function offline(Request $request)
  323. {
  324. list($orderId) = UtilService::postMore([['order_id', '']], $request, true);
  325. $orderInfo = StoreOrder::getAdminOrderDetail($orderId, 'id');
  326. if (!$orderInfo) return app('json')->fail('参数错误');
  327. $id = $orderInfo->id;
  328. $res = StoreOrder::updateOffline($id);
  329. if ($res) {
  330. event('StoreProductOrderOffline', [$id]);
  331. StoreOrderStatus::status($id, 'offline', '线下付款');
  332. return app('json')->successful('修改成功!');
  333. }
  334. return app('json')->fail(StoreOrder::getErrorInfo('修改失败!'));
  335. }
  336. /**
  337. * 订单退款
  338. * @param Request $request
  339. * @return mixed
  340. * @throws \think\Exception
  341. * @throws \think\db\exception\DataNotFoundException
  342. * @throws \think\db\exception\ModelNotFoundException
  343. * @throws \think\exception\DbException
  344. */
  345. public function refund(Request $request)
  346. {
  347. list($orderId, $price, $type) = UtilService::postMore([
  348. ['order_id', ''],
  349. ['price', 0],
  350. ['type', 1],
  351. ], $request, true);
  352. if (!strlen(trim($orderId))) return app('json')->fail('参数错误');
  353. $orderInfo = StoreOrder::getAdminOrderDetail($orderId);
  354. if (!$orderInfo) return app('json')->fail('数据不存在!');
  355. $orderInfo = $orderInfo->toArray();
  356. if ($type == 1)
  357. $data['refund_status'] = 2;
  358. else if ($type == 2)
  359. $data['refund_status'] = 0;
  360. else
  361. return app('json')->fail('退款修改状态错误');
  362. if ($orderInfo['pay_price'] == 0 || $type == 2) {
  363. StoreOrder::update($data, ['order_id' => $orderId]);
  364. return app('json')->successful('修改退款状态成功!');
  365. }
  366. if ($orderInfo['pay_price'] == $orderInfo['refund_price']) return app('json')->fail('已退完支付金额!不能再退款了');
  367. if (!$price) return app('json')->fail('请输入退款金额');
  368. $data['refund_price'] = bcadd($price, $orderInfo['refund_price'], 2);
  369. $bj = bccomp((float)$orderInfo['pay_price'], (float)$data['refund_price'], 2);
  370. if ($bj < 0) return app('json')->fail('退款金额大于支付金额,请修改退款金额');
  371. $refundData['pay_price'] = $orderInfo['pay_price'];
  372. $refundData['refund_price'] = $price;
  373. if ($orderInfo['pay_type'] == 'weixin') {
  374. if ($orderInfo['is_channel'] == 1) {// 小程序
  375. try {
  376. MiniProgramService::payOrderRefund($orderInfo['order_id'], $refundData);
  377. } catch (\Exception $e) {
  378. return app('json')->fail($e->getMessage());
  379. }
  380. } else {// 公众号
  381. try {
  382. WechatService::payOrderRefund($orderInfo['order_id'], $refundData);
  383. } catch (\Exception $e) {
  384. return app('json')->fail($e->getMessage());
  385. }
  386. }
  387. } else if ($orderInfo['pay_type'] == 'yue') {//余额
  388. StoreOrder::beginTrans();
  389. $userInfo = User::getUserInfo($orderInfo['uid'], 'now_money');
  390. if (!$userInfo) {
  391. StoreOrder::rollbackTrans();
  392. return app('json')->fail('订单用户不存在');
  393. }
  394. $res1 = User::bcInc($orderInfo['uid'], 'now_money', $price, 'uid');
  395. $res2 = $res2 = UserBill::income('商品退款', $orderInfo['uid'], 'now_money', 'pay_product_refund', $price, $orderInfo['id'], bcadd($userInfo['now_money'], $price, 2), '订单退款到余额' . floatval($price) . '元');
  396. try {
  397. OrderRepository::storeOrderYueRefund($orderInfo, $refundData);
  398. } catch (\Exception $e) {
  399. StoreOrder::rollbackTrans();
  400. return app('json')->fail($e->getMessage());
  401. }
  402. $res = $res1 && $res2;
  403. StoreOrder::checkTrans($res);
  404. if (!$res) return app('json')->fail('余额退款失败!');
  405. }
  406. $resEdit = StoreOrder::edit($data, $orderInfo['id'], 'id');
  407. if ($resEdit) {
  408. $data['type'] = $type;
  409. if ($data['type'] == 1) StorePink::setRefundPink($orderInfo['id']);
  410. try {
  411. OrderRepository::storeProductOrderRefundY($data, $orderInfo['id']);
  412. } catch (\Exception $e) {
  413. return app('json')->fail($e->getMessage());
  414. }
  415. StoreOrderStatus::status($orderInfo['id'], 'refund_price', '退款给用户' . $price . '元');
  416. //退佣金
  417. $brokerage_list = UserBill::where('category', 'now_money')
  418. ->where('type', 'brokerage')
  419. ->where('link_id', $orderId)
  420. ->where('pm', 1)
  421. ->select()->toArray();
  422. if ($brokerage_list)
  423. foreach ($brokerage_list as $item) {
  424. $usermoney = User::where('uid', $item['uid'])->value('brokerage_price');
  425. if ($item['number'] > $usermoney)
  426. $item['number'] = $usermoney;
  427. User::bcDec($item['uid'], 'brokerage_price', $item['number'], 'uid');
  428. UserBill::expend('退款退佣金', $item['uid'], 'now_money', 'brokerage', $item['number'], $orderId, bcsub($usermoney, $item['number'], 2), '订单退款扣除佣金' . floatval($item['number']) . '元');
  429. }
  430. //退款扣除用户积分
  431. //购买赠送的积分
  432. $bill_integral = UserBill::where('category', 'integral')
  433. ->where('type', 'gain')
  434. ->where('link_id', $orderId)
  435. ->where('pm', 1)
  436. ->find();
  437. if ($bill_integral) {
  438. $bill_integral = $bill_integral->toArray();
  439. //用户积分
  440. $user_integral = User::where('uid', $bill_integral['uid'])->value('integral');
  441. if ($bill_integral['number'] > $user_integral)
  442. $bill_integral['number'] = $user_integral;
  443. User::bcDec($bill_integral['uid'], 'integral', $bill_integral['number'], 'uid');
  444. UserBill::expend('退款扣除积分', $bill_integral['uid'], 'integral', 'gain', $bill_integral['number'], $orderId, bcsub($user_integral, $bill_integral['number'], 2), '订单退款扣除积分' . floatval($bill_integral['number']) . '积分');
  445. }
  446. return app('json')->successful('修改成功!');
  447. } else {
  448. StoreOrderStatus::status($orderInfo['id'], 'refund_price', '退款给用户' . $price . '元失败');
  449. return app('json')->successful('修改失败!');
  450. }
  451. }
  452. /**
  453. * 门店核销
  454. * @param Request $request
  455. */
  456. public function order_verific(Request $request)
  457. {
  458. list($verify_code, $is_confirm) = UtilService::postMore([
  459. ['verify_code', ''],
  460. ['is_confirm', 0]
  461. ], $request, true);
  462. if (!$verify_code) return app('json')->fail('缺少核销码');
  463. $orderInfo = StoreOrder::where('verify_code', $verify_code)->where('paid', 1)->where('refund_status', 0)->find();
  464. if (!$orderInfo) return app('json')->fail('核销的订单不存在或未支付或已退款');
  465. if ($orderInfo->status > 0) return app('json')->fail('订单已经核销');
  466. if ($orderInfo->combination_id && $orderInfo->pink_id) {
  467. $res = StorePink::where('id', $orderInfo->pink_id)->where('status', '<>', 2)->count();
  468. if ($res) return app('json')->fail('拼团订单暂未成功无法核销!');
  469. }
  470. if (!$is_confirm) {
  471. $orderInfo['image'] = StoreCart::getProductImage($orderInfo->cart_id);
  472. return app('json')->success($orderInfo->toArray());
  473. }
  474. StoreOrder::beginTrans();
  475. try {
  476. $uid = $request->uid();
  477. if (SystemStoreStaff::verifyStatus($uid) && ($storeStaff = SystemStoreStaff::where('uid', $uid)->field(['store_id', 'id'])->find())) {
  478. $orderInfo->store_id = $storeStaff['store_id'];
  479. $orderInfo->clerk_id = $storeStaff['id'];
  480. }
  481. $orderInfo->status = 2;
  482. if ($orderInfo->save()) {
  483. OrderRepository::storeProductOrderTakeDeliveryAdmin($orderInfo);
  484. StoreOrderStatus::status($orderInfo->id, 'take_delivery', '已核销');
  485. event('ShortMssageSend', [$orderInfo['order_id'], 'Receiving']);
  486. StoreOrder::commitTrans();
  487. return app('json')->success('核销成功');
  488. } else {
  489. StoreOrder::rollbackTrans();
  490. return app('json')->fail('核销失败');
  491. }
  492. } catch (\PDOException $e) {
  493. StoreOrder::rollbackTrans();
  494. return app('json')->fail($e->getMessage());
  495. }
  496. }
  497. }