123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- <?php
- namespace app\controller\store\staff;
- use app\services\order\store\BranchOrderServices;
- use app\services\order\StoreOrderServices;
- use think\facade\App;
- use app\controller\store\AuthController;
- use app\services\store\DeliveryServiceServices;
- use app\services\user\UserWechatuserServices;
- class StoreDelivery extends AuthController
- {
-
- public function __construct(App $app, DeliveryServiceServices $services)
- {
- parent::__construct($app);
- $this->services = $services;
- }
-
- public function index()
- {
- $where = $this->request->getMore([
- ['field_key', ''],
- ['keyword', '']
- ]);
- $where['type'] = 1;
- $where['relation_id'] = $this->storeId;
- $where['is_del'] = 0;
- return app('json')->success($this->services->getServiceList($where));
- }
-
- public function create()
- {
- return app('json')->success($this->services->createStoreDeliveryForm());
- }
-
- public function deliveryDetail($id)
- {
- $id = (int)$id;
- if (!$id) return $this->fail('缺少参数');
- return $this->success($this->services->deliveryDetail($id));
- }
-
- public function edit()
- {
- [$id] = $this->request->getMore([
- [['id', 'd'], 0],
- ], true);
- $storeDelivery = $this->services->getOne(['id' => $id, 'is_del' => 0]);
- if (!$storeDelivery) {
- return app('json')->fail('配送员不存在');
- }
- return app('json')->success($this->services->updateStoreDeliveryForm($id, $storeDelivery));
- }
-
- public function userList(UserWechatuserServices $services)
- {
- $where = $this->request->getMore([
- ['nickname', ''],
- ['data', '', '', 'time'],
- ['type', '', '', 'user_type'],
- ]);
- [$list, $count] = $services->getWhereUserList($where, 'u.nickname,u.uid,u.avatar as headimgurl,w.subscribe,w.province,w.country,w.city,w.sex');
- return app('json')->success(compact('list', 'count'));
- }
-
- public function save()
- {
- $data = $this->request->postMore([
- ['image', ''],
- ['uid', 0],
- ['avatar', ''],
- ['phone', ''],
- ['nickname', ''],
- ['status', 1],
- ]);
- if ($data['image'] == '') return $this->fail('请选择用户');
- $data['uid'] = $data['image']['uid'];
- if (!$data['nickname']) {
- return app()->fail('请输入配送员名称');
- }
- if (!check_phone($data['phone'])) {
- return app('json')->fail('请输入正确的手机号!');
- }
- if ($this->services->count(['type' => 1, 'relation_id' => $this->storeId, 'phone' => $data['phone'], 'is_del' => 0])) {
- return app('json')->fail('同一个手机号的配送员只能添加一个!');
- }
- $data['avatar'] = $data['image']['image'];
- if ($this->services->count(['uid' => $data['uid'], 'type' => 1, 'relation_id' => $this->storeId, 'is_del' => 0])) {
- return $this->fail('配送员已存在!');
- }
- unset($data['image']);
- $data['type'] = 1;
- $data['relation_id'] = $this->storeId;
- unset($data['image']);
- $data['add_time'] = time();
- $res = $this->services->save($data);
- if ($res) {
- return app('json')->success('配送员添加成功');
- } else {
- return app('json')->fail('配送员添加失败,请稍后再试');
- }
- }
-
- public function update($id)
- {
- $data = $this->request->postMore([
- ['avatar', ''],
- ['nickname', ''],
- ['phone', ''],
- ['status', 1],
- ]);
- $delivery = $this->services->get((int)$id);
- if (!$delivery) {
- return app('json')->fail('数据不存在');
- }
- if ($data["nickname"] == '') {
- return app('json')->fail("配送员名称不能为空!");
- }
- if (!$data['phone']) {
- return app('json')->fail("手机号不能为空!");
- }
- if (!check_phone($data['phone'])) {
- return app('json')->fail('请输入正确的手机号!');
- }
- if ($delivery['phone'] != $data['phone'] && $this->services->count(['type' => 1, 'relation_id' => $this->storeId, 'phone' => $data['phone'], 'is_del' => 0])) {
- return app('json')->fail('同一个手机号的配送员只能添加一个!');
- }
- $this->services->update($id, $data);
- return app('json')->success('修改成功!');
- }
-
- public function delete($id)
- {
- if (!$this->services->update($id, ['is_del' => 1]))
- return app('json')->fail('删除失败,请稍候再试!');
- else
- return app('json')->success('删除成功!');
- }
-
- public function set_status($id, $status)
- {
- if ($status == '' || $id == 0) return app('json')->fail('参数错误');
- $this->services->update($id, ['status' => $status]);
- return app('json')->success($status == 0 ? '关闭成功' : '开启成功');
- }
-
- public function getDeliverySelect()
- {
- $where['type'] = 1;
- $where['relation_id'] = $this->storeId;
- $where['is_del'] = 0;
- $where['status'] = 1;
- return app('json')->success($this->services->getSelectList($where));
- }
-
- public function get_delivery_list()
- {
- $data = $this->services->getDeliveryList(1, (int)$this->storeId);
- return $this->success($data);
- }
-
- public function statistics(StoreOrderServices $services, BranchOrderServices $orderServices)
- {
- $where = $this->request->getMore([
- ['delivery_uid', 0],
- ['data', '', '', 'time'],
- ]);
- $where['type'] = 1;
- $where['relation_id'] = $this->storeId;
- $where['time'] = $orderServices->timeHandle($where['time']);
- return app('json')->success($services->getDeliveryStatistics($where));
- }
-
- public function statisticsHeader(StoreOrderServices $services, BranchOrderServices $orderServices)
- {
- [$delivery_uid, $time] = $this->request->getMore([
- ['delivery_uid', 0],
- ['data', '', '', 'time']
- ], true);
- $time = $orderServices->timeHandle($time, true);
- $store_id = (int)$this->storeId;
- return app('json')->success($services->getStatisticsHeader($store_id, $delivery_uid, $time));
- }
- }
|