فهرست منبع

Merge branch 'master' into group_0313

dongxiaoqin 11 ماه پیش
والد
کامیت
e0730f1da6
27فایلهای تغییر یافته به همراه427 افزوده شده و 44 حذف شده
  1. 13 0
      app/adminapi/controller/external/ExternalConsultationController.php
  2. 12 5
      app/adminapi/lists/external/ExternalConsultationLists.php
  3. 5 4
      app/adminapi/lists/sale/SaleCommissionLists.php
  4. 1 1
      app/adminapi/lists/works/ServiceWorkLists.php
  5. 40 1
      app/adminapi/logic/external/ExternalConsultationLogic.php
  6. 47 4
      app/adminapi/logic/works/ServiceWorkLogic.php
  7. 1 1
      app/api/controller/GoodsController.php
  8. 24 0
      app/api/controller/ServiceOrderController.php
  9. 27 2
      app/api/logic/GoodsLogic.php
  10. 2 14
      app/api/logic/ServiceOrderLogic.php
  11. 4 0
      app/api/validate/ServiceOrderValidate.php
  12. 1 0
      app/common/controller/InternalApiController.php
  13. 1 0
      app/common/logic/ExternalPlatformLogic.php
  14. 1 1
      app/common/logic/PayNotifyLogic.php
  15. 2 1
      app/common/logic/ThirdOrderLogic.php
  16. 9 1
      app/common/model/external/ExternalConsultation.php
  17. 10 0
      app/common/model/external/ExternalConsultationFollowLog.php
  18. 10 0
      app/common/model/external/ExternalConsultationOrder.php
  19. 5 1
      app/common/model/works/ServiceWork.php
  20. 9 3
      app/workerapi/controller/LoginController.php
  21. 43 0
      app/workerapi/controller/WorksController.php
  22. 13 3
      app/workerapi/lists/MasterWorkerRegisterLists.php
  23. 38 0
      app/workerapi/lists/ServiceWorkGrabOrderLists.php
  24. 50 0
      app/workerapi/lists/ServiceWorkGrabOrderLogLists.php
  25. 2 1
      app/workerapi/logic/GoodsCategoryLogic.php
  26. 1 1
      app/workerapi/logic/LoginLogic.php
  27. 56 0
      app/workerapi/logic/MasterWorkerLogic.php

+ 13 - 0
app/adminapi/controller/external/ExternalConsultationController.php

@@ -85,6 +85,19 @@ class ExternalConsultationController extends BaseAdminController
         }
         return $this->fail(ExternalConsultationLogic::getError());
     }
+
+
+    public function followLog()
+    {
+        $params = (new ExternalConsultationValidate())->post()->goCheck('edit');
+        $result = ExternalConsultationLogic::followLog($params);
+        if (true === $result) {
+            return $this->success('添加成功', [], 1, 1);
+        }
+        return $this->fail(ExternalConsultationLogic::getError());
+    }
+
+
     /**
      * @notes 删除
      * @return \think\response\Json

+ 12 - 5
app/adminapi/lists/external/ExternalConsultationLists.php

@@ -38,12 +38,19 @@ class ExternalConsultationLists extends BaseAdminDataLists implements ListsSearc
     public function setSearch(): array
     {
         return [
-            '=' => ['external_platform_id'],
-            '%like%' => ['user_name', 'mobile', 'unique_code'],
+            '=' => ['external_platform_id','follow_status'],
+            '%like%' => ['user_name', 'mobile', 'unique_code','remark'],
         ];
     }
 
-
+    public function queryWhere(){
+        $where = [];
+        if(isset($this->params['create_time_range']) && !empty($this->params['create_time_range'][0]) && !empty($this->params['create_time_range'][1])){
+            $time = [strtotime($this->params['create_time_range'][0]), strtotime($this->params['create_time_range'][1])+86400-1];
+            $where[] = ['create_time', 'between', $time];
+        }
+        return  $where;
+    }
     /**
      * @notes 获取列表
      * @return array
@@ -55,7 +62,7 @@ class ExternalConsultationLists extends BaseAdminDataLists implements ListsSearc
      */
     public function lists(): array
     {
-        return ExternalConsultation::with(['goods'])->where($this->searchWhere)
+        return ExternalConsultation::with(['goods','customerLog','customerOrder'])->where($this->searchWhere)->where($this->queryWhere())
             ->field(['*'])
             ->limit($this->limitOffset, $this->limitLength)
             ->order(['id' => 'desc'])
@@ -72,7 +79,7 @@ class ExternalConsultationLists extends BaseAdminDataLists implements ListsSearc
      */
     public function count(): int
     {
-        return ExternalConsultation::where($this->searchWhere)->count();
+        return ExternalConsultation::where($this->searchWhere)->where($this->queryWhere())->count();
     }
 
 }

+ 5 - 4
app/adminapi/lists/sale/SaleCommissionLists.php

@@ -241,10 +241,11 @@ class SaleCommissionLists extends BaseAdminDataLists implements ListsSearchInter
             $propertyHeadIds = PropertyHead::where('sale_id','>',0)->where('is_cooperate','=',1)->where('sale_id',$sale_id)->column('id')??[];
             $groupOrderIds = GroupOrder::whereIn('property_head_id',$propertyHeadIds)->column('id')??[];
             //->whereB('pay_time',1)->
-            $paid_amounts = GroupUserOrder::whereIn('group_order_id',$groupOrderIds)
-                ->where('status',1)
-                ->whereBetween('pay_time',[$whereTime[0],$whereTime[1]])
-                ->sum('paid_amount');
+            $paid_amounts = GroupUserOrder::alias("a")->whereIn('a.group_order_id',$groupOrderIds)
+                ->join('group_service_work b','a.id = b.group_user_order_id AND b.service_status = 3')
+                ->where('a.status',1)
+                ->whereBetween('a.pay_time',[$whereTime[0],$whereTime[1]])
+                ->sum('a.paid_amount');
             $groupCounts[$sale_id] = $paid_amounts;
         }
         return $groupCounts;

+ 1 - 1
app/adminapi/lists/works/ServiceWorkLists.php

@@ -70,7 +70,7 @@ class ServiceWorkLists extends BaseAdminDataLists implements ListsSearchInterfac
     public function setSearch(): array
     {
         return [
-            '=' => ['id','category_type', 'base_service_fee', 'service_fee', 'work_status', 'service_status',  'data_type',  'finished_images', 'master_worker_id', 'work_amount','work_type','appoint_approval','refund_approval', 'city','tenant_id','third_type','group_order_id'],
+            '=' => ['id','category_type', 'base_service_fee', 'service_fee', 'work_status', 'service_status',  'data_type',  'finished_images', 'master_worker_id', 'work_amount','work_type','appoint_approval','refund_approval', 'city','tenant_id','external_platform_id','group_order_id'],
             '%like%'=>[ 'work_sn','mobile','real_name', 'title', 'address']
         ];
     }

+ 40 - 1
app/adminapi/logic/external/ExternalConsultationLogic.php

@@ -18,6 +18,8 @@ namespace app\adminapi\logic\external;
 use app\common\logic\ThirdOrderLogic;
 use app\common\model\external\ExternalConsultation;
 use app\common\logic\BaseLogic;
+use app\common\model\external\ExternalConsultationFollowLog;
+use app\common\model\external\ExternalConsultationOrder;
 use think\facade\Db;
 
 
@@ -119,6 +121,7 @@ class ExternalConsultationLogic extends BaseLogic
 
             // userName mobile goods_id userAddress amount appointment_time lon lat
             $work_id = ThirdOrderLogic::submitOrders([
+                'external_platform_id' => $params['external_platform_id'],
                 'userName' => $params['user_name'],
                 'mobile' => $params['mobile'],
                 'goods_id' => $params['goods_id'],
@@ -147,9 +150,45 @@ class ExternalConsultationLogic extends BaseLogic
                 'amount' => $params['amount'],
                 'lon' => $params['lon'],
                 'lat' => $params['lat'],
-                'work_id' => $work_id,
+                //'work_id' => $work_id,
                 'remark' => $params['remark']
             ]);
+            ExternalConsultationOrder::create([
+                'consultation_id' => $params['id'],
+                'user_address' => $params['user_address'],
+                'lon' => $params['lon'],
+                'lat' => $params['lat'],
+
+                'appointment_time' => $params['appointment_time'],
+                'goods_id' => $params['goods_id'],
+                'amount' => $params['amount'],
+                'work_id' => $work_id,
+            ]);
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+    public static function followLog(array $params): bool
+    {
+        Db::startTrans();
+        try {
+
+            $consultation = ExternalConsultation::where('id', $params['id'])->findOrEmpty();
+            if(empty($consultation->follow_start_time)) $consultation->follow_start_time  = time();
+            $consultation->follow_status = 1;
+            $consultation->save();
+
+            ExternalConsultationFollowLog::create([
+                'consultation_id' => $params['id']??0,
+                'content' => $params['content']??'',
+                'admin_id' => $params['admin_id']??0,
+                'create_time' => time(),
+            ]);
+
             Db::commit();
             return true;
         } catch (\Exception $e) {

+ 47 - 4
app/adminapi/logic/works/ServiceWorkLogic.php

@@ -21,6 +21,7 @@ use app\common\logic\ThirdOrderLogic;
 use app\common\logic\WorkerAccountLogLogic;
 use app\common\model\third\ThirdOrders;
 use app\common\model\works\ServiceWorkDeterminedPrice;
+use app\workerapi\logic\MasterWorkerLogic;
 use think\Exception;
 use think\db\Query;
 use think\facade\Db;
@@ -125,6 +126,16 @@ class ServiceWorkLogic extends BaseLogic
             //添加领单日志
             ServiceWorkReceiveLogLogic::add($work_log);
             Db::commit();
+
+            // 工单状态通知外部平台 即工程师接单成功
+            if($work->external_platform_id > 0){
+                event('ExternalPlatform',  [
+                    'send_code' => 1001,
+                    'params' => [
+                        'work_id' => $work->id,
+                    ]
+                ]);
+            }
         }
         catch (\Exception $e) {
             Db::rollback();
@@ -502,14 +513,14 @@ class ServiceWorkLogic extends BaseLogic
             if($work->work_status >=6 ){
                 throw new \Exception('工单状态只能修改待结算之前的');
             }
-            if($work->master_worker_id == $params['master_worker_id']){
+            if($work->master_worker_id == $params['master_worker_id'] && !isset($params['is_grab_order'])){
                 throw new \Exception('分配的工程师相同');
             }
             $worker = MasterWorker::where(['id'=>$params['master_worker_id'],'is_disable' =>0])->findOrEmpty();
             if($worker->isEmpty()){
                 throw new \Exception('工程师不存在或被禁用');
             }
-            if($worker->master_worker_id){
+            if($worker->master_worker_id && !isset($params['is_grab_order'])){
                 MasterWorker::setWorktotal('dec',$worker->master_worker_id);
             }
             $work->master_worker_id = $params['master_worker_id'];
@@ -520,7 +531,7 @@ class ServiceWorkLogic extends BaseLogic
             $work_log = [
                 'work_id'=>$work->id,
                 'master_worker_id'=>$work->master_worker_id,
-                'type' => 0,
+                'type' => isset($params['is_grab_order'])?3:0,
                 'opera_log'=>'后台用户['.$userInfo['admin_id'].']'.$userInfo['name'].'于'.date('Y-m-d H:i:s',time()).'分配了工程师'.'编号['.$worker->worker_number.']'.$worker->real_name
             ];
             ServiceWorkerAllocateWorkerLogic::add($work_log);
@@ -1241,5 +1252,37 @@ class ServiceWorkLogic extends BaseLogic
         }
     }
 
-
+    /**
+     * 工程师抢单
+     */
+    public static function grabOrder($params): bool
+    {
+        if(MasterWorkerLogic::isReceivingOrders($params['master_worker_id'])){
+            Log::info('抢单失败:工程师不能接单:'.$params['id'].'--'.$params['master_worker_id']);
+            self::setError('未达到接单条件');
+            return false;
+        }
+        Db::startTrans();
+        try {
+            // 抢单
+            $serviceWork = ServiceWork::where(['work_pay_status'=>1,'work_status'=>0,'service_status'=>0,'master_worker_id'=>0])
+                ->where('id',$params['id'])->update(['master_worker_id'=>$params['master_worker_id'],'work_status'=>1]);
+            Db::commit();
+            if($serviceWork == 1){
+                Log::info('抢单成功:'.$params['id'].'--'.$params['master_worker_id']);
+                $params['is_grab_order'] = 1;
+                self::allocateWorker($params,['admin_id'=>0,'name'=>'抢单工程师ID:'.$params['master_worker_id']]);
+                return true;
+            }else{
+                Log::info('抢单失败:'.$params['id'].'--'.$params['master_worker_id']);
+                self::setError('抢单失败');
+                return false;
+            }
+        } catch (\Exception $e) {
+            Db::rollback();
+            Log::info('抢单失败:'.$params['id'].'--'.$params['master_worker_id'].':'.$e->getMessage());
+            self::setError('抢单失败');
+            return false;
+        }
+    }
 }

+ 1 - 1
app/api/controller/GoodsController.php

@@ -30,7 +30,7 @@ class GoodsController extends BaseApiController
     public function categoryDetail()
     {
         $params = (new GoodsValidate())->goCheck('category');
-        $result = GoodsLogic::detail($params['goods_category_id'],'category',$this->userId);
+        $result = GoodsLogic::detail($params['goods_category_id'],'category',$this->userId,$params['service_work_id']??0);
         return $this->data($result);
     }
 

+ 24 - 0
app/api/controller/ServiceOrderController.php

@@ -308,4 +308,28 @@ class ServiceOrderController extends BaseApiController
         return $this->success('绑定成功', [], 1, 1);
     }
 
+
+    /**
+     * 终止结束服务 - 上门费直接给工程师
+     * @return \think\response\Json
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/5 19:03
+     */
+    public function terminateService()
+    {
+        $params = (new ServiceOrderValidate())->post()->goCheck('terminateService', [
+            'user_id' => $this->userId,
+            'user_info' => $this->userInfo
+        ]);
+        $params['isearnest'] = 0;
+        $result = ServiceWorkLogic::terminateService($params);
+        if (false === $result) {
+            return $this->fail(ServiceWorkLogic::getError());
+        }
+        return $this->success('终止服务成功', [], 1, 1);
+    }
+
+
+
+
 }

+ 27 - 2
app/api/logic/GoodsLogic.php

@@ -2,8 +2,10 @@
 namespace app\api\logic;
 
 use app\common\logic\BaseLogic;
+use app\common\model\external\ExternalPlatformGoods;
 use app\common\model\goods\Goods;
 use app\common\model\goods_category\GoodsCategory;
+use app\common\model\works\ServiceWork;
 use think\facade\Db;
 
 
@@ -23,9 +25,20 @@ class GoodsLogic extends BaseLogic
      * @author whitef
      * @date 2022/9/20 17:09
      */
-    public static function detail($id,$type){
+    public static function detail($id,$type,$userId = 0,$service_work_id = 0){
+        $where = [];
         if($type == 'category'){
-            $goods = Goods::where(['goods_category_id'=>$id,'user_id'=>0,'is_agent'=>0,'is_activity'=>0,'platform_value'=>0])->visible([
+            $where[] = ['goods_category_id','=',$id];
+            $where[] = ['user_id','=',0];
+            $where[] = ['is_agent','=',0];
+            $where[] = ['is_activity','=',0];
+            if($service_work_id > 0){
+                $platform_value = ServiceWork::where('id',$service_work_id)->value('external_platform_id');
+                $where[] = ['platform_value','=',$platform_value];
+            }else{
+                $where[] = ['platform_value','=',0];
+            }
+            $goods = Goods::where($where)->visible([
                 'id','goods_image','goods_name','goods_banners','good_unit','sell_num','base_service_fee',
                 'service_total','service_fee','service_image','fee_schedule','warranty_period','goods_payment_type','goods_category_id'
             ])->select()->toArray();
@@ -40,6 +53,9 @@ class GoodsLogic extends BaseLogic
         if(!empty($goods)){
             $data = [];
             foreach ($goods as $key => $value) {
+                if($service_work_id > 0){
+                    $value['service_fee'] = self::getPlatformServiceFee($platform_value,$value['id'])?:$value['service_fee'];
+                }
                 if($value['goods_payment_type'] == '2'){
                     $coupon = ($value['service_total']-$value['service_fee'])>0?'立减'.$value['service_total']-$value['service_fee']:'';
                 }
@@ -191,4 +207,13 @@ class GoodsLogic extends BaseLogic
             return false;
         }
     }
+
+    public static function getPlatformServiceFee($platform_value,$goods_id)
+    {
+        return ExternalPlatformGoods::where('external_platform_id',$platform_value)->where('goods_id',$goods_id)->value('service_fee');
+    }
+
+
+
+
 }

+ 2 - 14
app/api/logic/ServiceOrderLogic.php

@@ -177,7 +177,7 @@ class ServiceOrderLogic extends BaseLogic
             if(!empty($params['worker'])){
                 $worker_id = MasterWorker::where('worker_number',$params['worker'])->value('id');
                 $work_data['master_worker_id'] = $worker_id;
-                $work_data['work_status'] = 1;
+                $work_data['work_status'] = 4;
                 $work_data['dispatch_time'] = time();
                 $work_data['work_type'] = 2;
                 $work_data['data_type'] = 1;
@@ -439,7 +439,7 @@ class ServiceOrderLogic extends BaseLogic
             $order_info =  \app\common\model\recharge\RechargeOrder::with(['order_goods'=>function ($query) {
                 $query->visible(['goods_id','goods_name','goods_image','goods_number','good_unit']);
             },'service_work'=>function ($query) {
-                $query->visible(['id','work_sn','real_name','mobile','address','service_status','appointment_time','master_worker_id','work_images','explanation','finished_images','finished_time','spare_total','refund_approval','property_activity_id','order_effective_id'])->append(['service_status_text','user_service_status','user_service_status_text']);
+                $query->visible(['id','work_sn','real_name','mobile','address','service_status','appointment_time','master_worker_id','work_images','explanation','finished_images','finished_time','spare_total','refund_approval','property_activity_id','order_effective_id','external_platform_id'])->append(['service_status_text','user_service_status','user_service_status_text','external_platform_text']);
             }])
                 ->visible(['id','sn','payment_type','order_total','order_amount','paid_amount','pay_status','create_time','title','work_id'])
                 ->where([
@@ -863,18 +863,6 @@ class ServiceOrderLogic extends BaseLogic
                 $service_work->work_status = 6;
                 $service_work->user_confirm_status = 4;
             }
-            if(isset($params['admin_id']) && $service_work->user_confirm_status!=3){
-                \app\common\model\recharge\RechargeOrder::where([
-                    'order_type' => 0,
-                    'user_id' => $params['user_id'],
-                    'pay_status' => 0,
-                    'payment_type' => 2,
-                    'sn'=>$params['sn']
-                ])->update(['pay_status'=>1]);
-                $service_work->work_status = 7;
-                $service_work->user_confirm_status = 5;
-                $service_work->service_status = 3;
-            }
             $service_work->finished_time = time();
             $service_work->save();
 

+ 4 - 0
app/api/validate/ServiceOrderValidate.php

@@ -119,5 +119,9 @@ class ServiceOrderValidate extends BaseValidate
     {
         return $this->only(['sn','worker_id']);
     }
+    public function sceneTerminateService()
+    {
+        return $this->only(['id']);
+    }
 
 }

+ 1 - 0
app/common/controller/InternalApiController.php

@@ -99,6 +99,7 @@ class InternalApiController extends BaseLikeAdminController
             if($order->pay_status == PayEnum::ISPAID) {
                 return $this->success('内部支付已完成', [], 0, 1);
             }
+            if(!empty($params['pay_way']??'')) $params['extra']['pay_way'] = $params['pay_way'];
             $payNotifyLogic = PayNotifyLogic::handle('goods', $params['sn'], $params['extra']??[]);
             if($payNotifyLogic === true){
                 return $this->success('内部支付完成', [], 0, 1);

+ 1 - 0
app/common/logic/ExternalPlatformLogic.php

@@ -16,6 +16,7 @@ class ExternalPlatformLogic  extends BaseLogic
     {
         try {
             switch ($params['send_code']){
+                case 1001:
                 case 1002:
                 case 1003:
                 case 1005:

+ 1 - 1
app/common/logic/PayNotifyLogic.php

@@ -105,7 +105,7 @@ class PayNotifyLogic extends BaseLogic
             $order->pay_status = PayEnum::ISPAID;
             $order->pay_time = time();
             $order->paid_amount = $order->order_amount;
-
+            if(empty($extra['transaction_id']??'') && !empty($extra['pay_way']??'')) $order->pay_way = $extra['pay_way'];
             //判断是否是一口价预支付订单,支付成功后生成尾款订单
             $order_goods = OrderGoods::where('sn',$order->sn)->findOrEmpty();
             if(!$order_goods->isEmpty() and $order_goods->goods_payment_type == 3 and bcsub($order_goods->base_service_fee,$order_goods->service_fee,2)>=0){

+ 2 - 1
app/common/logic/ThirdOrderLogic.php

@@ -300,6 +300,7 @@ class ThirdOrderLogic extends BaseLogic
                 'lat'=>$message['lat'],
                 'property_activity_id'=>0,
                 'user_equity_id'=>0,
+                'external_platform_id'=>$message['external_platform_id']??0,
                 'work_total'=>$message['amount'],
                 'work_amount'=>$message['amount']
             ];
@@ -318,7 +319,7 @@ class ThirdOrderLogic extends BaseLogic
                 'pay_status' => PayEnum::ISPAID,
                 'coupon_id'=>0,
                 'coupon_price'=>0,
-                'pay_way' => 3,
+                'pay_way' => 4,
                 'order_total' => $message['amount'],
                 'order_amount' => $message['amount'],
                 'paid_amount'=>$message['amount']

+ 9 - 1
app/common/model/external/ExternalConsultation.php

@@ -39,5 +39,13 @@ class ExternalConsultation extends BaseModel
         return $this->hasOne(ExternalPlatform::class, 'id', 'external_platform_id')
             ->field('id,name,tel');
     }
-    
+
+    public function customerLog()
+    {
+        return $this->hasMany(ExternalConsultationFollowLog::class,'consultation_id','id')->order(['id'=>'desc']);
+    }
+    public function customerOrder()
+    {
+        return $this->hasMany(ExternalConsultationOrder::class,'consultation_id','id')->order(['id'=>'desc']);
+    }
 }

+ 10 - 0
app/common/model/external/ExternalConsultationFollowLog.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace app\common\model\external;
+
+use app\common\model\BaseModel;
+
+class ExternalConsultationFollowLog extends BaseModel
+{
+    protected $name = 'external_consultation_follow_log';
+}

+ 10 - 0
app/common/model/external/ExternalConsultationOrder.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace app\common\model\external;
+
+use app\common\model\BaseModel;
+
+class ExternalConsultationOrder extends BaseModel
+{
+    protected $name = 'external_consultation_order';
+}

+ 5 - 1
app/common/model/works/ServiceWork.php

@@ -20,6 +20,7 @@ use app\api\logic\PerformanceLogic;
 use app\common\model\BaseModel;
 use app\common\model\equity\EquityConfig;
 use app\common\model\equity\UserEquity;
+use app\common\model\external\ExternalPlatform;
 use app\common\model\goods_category\GoodsCategory;
 use app\common\model\master_commission\MasterWorkerCommissionConfig;
 use app\common\model\master_commission\MasterWorkerCommissionRatio;
@@ -262,5 +263,8 @@ class ServiceWork extends BaseModel
         $thirdTypedata = array_column(ConfigLogic::getDictByType('third_type')['third_type'],'name','value');
         return $thirdTypedata[$data['third_type']];
     }
-
+    public function getExternalPlatformTextAttr($value,$data)
+    {
+        return ExternalPlatform::where('id',$data['external_platform_id'])->value('name');
+    }
 }

+ 9 - 3
app/workerapi/controller/LoginController.php

@@ -14,6 +14,7 @@
 
 namespace app\workerapi\controller;
 
+use app\common\cache\MasterWokerTokenCache;
 use app\common\enum\notice\NoticeEnum;
 use app\common\model\master_worker\MasterWorker;
 use app\common\model\master_worker_register\MasterWorkerRegister;
@@ -22,6 +23,7 @@ use app\common\model\notice\NoticeSetting;
 use app\common\service\wechat\WeChatOaService;
 use app\workerapi\logic\DictLogic;
 use app\workerapi\logic\LoginLogic;
+use app\workerapi\logic\MasterWorkerLogic;
 use app\workerapi\logic\MasterWorkerRegisterLogic;
 use app\workerapi\validate\LoginAccountValidate;
 use app\workerapi\validate\RegisterValidate;
@@ -121,15 +123,19 @@ class LoginController extends BaseApiController
         }
         $worker_register = MasterWorkerRegister::where('mobile',$params['account'])->findOrEmpty();
         if($worker_register->isEmpty()) {
-            return $this->fail('请点击下方的工程师入驻',[],402);
+            return $this->fail($params['terminal'] == 5?'工程师不存在':'请点击下方的工程师入驻',[],402);
+        }
+        if(isset($params['terminal']) && $params['terminal'] == 5 && $worker_register->worker_id > 0){
+            if(MasterWorkerLogic::isReceivingOrders($worker_register->worker_id)){
+                return $this->fail('未达到接单条件');
+            }
         }
-
         $result = LoginLogic::login($params);
         if (false === $result) {
             return $this->fail(LoginLogic::getError());
         }
         //if(!empty($params['wx_code']) and $params['terminal']==1){
-        if(!empty($params['wx_code'])){
+        if(isset($params['wx_code']) && !empty($params['wx_code'])){
             $params['code'] = $params['wx_code'];
             $params['user_id'] = MasterWorker::where('sn',$result['sn'])->value('id');
             $wx_result = LoginLogic::mnpAuthLogin($params);

+ 43 - 0
app/workerapi/controller/WorksController.php

@@ -11,6 +11,8 @@ use app\common\model\works\ServiceWork;
 use app\workerapi\lists\HistoryWorkLists;
 use app\workerapi\lists\ServiceAssignWorkLists;
 use app\workerapi\lists\GoodsFeeStandardsLists;
+use app\workerapi\lists\ServiceWorkGrabOrderLists;
+use app\workerapi\lists\ServiceWorkGrabOrderLogLists;
 use app\workerapi\lists\ServiceWorkLists;
 use app\workerapi\lists\ServiceWorkSparePartLists;
 use app\workerapi\lists\SparePartLists;
@@ -23,6 +25,9 @@ use Exception;
  */
 class WorksController extends BaseApiController
 {
+
+
+    public array $notNeedLogin = ['grabOrder'];
     /**
      * 首页数量统计
      * @return \think\response\Json
@@ -385,4 +390,42 @@ class WorksController extends BaseApiController
         }
         return $this->success('成功', [], 1, 1);
     }
+
+    /**
+     * 工程师抢单池
+     * @return \think\response\Json
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/7 15:08
+     */
+    public function grabOrderList()
+    {
+        return $this->dataLists(new ServiceWorkGrabOrderLists());
+    }
+    /**
+     * 工程师抢单记录列表
+     * @return \think\response\Json
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/7 15:08
+     */
+    public function grabOrderLog()
+    {
+        return $this->dataLists(new ServiceWorkGrabOrderLogLists());
+    }
+    /**
+     * 工程师抢单
+     * @return \think\response\Json
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/7 15:08
+     */
+    public function grabOrder()
+    {
+        $params = (new ServiceWorkValidate())->post()->goCheck('cancel');
+        $result = ServiceWorkLogic::grabOrder(['id'=>$params['id'],'master_worker_id'=>$this->userId]);
+        if (false === $result) {
+            return $this->fail(ServiceWorkLogic::getError());
+        }
+        return $this->success('抢单成功', [], 1, 1);
+    }
+
+
 }

+ 13 - 3
app/workerapi/lists/MasterWorkerRegisterLists.php

@@ -34,7 +34,17 @@ class MasterWorkerRegisterLists extends BaseWorkerDataLists implements ListsSear
             '%like%' => ['name', 'mobile'],
         ];
     }
-
+    public function queryWhere()
+    {
+        $where = [];
+        if(isset($this->params['time_range']) && $this->params['time_range']){
+            $time_range = explode(',', $this->params['time_range']);
+            $startDateTime = strtotime($time_range[0]);
+            $endDateTime = strtotime($time_range[1])+86400-1;
+            $where[] = ['create_time','BETWEEN',[$startDateTime,$endDateTime]];
+        }
+        return $where;
+    }
 
     /**
      * @notes 获取列表
@@ -47,7 +57,7 @@ class MasterWorkerRegisterLists extends BaseWorkerDataLists implements ListsSear
      */
     public function lists(): array
     {
-        $list = MasterWorkerRegister::where($this->searchWhere)
+        $list = MasterWorkerRegister::where($this->searchWhere)->where($this->queryWhere())
             ->field(['*'])
             ->limit($this->limitOffset, $this->limitLength)
             ->order(['id' => 'desc'])
@@ -77,7 +87,7 @@ class MasterWorkerRegisterLists extends BaseWorkerDataLists implements ListsSear
      */
     public function count(): int
     {
-        return MasterWorkerRegister::where($this->searchWhere)->count();
+        return MasterWorkerRegister::where($this->searchWhere)->where($this->queryWhere())->count();
     }
 
 

+ 38 - 0
app/workerapi/lists/ServiceWorkGrabOrderLists.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace app\workerapi\lists;
+
+use app\common\model\works\ServiceWork;
+
+class ServiceWorkGrabOrderLists extends BaseWorkerDataLists
+{
+    /**
+     * 获取列表
+     * @return array
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/8 9:16
+     */
+    public function lists(): array
+    {
+        return ServiceWork::where('appointment_time','>',time())
+            ->where(['work_status'=>0,'service_status'=>0,'work_pay_status'=>1,'master_worker_id'=>0])
+            ->field(['id', 'work_sn', 'address', 'title', 'work_status', 'service_status','work_pay_status', 'appointment_time','receive_time','base_service_fee','service_fee'])
+            ->append(['work_status_text','service_status_text'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['appointment_time' => 'asc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * 获取数量
+     * @return int
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/8 9:16
+     */
+    public function count(): int
+    {
+        return ServiceWork::where('appointment_time','>',time())->where(['work_status'=>0,'service_status'=>0,'work_pay_status'=>1,'master_worker_id'=>0])->count();
+    }
+}

+ 50 - 0
app/workerapi/lists/ServiceWorkGrabOrderLogLists.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace app\workerapi\lists;
+
+use app\common\model\works\ServiceWorkAllocateWorkerLog;
+
+class ServiceWorkGrabOrderLogLists extends BaseWorkerDataLists
+{
+    /**
+     * 获取列表 - 15天内
+     * @return array
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/8 9:16
+     */
+    public function lists(): array
+    {
+        $list = ServiceWorkAllocateWorkerLog::alias("a")
+            ->join("service_work b","a.work_id = b.id AND a.master_worker_id = b.master_worker_id")
+            ->where('a.type',3)
+            ->where('a.create_time','>',(time()-15*86400))
+            ->where('a.master_worker_id',$this->userId)
+            ->field(['a.opera_log','b.id', 'b.work_sn', 'b.address', 'b.title', 'b.work_status', 'b.service_status','b.work_pay_status', 'b.appointment_time','b.receive_time','b.base_service_fee','b.service_fee'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['b.appointment_time' => 'asc'])
+            ->select()
+            ->toArray();
+        foreach ($list as &$item) {
+            $item['work_status_text'] = (new \app\common\model\works\ServiceWork)->getWorkStatusTextAttr('',$item);
+            $item['service_status_text'] = (new \app\common\model\works\ServiceWork)->getServiceStatusTextAttr('',$item);
+            $item['appointment_time'] = (new \app\common\model\works\ServiceWork)->getAppointmentTimeAttr('',$item);
+        }
+        return $list;
+    }
+
+
+    /**
+     * 获取数量
+     * @return int
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/8 9:16
+     */
+    public function count(): int
+    {
+        return ServiceWorkAllocateWorkerLog::alias("a")
+            ->join("service_work b","a.work_id = b.id AND a.master_worker_id = b.master_worker_id")
+            ->where('a.type',3)
+            ->where('a.create_time','>',(time()-15*86400))
+            ->where('a.master_worker_id',$this->userId)->count();
+    }
+}

+ 2 - 1
app/workerapi/logic/GoodsCategoryLogic.php

@@ -21,8 +21,9 @@ class GoodsCategoryLogic extends BaseLogic
     public static function getQRCode($params)
     {
         try {
+            //external_platform_id
             $response = (new WeChatMnpService())->getUnlimitedQRCode(
-                '&type=2&id='.$params['id'].'&worker='.$params['user_info']['worker_number'],
+                '&type=2&id='.$params['id'].'&worker='.$params['user_info']['worker_number'].'&service_work_id='.($params['service_work_id']??0),
                 "pages/good/good",
                 'release',//trial、release、develop
                 false

+ 1 - 1
app/workerapi/logic/LoginLogic.php

@@ -156,7 +156,7 @@ class LoginLogic extends BaseLogic
             $user->save();
 
             //设置token
-            $userInfo = MasterWokerTokenService::setToken($user->id, 1);
+            $userInfo = MasterWokerTokenService::setToken($user->id, $params['terminal']??1);
 
             //返回登录信息
             $avatar = $user->avatar ?: Config::get('project.default_image.user_avatar');

+ 56 - 0
app/workerapi/logic/MasterWorkerLogic.php

@@ -426,5 +426,61 @@ class MasterWorkerLogic extends  BaseLogic
         $name = str_replace($specialChars,"",$user);
         return (int)MasterWorkerRegister::where('name',$name)->where('mobile',$mobile)->value('id');
     }
+
+    /**
+     * 工程师是否能接单
+     * @param $userId
+     * @return bool
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/8 10:07
+     */
+    public static function isReceivingOrders($userId)
+    {
+        try {
+            $masterWorker = MasterWorker::where(['id'=>$userId])->findOrEmpty();
+            if($masterWorker['work_status'] != 0 || $masterWorker['is_disable'] != 0){
+                throw new Exception('该账号已禁用或已长期停单');
+            }
+            if(!self::taskRequired($userId,$masterWorker['identity_source'])){
+                throw new Exception('培训中心必须任务未完成');
+            }
+            $idCard = MasterWorkerInfo::where(['worker_id'=>$userId])->findOrEmpty();
+            if ($idCard->isEmpty()) {
+                throw new Exception('请先完善身份证信息');
+            }
+            if($idCard->audit_state == 0){
+                throw new Exception('身份证信息核验中,请等待核验完成');
+            }
+            if($idCard->audit_state == 2){
+                throw new Exception('身份证信息核验不通过,请重新填写');
+            }
+            $bank = BankAccount::where(['worker_id'=>$userId])->findOrEmpty();
+            if ($bank->isEmpty()) {
+                throw new Exception('请先完善银行卡信息');
+            }
+            if($bank->audit_state == 0){
+                throw new Exception('银行卡信息核验中,请等待核验完成');
+            }
+            if($bank->audit_state == 2){
+                throw new Exception('银行卡信息核验不通过,请重新填写');
+            }
+            $agree = MasterWorkerAgree::where(['worker_id'=>$userId])->findOrEmpty();
+            if ($agree->isEmpty()) {
+                throw new Exception('请先签写协议信息');
+            }
+            if($agree->audit_state == 0){
+                throw new Exception('协议信息核验中,请等待核验完成');
+            }
+            if($agree->audit_state == 2){
+                throw new Exception('协议信息核验不通过,请重新签写');
+            }
+            return true;
+        } catch (\Exception $e) {
+            Log::info($e->getMessage());
+            return false;
+        }
+    }
+
+
     
 }