Order.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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\controller\supplier;
  12. use app\common\controller\Order as CommonOrder;
  13. use app\Request;
  14. use app\services\order\StoreOrderDeliveryServices;
  15. use app\services\order\StoreOrderServices;
  16. use app\services\store\DeliveryServiceServices;
  17. use app\services\order\supplier\SupplierOrderServices;
  18. use think\facade\App;
  19. /**
  20. * Class Order
  21. * @package app\controller\supplier
  22. * @property Request $request
  23. */
  24. class Order extends AuthController
  25. {
  26. use CommonOrder;
  27. protected $orderServices;
  28. /**
  29. * Order constructor.
  30. * @param App $app
  31. * @param SupplierOrderServices $service
  32. * @param StoreOrderServices $orderServices
  33. */
  34. public function __construct(App $app, SupplierOrderServices $supplierOrderServices, StoreOrderServices $services)
  35. {
  36. parent::__construct($app);
  37. $this->services = $services;
  38. $this->supplierOrderServices = $supplierOrderServices;
  39. }
  40. /**
  41. * 获取订单列表
  42. * @param Request $request
  43. * @return mixed
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\DbException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. */
  48. public function lst(Request $request)
  49. {
  50. $where = $request->getMore([
  51. ['status', ''],
  52. ['real_name', ''],
  53. ['is_del', ''],
  54. ['data', '', '', 'time'],
  55. ['type', ''],
  56. ['pay_type', ''],
  57. ['order', ''],
  58. ['field_key', ''],
  59. ]);
  60. $where['type'] = trim($where['type']);
  61. $where['is_system_del'] = 0;
  62. if (!$where['real_name'] && !in_array($where['status'], [-1, -2, -3])) {
  63. $where['pid'] = 0;
  64. }
  65. $where['supplier_id'] = $this->supplierId;
  66. return $this->success($this->services->getOrderList($where, ['*'], ['split' => function ($query) {
  67. $query->field('id,pid');
  68. }, 'pink', 'invoice']));
  69. }
  70. /**
  71. *获取所有配送员列表
  72. */
  73. public function get_delivery_list()
  74. {
  75. /** @var DeliveryServiceServices $deliverServices */
  76. $deliverServices = app()->make(DeliveryServiceServices::class);
  77. $data = $deliverServices->getDeliveryList(2, (int)$this->supplierId);
  78. return $this->success($data);
  79. }
  80. /**
  81. * 订单发送货
  82. * @param Request $request
  83. * @param StoreOrderDeliveryServices $services
  84. * @param $id
  85. * @return mixed
  86. * @throws \think\db\exception\DataNotFoundException
  87. * @throws \think\db\exception\DbException
  88. * @throws \think\db\exception\ModelNotFoundException
  89. */
  90. public function update_delivery(Request $request, StoreOrderDeliveryServices $services, $id)
  91. {
  92. $data = $request->postMore([
  93. ['type', 1],
  94. ['delivery_name', ''],//快递公司名称
  95. ['delivery_id', ''],//快递单号
  96. ['delivery_code', ''],//快递公司编码
  97. ['express_record_type', 2],//发货记录类型
  98. ['express_temp_id', ""],//电子面单模板
  99. ['to_name', ''],//寄件人姓名
  100. ['to_tel', ''],//寄件人电话
  101. ['to_addr', ''],//寄件人地址
  102. ['sh_delivery_name', ''],//送货人姓名
  103. ['sh_delivery_id', ''],//送货人电话
  104. ['sh_delivery_uid', ''],//送货人ID
  105. ['delivery_type', 1],//送货类型
  106. ['station_type', 1],//送货类型
  107. ['cargo_weight', 0],//重量
  108. ['mark', '', '', 'remark'],//管理员备注
  109. ['remark', '', '', 'delivery_remark'],//第三方配送备注
  110. ['fictitious_content', '']//虚拟发货内容
  111. ]);
  112. if (!$id) {
  113. return app('json')->fail('缺少发货ID');
  114. }
  115. $services->setItem('supplier_id', $this->supplierId);
  116. $res = $services->delivery((int)$id, $data);
  117. $services->reset();
  118. return app('json')->success('SUCCESS', $res);
  119. }
  120. /**
  121. * 订单拆单发送货
  122. * @param Request $request
  123. * @param StoreOrderDeliveryServices $services
  124. * @param $id
  125. * @return mixed
  126. * @throws \think\db\exception\DataNotFoundException
  127. * @throws \think\db\exception\DbException
  128. * @throws \think\db\exception\ModelNotFoundException
  129. */
  130. public function split_delivery(Request $request, StoreOrderDeliveryServices $services, $id)
  131. {
  132. $data = $request->postMore([
  133. ['type', 1],
  134. ['delivery_name', ''],//快递公司名称
  135. ['delivery_id', ''],//快递单号
  136. ['delivery_code', ''],//快递公司编码
  137. ['express_record_type', 2],//发货记录类型
  138. ['express_temp_id', ""],//电子面单模板
  139. ['to_name', ''],//寄件人姓名
  140. ['to_tel', ''],//寄件人电话
  141. ['to_addr', ''],//寄件人地址
  142. ['sh_delivery_name', ''],//送货人姓名
  143. ['sh_delivery_id', ''],//送货人电话
  144. ['sh_delivery_uid', ''],//送货人ID
  145. ['delivery_type', 1],//送货类型
  146. ['station_type', 1],//送货类型
  147. ['cargo_weight', 0],//重量
  148. ['mark', ''],//备注
  149. ['remark', ''],//配送备注
  150. ['fictitious_content', ''],//虚拟发货内容
  151. ['cart_ids', []]
  152. ]);
  153. if (!$id) {
  154. return app('json')->fail('缺少发货ID');
  155. }
  156. if (!$data['cart_ids']) {
  157. return app('json')->fail('请选择发货商品');
  158. }
  159. foreach ($data['cart_ids'] as $cart) {
  160. if (!isset($cart['cart_id']) || !$cart['cart_id'] || !isset($cart['cart_num']) || !$cart['cart_num']) {
  161. return app('json')->fail('请重新选择发货商品,或发货件数');
  162. }
  163. }
  164. $services->setItem('supplier_id', $this->supplierId);
  165. $services->splitDelivery((int)$id, $data);
  166. $services->reset();
  167. return app('json')->success('SUCCESS');
  168. }
  169. /**
  170. * 获取订单拆分子订单列表
  171. * @return mixed
  172. */
  173. public function split_order(Request $request, $id)
  174. {
  175. if (!$id) {
  176. return app('json')->fail('缺少订单ID');
  177. }
  178. $where = ['pid' => $id, 'is_system_del' => 0, 'supplier_id' => $this->supplierId];
  179. if (!$this->services->count($where)) {
  180. $where = ['id' => $id, 'is_system_del' => 0, 'supplier_id' => $this->supplierId];
  181. }
  182. return app('json')->success($this->services->getSplitOrderList($where, ['*'], ['split', 'pink', 'invoice', 'supplier']));
  183. }
  184. /**
  185. * 易联云打印机打印
  186. * @param $id
  187. * @return mixed
  188. */
  189. public function order_print($id)
  190. {
  191. if (!$id) return app('json')->fail('缺少参数');
  192. $order = $this->services->get($id);
  193. if (!$order) {
  194. return app('json')->fail('订单没有查到,无法打印!');
  195. }
  196. $res = $this->services->orderPrint((int)$id, 2, (int)$this->supplierId);
  197. if ($res) {
  198. return app('json')->success('打印成功');
  199. } else {
  200. return app('json')->fail('打印失败');
  201. }
  202. }
  203. }