StoreOrder.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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\outapi\controller;
  12. use app\services\order\OutStoreOrderServices;
  13. use app\services\shipping\ExpressServices;
  14. use crmeb\services\CacheService;
  15. use think\facade\App;
  16. /**
  17. * 订单管理
  18. * Class StoreOrder
  19. * @package app\outapi\controller
  20. */
  21. class StoreOrder extends AuthController
  22. {
  23. /**
  24. * StoreOrder constructor.
  25. * @param App $app
  26. * @param OutStoreOrderServices $service
  27. * @method temp
  28. */
  29. public function __construct(App $app, OutStoreOrderServices $service)
  30. {
  31. parent::__construct($app);
  32. $this->services = $service;
  33. }
  34. /**
  35. * 获取订单列表
  36. * @return mixed
  37. */
  38. public function lst()
  39. {
  40. $where = $this->request->getMore([
  41. ['status', ''],
  42. ['real_name', ''],
  43. ['is_del', ''],
  44. ['data', '', '', 'time'],
  45. ['type', ''],
  46. ['pay_type', ''],
  47. ['order', ''],
  48. ['field_key', ''],
  49. ['paid', '']
  50. ]);
  51. $where['is_system_del'] = 0;
  52. $where['pid'] = 0;
  53. return app('json')->success($this->services->getOrderList($where));
  54. }
  55. /**
  56. * 快递公司列表
  57. * @return mixed
  58. */
  59. public function express(ExpressServices $services)
  60. {
  61. [$status] = $this->request->getMore([
  62. ['status', ''],
  63. ], true);
  64. if ($status != '') $data['status'] = $status;
  65. $data['is_show'] = 1;
  66. $list = CacheService::remember('EXPRESS_LIST', function () use ($services, $data) {
  67. return $services->express($data);
  68. }, 86400);
  69. return app('json')->success($list);
  70. }
  71. /**
  72. * 订单发货
  73. * @param string $order_id 订单号
  74. * @return mixed
  75. */
  76. public function delivery(string $order_id)
  77. {
  78. if (!$order_id) return app('json')->fail(100100);
  79. $data = $this->request->postMore([
  80. ['delivery_name', ''],//快递公司名称
  81. ['delivery_id', ''],//快递单号
  82. ['delivery_code', ''],//快递公司编码
  83. ]);
  84. $data['express_record_type'] = 1;
  85. $data['type'] = 1;
  86. return app('json')->success(100010, $this->services->delivery($order_id, $data));
  87. }
  88. /**
  89. * 获取订单可拆分发货商品列表
  90. * @param string $order_id 订单号
  91. * @return mixed
  92. */
  93. public function splitCartInfo(string $order_id)
  94. {
  95. if (!$order_id) return app('json')->fail(100100);
  96. return app('json')->success($this->services->getCartList($order_id));
  97. }
  98. /**
  99. * 订单拆单发送货
  100. * @param string $order_id 订单号
  101. * @return mixed
  102. */
  103. public function splitDelivery(string $order_id)
  104. {
  105. if (!$order_id) return app('json')->fail(100100);
  106. $data = $this->request->postMore([
  107. ['delivery_name', ''],//快递公司名称
  108. ['delivery_id', ''],//快递单号
  109. ['delivery_code', ''],//快递公司编码
  110. ['fictitious_content', ''],//虚拟发货内容
  111. ['cart_ids', []]
  112. ]);
  113. if (!$data['cart_ids']) {
  114. return app('json')->fail(400158);
  115. }
  116. foreach ($data['cart_ids'] as &$cart) {
  117. if (!isset($cart['cart_id']) || !$cart['cart_id'] || !isset($cart['cart_num']) || !$cart['cart_num']) {
  118. return app('json')->fail(400159);
  119. }
  120. $cart['cart_id'] = (int)$cart['cart_id'];
  121. $cart['cart_num'] = (int)$cart['cart_num'];
  122. }
  123. $data['express_record_type'] = 1;
  124. $data['type'] = 1;
  125. $this->services->splitDelivery($order_id, $data);
  126. return app('json')->success(100010);
  127. }
  128. /**
  129. * 确认收货
  130. * @param string $order_id 订单号
  131. * @return mixed
  132. * @throws \Exception
  133. */
  134. public function receive(string $order_id)
  135. {
  136. if (!$order_id) return app('json')->fail(100100);
  137. $this->services->receive($order_id);
  138. return app('json')->success(400117);
  139. }
  140. /**
  141. * 设置发票信息
  142. * @param string $order_id 订单号
  143. * @return mixed
  144. */
  145. public function setInvoice(string $order_id)
  146. {
  147. if (!$order_id) return app('json')->fail(100100);
  148. $data = $this->request->postMore([
  149. [['header_type', 'd'], 1],
  150. [['type', 'd'], 1],
  151. ['drawer_phone', ''],
  152. ['email', ''],
  153. ['name', ''],
  154. ['duty_number', ''],
  155. ['tell', ''],
  156. ['address', ''],
  157. ['bank', ''],
  158. ['card_number', ''],
  159. ]);
  160. if (!$data['drawer_phone']) return app('json')->fail(410144);
  161. if (!check_phone($data['drawer_phone'])) return app('json')->fail(410018);
  162. if (!$data['name']) return app('json')->fail(410145);
  163. if (!in_array($data['header_type'], [1, 2])) {
  164. $data['header_type'] = empty($data['duty_number']) ? 1 : 2;
  165. }
  166. if ($data['header_type'] == 1 && !preg_match('/^[\x80-\xff]{2,60}$/', $data['name'])) {
  167. return app('json')->fail(410146);
  168. }
  169. if ($data['header_type'] == 2 && !preg_match('/^[0-9a-zA-Z&\(\)\(\)\x80-\xff]{2,150}$/', $data['name'])) {
  170. return app('json')->fail(410146);
  171. }
  172. if ($data['header_type'] == 2 && !$data['duty_number']) {
  173. return app('json')->fail(410147);
  174. }
  175. if ($data['header_type'] == 2 && !preg_match('/^[A-Z0-9]{15}$|^[A-Z0-9]{17}$|^[A-Z0-9]{18}$|^[A-Z0-9]{20}$/', $data['duty_number'])) {
  176. return app('json')->fail(410148);
  177. }
  178. if ($data['card_number'] && !preg_match('/^[1-9]\d{11,19}$/', $data['card_number'])) {
  179. return app('json')->fail(410149);
  180. }
  181. if ($this->services->setInvoice($order_id, $data)) {
  182. return app('json')->success(100001);
  183. } else {
  184. return app('json')->fail(100005);
  185. }
  186. }
  187. /**
  188. * 设置发票状态
  189. * @param string $order_id 订单号
  190. * @return mixed
  191. */
  192. public function setInvoiceStatus(string $order_id)
  193. {
  194. if (!$order_id) return app('json')->fail(100100);
  195. $data = $this->request->postMore([
  196. ['is_invoice', 0],
  197. ['invoice_number', 0],
  198. ['remark', '']
  199. ]);
  200. if ($data['is_invoice'] == 1 && !$data['invoice_number']) {
  201. return app('json')->fail(400166);
  202. }
  203. if ($data['invoice_number'] && !preg_match('/^\d{8,10}$/', $data['invoice_number'])) {
  204. return app('json')->fail(400167);
  205. }
  206. $this->services->setInvoice($order_id, $data);
  207. return app('json')->success(100014);
  208. }
  209. /**
  210. * 订单详情
  211. * @param string $order_id 订单号
  212. * @return mixed
  213. */
  214. public function read(string $order_id)
  215. {
  216. if (!$order_id) return app('json')->fail(100100);
  217. return app('json')->success($this->services->getInfo($order_id));
  218. }
  219. /**
  220. * 修改备注
  221. * @param string $order_id 订单号
  222. * @return mixed
  223. */
  224. public function remark(string $order_id)
  225. {
  226. if (!$order_id) return app('json')->fail(100100);
  227. $data = $this->request->postMore([['remark', '']]);
  228. if (!$data['remark']) return app('json')->fail(400106);
  229. if (!$order = $this->services->get(['order_id' => $order_id])) {
  230. return app('json')->fail(400118);
  231. }
  232. $order->remark = $data['remark'];
  233. if ($order->save()) {
  234. return app('json')->success(100024);
  235. } else
  236. return app('json')->fail(100025);
  237. }
  238. /**
  239. * 修改配送信息
  240. * @param string $order_id 订单号
  241. * @return mixed
  242. */
  243. public function updateDistribution(string $order_id)
  244. {
  245. if (!$order_id) return app('json')->fail(100100);
  246. $data = $this->request->postMore([['delivery_name', ''], ['delivery_code', ''], ['delivery_id', '']]);
  247. $this->services->updateDistribution($order_id, $data);
  248. return app('json')->success(100010);
  249. }
  250. }