geek преди 4 години
родител
ревизия
1801f0d066

+ 1 - 1
application/api/controller/Admin.php

@@ -119,7 +119,7 @@ class Admin extends BaseController {
      *       mediaType="multipart/form-data",
      *         @OA\Schema(
      *           @OA\Property(description="登入账号", property="account", type="string", default="admin"),
-     *           @OA\Property(description="登入密码", property="password", type="string", default="123456"),
+     *           @OA\Property(description="登入密码", property="password", type="string", default="fbbede32f31a195334a6e1956f523b36"),
      *           @OA\Property(description="验证码", property="code", type="string", default="9999"),
      *           @OA\Property(description="生成验证码时的唯一码", property="uniqueKey", type="string", default="sdafsdfsd"),
      *           @OA\Property(description="mac地址", property="macAddress", type="string", default="sdafsdfsd"),

+ 16 - 2
application/api/controller/Order.php

@@ -19,6 +19,8 @@ use app\api\model\OrderProductModel;
 use app\api\model\OrderRoomModel;
 use app\api\model\ProductModel;
 use app\api\model\RoomModel;
+use app\api\model\StaffModel;
+use app\api\model\TurnStaffModel;
 use app\api\model\UserModel;
 use app\api\model\WriteOffModel;
 use app\common\service\OrderService;
@@ -343,7 +345,8 @@ class Order extends BaseController {
      *         @OA\Schema(
      *           @OA\Property(description="订单id", property="orderId", type="integer", default="1"),
      *           @OA\Property(description="职员id", property="staffId", type="integer", default="1"),
-     *           required={"orderId","staffId"})
+     *           @OA\Property(description="是否轮班", property="isTurn", type="integer", default="1"),
+     *           required={"orderId"})
      *       )
      *     ),
      *   @OA\Response(response="200", description="请求成功")
@@ -353,10 +356,12 @@ class Order extends BaseController {
         $input = Until::getInput();
         $rule = [
             'orderId|订单id' => 'require',
-            'staffId|职员id' => 'require',
+//            'staffId|职员id' => 'require',
         ];
+
         Until::check($rule, $input);
         $model = new OrderModel();
+        $orderInfo = $model::where(['id' => (int)$input['orderId']])->find();
         $allocateModel = new AllocateModel();
         $rs = $allocateModel::where(['order_id' => (int)$input['orderId']])->find();
         if (empty($rs)) {
@@ -371,9 +376,16 @@ class Order extends BaseController {
             }elseif ($rs['status'] == 3) {
                 throw new ApiException('服务已结束,无法分配职员');
             }
+            if (empty($input['staffId'])) {
+                $where[] = ['s.status', '=', 1];
+                $where[] = ['sto.id', '=', $orderInfo['store_id']];
+                $turnInfo = (new StaffModel())->getTurnInfo();
+                $input['staffId'] = $turnInfo['staffId'];
+            }
             $allocateModel::where(['id' => $rs['id']])->update(['staff_id' => $input['staffId'],'assign_admin_id' => $this->adminId]);
         }
         $model::where(['id' => (int)$input['orderId']])->update(['staff_id' => (int)$input['staffId']]);
+        (new StaffModel())::where(['id' => $input['staffId']])->update(['server_status' => 2]);
         Until::output();
     }
 
@@ -427,6 +439,7 @@ class Order extends BaseController {
         }
         (new RoomModel())::where(['id' => $orderRoomRs['room_id']])->update(['room_server_status' => 2]);
         $allocateModel::where(['id' => $rs['id']])->update(['status' => 2, 'start_admin_id' => $this->adminId,'server_start_time' => date('Y-m-d H:i:s')]);
+        (new StaffModel())::where(['id' => $input['staffId']])->update(['server_status' => 3]);
         Until::output();
     }
 
@@ -466,6 +479,7 @@ class Order extends BaseController {
         $model::where(['id' => $input['orderId']])->update(['status' => 5]);
         $orderRoomRs = (new OrderRoomModel())::where(['order_id' => $input['orderId']])->find();
         (new RoomModel())::where(['id' => $orderRoomRs['room_id']])->update(['room_server_status' => 3]);
+        (new StaffModel())::where(['id' => $input['staffId']])->update(['server_status' => 1]);
         Until::output();
     }
 

+ 23 - 6
application/api/controller/Staff.php

@@ -25,6 +25,7 @@ class Staff extends BaseController {
      *   @OA\Parameter(name="page", in="query", description="页码", @OA\Schema(type="ineger",default="1")),
      *   @OA\Parameter(name="pageSize", in="query", description="页尺寸", @OA\Schema(type="integer",default="10")),
      *   @OA\Parameter(name="status", in="query", description="状态 1正常 2删除", @OA\Schema(type="integer",default="1")),
+     *   @OA\Parameter(name="serverStatus", in="query", description="服务状态1空闲 2待服务 3服务中", @OA\Schema(type="integer",default="1")),
      *   @OA\Parameter(name="name", in="query", description="职员名", @OA\Schema(type="string")),
      *   @OA\Parameter(name="mobile", in="query", description="手机号", @OA\Schema(type="string")),
      *   @OA\Parameter(name="storeId", in="query", description="门店(多个逗号分隔)", @OA\Schema(type="integer")),
@@ -52,6 +53,10 @@ class Staff extends BaseController {
             $where[] = ['s.staff_name|s.staff_code', 'like', "%{$input['name']}%"];
         }
 
+        if (!empty($input['serverStatus'])) {
+            $where[] = ['s.server_status', '=', $input['serverStatus']];
+        }
+
         if (!empty($input['mobile'])) {
             $where[] = ['s.mobile', 'like', "%{$input['mobile']}%"];
         }
@@ -192,21 +197,33 @@ class Staff extends BaseController {
      *   summary="获取排班职员列表",
      *   @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
      *   @OA\Parameter(name="storeId", in="query", description="门店id", @OA\Schema(type="ineger",default="1")),
+     *   @OA\Parameter(name="serverStatus", in="query", description="服务状态1空闲 2待服务 3服务中", @OA\Schema(type="ineger",default="1")),
      *   @OA\RequestBody(
      *     ),
      *   @OA\Response(response="200", description="请求成功")
      * )
      */
-    public function turnStaffList($id, $status) {
+    public function turnStaffList() {
         $input = Until::getInput();
         $rule = [
-            'storeId|storeId'   => 'require',
+            'storeId'   => 'require',
+            'serverStatus'   => 'require',
         ];
         Until::check($rule, $input);
         $model = new StaffModel();
-        $where[] = ['id', '=', (int)$id];
-        $data = ['status' => (int)$status];
-        $isSuccess = $model::where($where)->update($data);
-        Until::output(['isSuccess' => $isSuccess]);
+        $where[] = ['s.status', '=', 1];
+        if (!empty($input['storeId'])) {
+            $where[] = ['sto.id', '=', (int)$input['storeId']];
+        }
+        if (!empty($input['serverStatus'])) {
+            $where[] = ['s.server_status', '=', (int)$input['serverStatus']];
+        }
+        $model->setWhere($where);
+        $data = $model->getTurnList();
+        foreach ($data['list']  as &$v) {
+            $v['today_order_num'] = $v['today_order_num'] ?: 0;
+            $v['yesterday_order_num'] = $v['yesterday_order_num'] ?: 0;
+        }
+        Until::output($data);
     }
 }

+ 42 - 0
application/api/model/StaffModel.php

@@ -44,4 +44,46 @@ class StaffModel  extends BaseModel {
             ->find();
         return Until::modelToArray($selectModel);
     }
+
+    public function getTurnList() {
+        $joinType = 'INNER';
+        $countModel = $this->alias('s')
+            ->join('store sto','sto.id = s.store_id')
+            ->join('group g','g.id = sto.group_id')
+            ->join('staff_title st','st.id = s.staff_title_id','left')
+            ->join('group_role gr','g.id = gr.group_id and gr.admin_id = '.Until::$adminId,$joinType);
+
+
+        $selectModel = $this->alias('s')
+            ->field('s.id staffId,s.staff_name,s.server_status,
+            sto.store_name,st.staff_title,sto.id storeId,sto.group_id,
+            g.group_name,
+            ts.today_order_num,ts.yesterday_order_num')
+            ->join('store sto','sto.id = s.store_id')
+            ->join('group g','g.id = sto.group_id')
+            ->join('turn_staff ts','ts.staff_id = s.id','left')
+            ->join('group_role gr','g.id = gr.group_id and gr.admin_id = '.Until::$adminId,$joinType)
+            ->join('staff_title st','st.id = s.staff_title_id','left')
+            ->order(['ts.today_order_num' => 'asc','ts.yesterday_order_num' => 'asc']);
+        return $this->joinModelPageList($countModel, $selectModel);
+    }
+
+    public function getTurnInfo() {
+        $joinType = 'INNER';
+
+        $selectModel = $this->alias('s')
+            ->field('s.id staffId,s.staff_name,s.server_status,
+            sto.store_name,st.staff_title,sto.id storeId,sto.group_id,
+            g.group_name,
+            ts.today_order_num,ts.yesterday_order_num')
+            ->join('store sto','sto.id = s.store_id')
+            ->join('group g','g.id = sto.group_id')
+            ->join('turn_staff ts','ts.staff_id = s.id','left')
+            ->join('group_role gr','g.id = gr.group_id and gr.admin_id = '.Until::$adminId,$joinType)
+            ->join('staff_title st','st.id = s.staff_title_id','left')
+            ->order(['ts.today_order_num' => 'asc','ts.yesterday_order_num' => 'asc'])
+            ->where($this->getWhere())
+            ->find();
+        return Until::modelToArray($selectModel);
+    }
 }

+ 13 - 0
application/api/model/TurnStaffModel.php

@@ -0,0 +1,13 @@
+<?php
+/**
+ * Author: luzheng.liu
+ * Time: 2021/5/10 19:33
+ */
+
+namespace app\api\model;
+
+
+class TurnStaffModel extends BaseModel {
+
+    protected $table = 'turn_staff';
+}

+ 3 - 0
application/common/service/OrderService.php

@@ -14,6 +14,7 @@ use app\api\model\CartModel;
 use app\api\model\OrderModel;
 use app\api\model\OrderProductModel;
 use app\api\model\ProductModel;
+use app\api\model\StaffModel;
 use app\api\model\StoreModel;
 use app\api\model\UserModel;
 use app\api\model\WriteOffModel;
@@ -21,6 +22,7 @@ use app\common\until\Until;
 use GuzzleHttp\Client;
 use think\facade\Cache;
 use think\facade\Config;
+use think\Model;
 use const http\Client\Curl\Features\UNIX_SOCKETS;
 
 class OrderService {
@@ -72,6 +74,7 @@ class OrderService {
                 'assign_admin_id'   => Until::$adminId,
                 'server_start_time' => $input['appointmentTime'],
             ]);
+            (new StaffModel())::where(['id' => $input['staffId']])->update(['server_status' => 2]);
             $opModel = new OrderProductModel();
             $opModel->insert([
                 'order_id'        => $orderId,

+ 0 - 25
application/cron/Staff.php

@@ -1,25 +0,0 @@
-<?php
-/**
- * Author: luzheng.liu
- * Time: 2021/5/7 23:14
- */
-
-namespace app\cron;
-
-
-use app\api\model\StoreModel;
-use think\db\Where;
-
-class Staff {
-
-    // php /public/index.php /cron/Staff/turnStaff
-    public function turnStaff() {
-        $yDate = date('Y-m-d H:i:s', strtotime('-1 day'));
-
-//        $storeModel = new StoreModel();
-//        $storeModel->alias('s')
-//            ->join('staff sta','sta.store_id = s.id')
-//            ->join('allocate_staff astf','astf.staff_id = sta.id')
-//            ->where([['server_start_time','','']])
-    }
-}

+ 47 - 0
application/cron/controller/Staff.php

@@ -0,0 +1,47 @@
+<?php
+/**
+ * Author: luzheng.liu
+ * Time: 2021/5/7 23:14
+ */
+
+namespace app\cron\controller;
+
+
+use app\api\model\AllocateModel;
+use app\api\model\StaffModel;
+use app\api\model\StoreModel;
+use app\api\model\TurnStaffModel;
+use app\common\until\Until;
+use think\db\Where;
+use think\Model;
+
+class Staff {
+
+    //php public/index.php /cron/Staff/turnStaff
+    public function turnStaff() {
+        $yDate = date('Y-m-d', strtotime('-1 day'));
+        var_dump($yDate);
+//        $yDate = '2021-04-29';
+        $turnModel = new TurnStaffModel();
+        $model = new AllocateModel();
+        $turnModel::update(['today_order_num' => 0]);
+        $rs = $model::field('count(*) as count,staff_id')
+            ->where([
+                ['server_start_time', '>', $yDate . ' 00:00:00'],
+                ['server_end_time', '<', $yDate . ' 23:59:59']
+            ])
+            ->group('staff_id')
+            ->select();
+        $rs = Until::modelToArray($rs);
+        foreach ($rs as $v) {
+            $rs = $turnModel::where(['staff_id' => $v['staff_id']])->find();
+            if (!empty($rs)) {
+                $turnModel::where(['staff_id' => $v['staff_id']])->update(['yesterday_order_num' => $v['count']]);
+            }else {
+                $turnModel->insertGetId(['staff_id' => $v['staff_id'],'yesterday_order_num' => $v['count']]);
+            }
+        }
+    }
+
+
+}

+ 19 - 2
public/api.yaml

@@ -154,7 +154,7 @@ paths:
                 password:
                   description: 登入密码
                   type: string
-                  default: '123456'
+                  default: fbbede32f31a195334a6e1956f523b36
                 code:
                   description: 验证码
                   type: string
@@ -977,7 +977,6 @@ paths:
             schema:
               required:
                 - orderId
-                - staffId
               properties:
                 orderId:
                   description: 订单id
@@ -987,6 +986,10 @@ paths:
                   description: 职员id
                   type: integer
                   default: '1'
+                isTurn:
+                  description: 是否轮班
+                  type: integer
+                  default: '1'
               type: object
       responses:
         '200':
@@ -2017,6 +2020,13 @@ paths:
             type: integer
             default: '1'
         -
+          name: serverStatus
+          in: query
+          description: '服务状态1空闲 2待服务 3服务中'
+          schema:
+            type: integer
+            default: '1'
+        -
           name: name
           in: query
           description: 职员名
@@ -2176,6 +2186,13 @@ paths:
           schema:
             type: ineger
             default: '1'
+        -
+          name: serverStatus
+          in: query
+          description: '服务状态1空闲 2待服务 3服务中'
+          schema:
+            type: ineger
+            default: '1'
       requestBody: {  }
       responses:
         '200':