StoreOrder.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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. $this->services->delivery($order_id, $data);
  87. return app('json')->success(100010);
  88. }
  89. /**
  90. * 获取订单可拆分发货商品列表
  91. * @param string $order_id 订单号
  92. * @return mixed
  93. */
  94. public function splitCartInfo(string $order_id)
  95. {
  96. if (!$order_id) return app('json')->fail(100100);
  97. return app('json')->success($this->services->getCartList($order_id));
  98. }
  99. /**
  100. * 订单拆单发送货
  101. * @param string $order_id 订单号
  102. * @return mixed
  103. */
  104. public function splitDelivery(string $order_id)
  105. {
  106. if (!$order_id) return app('json')->fail(100100);
  107. $data = $this->request->postMore([
  108. ['delivery_name', ''],//快递公司名称
  109. ['delivery_id', ''],//快递单号
  110. ['delivery_code', ''],//快递公司编码
  111. ['fictitious_content', ''],//虚拟发货内容
  112. ['cart_ids', []]
  113. ]);
  114. if (!$data['cart_ids']) {
  115. return app('json')->fail(400158);
  116. }
  117. foreach ($data['cart_ids'] as &$cart) {
  118. if (!isset($cart['cart_id']) || !$cart['cart_id'] || !isset($cart['cart_num']) || !$cart['cart_num']) {
  119. return app('json')->fail(400159);
  120. }
  121. $cart['cart_id'] = (int)$cart['cart_id'];
  122. $cart['cart_num'] = (int)$cart['cart_num'];
  123. }
  124. $data['express_record_type'] = 1;
  125. $data['type'] = 1;
  126. $this->services->splitDelivery($order_id, $data);
  127. return app('json')->success(100010);
  128. }
  129. /**
  130. * 确认收货
  131. * @param string $order_id 订单号
  132. * @return mixed
  133. * @throws \Exception
  134. */
  135. public function receive(string $order_id)
  136. {
  137. if (!$order_id) return app('json')->fail(100100);
  138. $this->services->receive($order_id);
  139. return app('json')->success(400117);
  140. }
  141. /**
  142. * 设置发票信息
  143. * @param string $order_id 订单号
  144. * @return mixed
  145. */
  146. public function setInvoice(string $order_id)
  147. {
  148. if (!$order_id) return app('json')->fail(100100);
  149. $data = $this->request->postMore([
  150. [['header_type', 'd'], 1],
  151. [['type', 'd'], 1],
  152. ['drawer_phone', ''],
  153. ['email', ''],
  154. ['name', ''],
  155. ['duty_number', ''],
  156. ['tell', ''],
  157. ['address', ''],
  158. ['bank', ''],
  159. ['card_number', ''],
  160. ]);
  161. if (!$data['drawer_phone']) return app('json')->fail(410144);
  162. if (!check_phone($data['drawer_phone'])) return app('json')->fail(410018);
  163. if (!$data['name']) return app('json')->fail(410145);
  164. if (!in_array($data['header_type'], [1, 2])) {
  165. $data['header_type'] = empty($data['duty_number']) ? 1 : 2;
  166. }
  167. if ($data['header_type'] == 1 && !preg_match('/^[\x80-\xff]{2,60}$/', $data['name'])) {
  168. return app('json')->fail(410146);
  169. }
  170. if ($data['header_type'] == 2 && !preg_match('/^[0-9a-zA-Z&\(\)\(\)\x80-\xff]{2,150}$/', $data['name'])) {
  171. return app('json')->fail(410146);
  172. }
  173. if ($data['header_type'] == 2 && !$data['duty_number']) {
  174. return app('json')->fail(410147);
  175. }
  176. 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'])) {
  177. return app('json')->fail(410148);
  178. }
  179. if ($data['card_number'] && !preg_match('/^[1-9]\d{11,19}$/', $data['card_number'])) {
  180. return app('json')->fail(410149);
  181. }
  182. if ($this->services->setInvoice($order_id, $data)) {
  183. return app('json')->success(100001);
  184. } else {
  185. return app('json')->fail(100005);
  186. }
  187. }
  188. /**
  189. * 设置发票状态
  190. * @param string $order_id 订单号
  191. * @return mixed
  192. */
  193. public function setInvoiceStatus(string $order_id)
  194. {
  195. if (!$order_id) return app('json')->fail(100100);
  196. $data = $this->request->postMore([
  197. ['is_invoice', 0],
  198. ['invoice_number', 0],
  199. ['remark', '']
  200. ]);
  201. if ($data['is_invoice'] == 1 && !$data['invoice_number']) {
  202. return app('json')->fail(400166);
  203. }
  204. if ($data['invoice_number'] && !preg_match('/^\d{8,10}$/', $data['invoice_number'])) {
  205. return app('json')->fail(400167);
  206. }
  207. $this->services->setInvoice($order_id, $data);
  208. return app('json')->success(100014);
  209. }
  210. /**
  211. * 订单详情
  212. * @param string $order_id 订单号
  213. * @return mixed
  214. */
  215. public function read(string $order_id)
  216. {
  217. if (!$order_id) return app('json')->fail(100100);
  218. return app('json')->success($this->services->getInfo($order_id));
  219. }
  220. /**
  221. * 修改备注
  222. * @param string $order_id 订单号
  223. * @return mixed
  224. */
  225. public function remark(string $order_id)
  226. {
  227. if (!$order_id) return app('json')->fail(100100);
  228. $data = $this->request->postMore([['remark', '']]);
  229. if (!$data['remark']) return app('json')->fail(400106);
  230. if (!$order = $this->services->get(['order_id' => $order_id])) {
  231. return app('json')->fail(400118);
  232. }
  233. $order->remark = $data['remark'];
  234. if ($order->save()) {
  235. return app('json')->success(100024);
  236. } else
  237. return app('json')->fail(100025);
  238. }
  239. /**
  240. * 修改配送信息
  241. * @param string $order_id 订单号
  242. * @return mixed
  243. */
  244. public function updateDistribution(string $order_id)
  245. {
  246. if (!$order_id) return app('json')->fail(100100);
  247. $data = $this->request->postMore([['delivery_name', ''], ['delivery_code', ''], ['delivery_id', '']]);
  248. $this->services->updateDistribution($order_id, $data);
  249. return app('json')->success(100010);
  250. }
  251. }