123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\controller\supplier;
- use app\common\controller\Order as CommonOrder;
- use app\Request;
- use app\services\order\StoreOrderDeliveryServices;
- use app\services\order\StoreOrderServices;
- use app\services\store\DeliveryServiceServices;
- use app\services\order\supplier\SupplierOrderServices;
- use think\facade\App;
- /**
- * Class Order
- * @package app\controller\supplier
- * @property Request $request
- */
- class Order extends AuthController
- {
- use CommonOrder;
- protected $orderServices;
- /**
- * Order constructor.
- * @param App $app
- * @param SupplierOrderServices $service
- * @param StoreOrderServices $orderServices
- */
- public function __construct(App $app, SupplierOrderServices $supplierOrderServices, StoreOrderServices $services)
- {
- parent::__construct($app);
- $this->services = $services;
- $this->supplierOrderServices = $supplierOrderServices;
- }
- /**
- * 获取订单列表
- * @param Request $request
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function lst(Request $request)
- {
- $where = $request->getMore([
- ['status', ''],
- ['real_name', ''],
- ['is_del', ''],
- ['data', '', '', 'time'],
- ['type', ''],
- ['pay_type', ''],
- ['order', ''],
- ['field_key', ''],
- ]);
- $where['type'] = trim($where['type']);
- $where['is_system_del'] = 0;
- if (!$where['real_name'] && !in_array($where['status'], [-1, -2, -3])) {
- $where['pid'] = 0;
- }
- $where['supplier_id'] = $this->supplierId;
- return $this->success($this->services->getOrderList($where, ['*'], ['split' => function ($query) {
- $query->field('id,pid');
- }, 'pink', 'invoice']));
- }
- /**
- *获取所有配送员列表
- */
- public function get_delivery_list()
- {
- /** @var DeliveryServiceServices $deliverServices */
- $deliverServices = app()->make(DeliveryServiceServices::class);
- $data = $deliverServices->getDeliveryList(2, (int)$this->supplierId);
- return $this->success($data);
- }
- /**
- * 订单发送货
- * @param Request $request
- * @param StoreOrderDeliveryServices $services
- * @param $id
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function update_delivery(Request $request, StoreOrderDeliveryServices $services, $id)
- {
- $data = $request->postMore([
- ['type', 1],
- ['delivery_name', ''],//快递公司名称
- ['delivery_id', ''],//快递单号
- ['delivery_code', ''],//快递公司编码
- ['express_record_type', 2],//发货记录类型
- ['express_temp_id', ""],//电子面单模板
- ['to_name', ''],//寄件人姓名
- ['to_tel', ''],//寄件人电话
- ['to_addr', ''],//寄件人地址
- ['sh_delivery_name', ''],//送货人姓名
- ['sh_delivery_id', ''],//送货人电话
- ['sh_delivery_uid', ''],//送货人ID
- ['delivery_type', 1],//送货类型
- ['station_type', 1],//送货类型
- ['cargo_weight', 0],//重量
- ['mark', '', '', 'remark'],//管理员备注
- ['remark', '', '', 'delivery_remark'],//第三方配送备注
- ['fictitious_content', '']//虚拟发货内容
- ]);
- if (!$id) {
- return app('json')->fail('缺少发货ID');
- }
- $services->setItem('supplier_id', $this->supplierId);
- $res = $services->delivery((int)$id, $data);
- $services->reset();
- return app('json')->success('SUCCESS', $res);
- }
- /**
- * 订单拆单发送货
- * @param Request $request
- * @param StoreOrderDeliveryServices $services
- * @param $id
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function split_delivery(Request $request, StoreOrderDeliveryServices $services, $id)
- {
- $data = $request->postMore([
- ['type', 1],
- ['delivery_name', ''],//快递公司名称
- ['delivery_id', ''],//快递单号
- ['delivery_code', ''],//快递公司编码
- ['express_record_type', 2],//发货记录类型
- ['express_temp_id', ""],//电子面单模板
- ['to_name', ''],//寄件人姓名
- ['to_tel', ''],//寄件人电话
- ['to_addr', ''],//寄件人地址
- ['sh_delivery_name', ''],//送货人姓名
- ['sh_delivery_id', ''],//送货人电话
- ['sh_delivery_uid', ''],//送货人ID
- ['delivery_type', 1],//送货类型
- ['station_type', 1],//送货类型
- ['cargo_weight', 0],//重量
- ['mark', ''],//备注
- ['remark', ''],//配送备注
- ['fictitious_content', ''],//虚拟发货内容
- ['cart_ids', []]
- ]);
- if (!$id) {
- return app('json')->fail('缺少发货ID');
- }
- if (!$data['cart_ids']) {
- return app('json')->fail('请选择发货商品');
- }
- foreach ($data['cart_ids'] as $cart) {
- if (!isset($cart['cart_id']) || !$cart['cart_id'] || !isset($cart['cart_num']) || !$cart['cart_num']) {
- return app('json')->fail('请重新选择发货商品,或发货件数');
- }
- }
- $services->setItem('supplier_id', $this->supplierId);
- $services->splitDelivery((int)$id, $data);
- $services->reset();
- return app('json')->success('SUCCESS');
- }
- /**
- * 获取订单拆分子订单列表
- * @return mixed
- */
- public function split_order(Request $request, $id)
- {
- if (!$id) {
- return app('json')->fail('缺少订单ID');
- }
- $where = ['pid' => $id, 'is_system_del' => 0, 'supplier_id' => $this->supplierId];
- if (!$this->services->count($where)) {
- $where = ['id' => $id, 'is_system_del' => 0, 'supplier_id' => $this->supplierId];
- }
- return app('json')->success($this->services->getSplitOrderList($where, ['*'], ['split', 'pink', 'invoice', 'supplier']));
- }
- /**
- * 易联云打印机打印
- * @param $id
- * @return mixed
- */
- public function order_print($id)
- {
- if (!$id) return app('json')->fail('缺少参数');
- $order = $this->services->get($id);
- if (!$order) {
- return app('json')->fail('订单没有查到,无法打印!');
- }
- $res = $this->services->orderPrint((int)$id, 2, (int)$this->supplierId);
- if ($res) {
- return app('json')->success('打印成功');
- } else {
- return app('json')->fail('打印失败');
- }
- }
- }
|