Prechádzať zdrojové kódy

Merge branch 'master' of e.coding.net:zdap/weixiu/weixiu_api into add_order-m

liugc 11 mesiacov pred
rodič
commit
bdb981a30c

+ 2 - 1
app/adminapi/controller/export/ExportController.php

@@ -113,6 +113,7 @@ class ExportController extends BaseAdminController
     {
     {
         $params = $this->request->get();
         $params = $this->request->get();
         if(empty($params['download_type'])) return $this->fail('参数错误');
         if(empty($params['download_type'])) return $this->fail('参数错误');
+        $params['admin_id'] = $this->adminId??0;
         $result = ExportLogic::add([
         $result = ExportLogic::add([
             'download_type' => $params['download_type']??0,
             'download_type' => $params['download_type']??0,
             'params' => $params,
             'params' => $params,
@@ -123,7 +124,7 @@ class ExportController extends BaseAdminController
             return $this->fail(ExportLogic::getError());
             return $this->fail(ExportLogic::getError());
         }
         }
         // 暂时 - 立即生成导出文件
         // 暂时 - 立即生成导出文件
-        (new ExcelExportService)->download($result);
+        if(!isset($params['cmd'])) (new ExcelExportService)->download($result);
         return $this->success('添加成功-'.$result, [], 1, 1);
         return $this->success('添加成功-'.$result, [], 1, 1);
     }
     }
 
 

+ 57 - 1
app/adminapi/lists/master_worker_register/MasterWorkerRegisterLists.php

@@ -16,6 +16,8 @@ namespace app\adminapi\lists\master_worker_register;
 
 
 
 
 use app\adminapi\lists\BaseAdminDataLists;
 use app\adminapi\lists\BaseAdminDataLists;
+use app\adminapi\logic\auth\AdminLogic;
+use app\adminapi\logic\ConfigLogic;
 use app\common\model\master_worker_register\MasterWorkerRegister;
 use app\common\model\master_worker_register\MasterWorkerRegister;
 use app\common\lists\ListsSearchInterface;
 use app\common\lists\ListsSearchInterface;
 
 
@@ -50,7 +52,11 @@ class MasterWorkerRegisterLists extends BaseAdminDataLists implements ListsSearc
      */
      */
     public function queryDataWhere(){
     public function queryDataWhere(){
         $where = [];
         $where = [];
-        $data_rules = $this->adminInfo['data_rules'];
+        if(isset($this->params['admin_id']) && $this->params['admin_id']){
+            $data_rules = AdminLogic::getDataPermissions($this->params['admin_id']);
+        }else{
+            $data_rules = $this->adminInfo['data_rules'];
+        }
         if (isset($data_rules['province']) && !empty($data_rules['province'])) {
         if (isset($data_rules['province']) && !empty($data_rules['province'])) {
             $where[] = ['province','in' ,$data_rules['province']];
             $where[] = ['province','in' ,$data_rules['province']];
         }
         }
@@ -99,4 +105,54 @@ class MasterWorkerRegisterLists extends BaseAdminDataLists implements ListsSearc
         return MasterWorkerRegister::where($this->searchWhere)->where($this->queryWhere())->where($this->queryDataWhere())->count();
         return MasterWorkerRegister::where($this->searchWhere)->where($this->queryWhere())->where($this->queryDataWhere())->count();
     }
     }
 
 
+    public function setExcelComplexFields(): array
+    {
+        $zh_cn_fields = [
+            '工作经验','是否有证件', '特种证名称','证件照片','地区',
+            '销售名称','销售手机号'
+        ];
+        $data_fields = [
+            function($row){
+                $dictType = array_column(\app\adminapi\logic\ConfigLogic::getDictByType('worker_exp_type')['worker_exp_type'],'name','value');
+                return $dictType[$row['maintain_exp_type']]??'';
+            },function($row){ return $row['is_credential']? '有特种证' : '无特种证'; },function($row){ return $row['credential_name']? implode('、',$row['credential_name']) : ''; }
+            ,function($row){
+                if(empty($row['credential_images'])) return '';
+                $images = '';
+                if(is_array($row['credential_images'])){
+                    $images = implode("\r\n",$row['credential_images']);
+                }
+                return $images;
+            },'area_name',
+            function($row){ return empty($row['sale'])? '' :$row['sale']['sale_name']??''; },
+            function($row){ return empty($row['sale'])? '' :$row['sale']['mobile']??''; }
+        ];
+        /*$data_fields = [
+            function($row){
+                $dictType = array_column(\app\adminapi\logic\ConfigLogic::getDictByType('worker_exp_type')['worker_exp_type'],'name','value');
+                return $dictType[$row['maintain_exp_type']]??'';
+            },function($row){ return $row['is_credential']? '有特种证' : '无特种证'; },'credential_name'
+            ,function($row){
+                    if(empty($row['credential_images'])) return '';
+                    $images = '';
+                    if(is_array($row['credential_images'])){
+                        $images = implode(',',$row['credential_images']);
+                    }
+                    return $images;
+            },'area_name',function($row){
+                $dictType = array_column(\app\adminapi\logic\ConfigLogic::getDictByType('worker_vehicle_type')['worker_vehicle_type'],'name','value');
+                return $dictType[$row['vehicle_type']]??'';
+            },
+            function($row){ return $row['sale']['sale_name']??''; },
+            function($row){ return $row['sale']['mobile']??''; },
+            'name','age','mobile','address','create_time',function($row){
+                $dictType = array_column(\app\adminapi\logic\ConfigLogic::getDictByType('audit_state')['audit_state'],'name','value');
+                return $dictType[$row['status']]??'';
+            },'update_time'
+        ];*/
+        return [
+            'zh_cn_fields' => $zh_cn_fields,
+            'data_fields' => $data_fields
+        ];
+    }
 }
 }

+ 3 - 3
app/adminapi/lists/sale/SaleCommissionLists.php

@@ -128,7 +128,7 @@ class SaleCommissionLists extends BaseAdminDataLists implements ListsSearchInter
             $item['group_counts'] = $group_counts[$item['id']]??0;
             $item['group_counts'] = $group_counts[$item['id']]??0;
             $item['group_merits'] = $this->groupMerits($group_counts[$item['id']]??0);
             $item['group_merits'] = $this->groupMerits($group_counts[$item['id']]??0);
 
 
-            $item['all_merits'] = $item['passes_merits'] + $item['property_merits'] + $item['group_merits'];
+            $item['all_merits'] = (float)$item['passes_merits'] + (float)$item['property_merits'] + (float)$item['group_merits'];
         }
         }
         return $list;
         return $list;
     }
     }
@@ -153,7 +153,7 @@ class SaleCommissionLists extends BaseAdminDataLists implements ListsSearchInter
         ];
         ];
         $data_fields = [function($row){ return $row['saleGroupInfo']['sale_name']??''; },'sale_name','mobile',
         $data_fields = [function($row){ return $row['saleGroupInfo']['sale_name']??''; },'sale_name','mobile',
             'passes_counts','passes_merits','property_counts','property_merits','group_counts','group_merits','all_merits'
             'passes_counts','passes_merits','property_counts','property_merits','group_counts','group_merits','all_merits'
-            ,'start_date','end_date'
+            ,function($row){ return $row['start_date']?date('Y-m-d',$row['start_date']):''; },function($row){ return $row['end_date']?date('Y-m-d',$row['end_date']):''; }
         ];
         ];
         return [
         return [
             'zh_cn_fields' => $zh_cn_fields,
             'zh_cn_fields' => $zh_cn_fields,
@@ -252,7 +252,7 @@ class SaleCommissionLists extends BaseAdminDataLists implements ListsSearchInter
 
 
     public function groupMerits($value)
     public function groupMerits($value)
     {
     {
-        return $value;
+        return bcmul($value, 0.05,2);
     }
     }
 
 
 
 

+ 1 - 1
app/adminapi/lists/sale/SaleMasterWorkerLists.php

@@ -156,7 +156,7 @@ class SaleMasterWorkerLists extends BaseAdminDataLists implements ListsSearchInt
         $data_fields = [
         $data_fields = [
             function($row){ return $row['sale']['sale_name']??''; },
             function($row){ return $row['sale']['sale_name']??''; },
             function($row){ return $row['sale']['saleGroupInfo']['sale_name']??''; },
             function($row){ return $row['sale']['saleGroupInfo']['sale_name']??''; },
-            'register_count','settled_count','start_date','end_date'
+            'register_count','settled_count',function($row){ return $row['start_date']?date('Y-m-d',$row['start_date']):''; },function($row){ return $row['end_date']?date('Y-m-d',$row['end_date']):''; }
         ];
         ];
         return [
         return [
             'zh_cn_fields' => $zh_cn_fields,
             'zh_cn_fields' => $zh_cn_fields,

+ 0 - 1
app/adminapi/logic/works/ServiceWorkLogic.php

@@ -974,7 +974,6 @@ class ServiceWorkLogic extends BaseLogic
             $work->dispatch_time = 0;
             $work->dispatch_time = 0;
             $work->first_contact_time = 0;
             $work->first_contact_time = 0;
             $work->estimated_finish_time = 0;
             $work->estimated_finish_time = 0;
-            $work->exec_time = 0;
             $work->save();
             $work->save();
 
 
             $work_log = [
             $work_log = [

+ 52 - 16
app/common/command/AutomaticDispatch.php

@@ -10,6 +10,7 @@ use app\adminapi\service\WeCallService;
 use app\common\model\works\ServiceWork;
 use app\common\model\works\ServiceWork;
 use app\common\model\goods_time\GoodsTime;
 use app\common\model\goods_time\GoodsTime;
 use app\common\model\master_worker\MasterWorker;
 use app\common\model\master_worker\MasterWorker;
+use app\common\model\works\ServiceWorkAnomalous;
 use app\common\model\master_worker\MasterWorkerTeam;
 use app\common\model\master_worker\MasterWorkerTeam;
 use app\common\model\works\ServiceWorkAllocateWorkerLog;
 use app\common\model\works\ServiceWorkAllocateWorkerLog;
 use app\workerapi\logic\ServiceWorkerAllocateWorkerLogic;
 use app\workerapi\logic\ServiceWorkerAllocateWorkerLogic;
@@ -53,6 +54,46 @@ class AutomaticDispatch extends Command
         if ($h >= 8 && $h <= 22) {
         if ($h >= 8 && $h <= 22) {
             $this->startTask();
             $this->startTask();
         }
         }
+
+        //异常工单:上门时间超过两小时状态未变更已上门
+        $this->workAnomalous();
+    }
+
+    /**
+     * 异常工单:上门时间超过两小时状态未变更已上门
+     */
+    protected function workAnomalous() 
+    {
+        $size = 100;
+        $startTime = time() - 7200;  // 当前时间减去7200秒(2小时)
+        $list = ServiceWork::alias("a")
+            ->leftJoin('service_work_anomalous b','a.id = b.work_id')
+            ->where('a.work_status',3)
+            ->where('a.service_status','<',2)
+            ->where('a.refund_approval',0)
+            ->where('a.work_pay_status',1)
+            ->where('a.appointment_time','<=', $startTime)
+            ->whereNull('b.id')
+            ->field('a.id,a.appointment_time,b.id as anomalous_id')
+            ->order('a.create_time','asc')
+            ->limit($size)
+            ->select()
+            ->toArray();
+        if (!$list) {
+            return ;
+        }
+
+        foreach($list as $item) {     
+            try {
+                ServiceWorkAnomalous::create([
+                    'work_id' => $item['id'],
+                    'reason_type' => 3,
+                    'reason' => '上门时间超过两小时状态未变更已上门',
+                ]);
+            } catch (\Exception $e) {
+                Log::write('异常工单:'.$e->getMessage());
+            }
+        }
     }
     }
 
 
     /*
     /*
@@ -67,15 +108,11 @@ class AutomaticDispatch extends Command
         $startTime = strtotime(date('Y-m-d 00:00:00'));
         $startTime = strtotime(date('Y-m-d 00:00:00'));
         $endTime = strtotime(date('Y-m-d 23:59:59'));
         $endTime = strtotime(date('Y-m-d 23:59:59'));
        
        
-        // 获取当前时间的前五分钟时间戳
-        $fiveMinutesAgo = time() - 120; // 300 秒 = 2 分钟
         $list = ServiceWork::where('work_status',0)
         $list = ServiceWork::where('work_status',0)
             ->where('service_status',0)
             ->where('service_status',0)
             ->where('refund_approval',0)
             ->where('refund_approval',0)
             ->where('work_pay_status',1)
             ->where('work_pay_status',1)
-            ->where(function ($query) use ($fiveMinutesAgo) {
-                $query->where('exec_time', 0)->whereOr('exec_time', '<', $fiveMinutesAgo);
-            })
+            ->where('exec_num','<', 2)
             ->where('appointment_time','between', [$startTime, $endTime])
             ->where('appointment_time','between', [$startTime, $endTime])
             ->field('id,category_type,goods_category_id,service_area_id,lon,lat,province,city,title,appointment_time,address,mobile,work_sn')
             ->field('id,category_type,goods_category_id,service_area_id,lon,lat,province,city,title,appointment_time,address,mobile,work_sn')
             ->order('create_time','asc')
             ->order('create_time','asc')
@@ -86,8 +123,6 @@ class AutomaticDispatch extends Command
             return ;
             return ;
         }
         }
 
 
-        $isExec = 1;//是否派单成功
- 
         foreach($list as $item) {     
         foreach($list as $item) {     
             try {
             try {
                 //优先平台工程师派单
                 //优先平台工程师派单
@@ -96,20 +131,21 @@ class AutomaticDispatch extends Command
                     //门店负责人派单
                     //门店负责人派单
                     $res = $this->teamWorker($item);
                     $res = $this->teamWorker($item);
                     if ($res === false) {
                     if ($res === false) {
-                        $isExec = 0;
+                        ServiceWork::where('id',$item['id'])
+                            ->update([
+                                'exec_num' => 2,
+                            ]);
+                        ServiceWorkAnomalous::create([
+                            'work_id' => $item['id'],
+                            'reason_type' => 2,
+                            'reason' => '自动派单:找不到工程师',
+                        ]);
                     }
                     }
                 }
                 }
 
 
             } catch (\Exception $e) {
             } catch (\Exception $e) {
-                print_r($e->getMessage());
                 Log::write('自动派单异常:'.$e->getMessage());
                 Log::write('自动派单异常:'.$e->getMessage());
             }
             }
-
-            if ($isExec == 0) {
-                ServiceWork::where('id',$item['id'])->update([
-                    'exec_time' => time(),
-                ]);
-            }
         }
         }
     }
     }
 
 
@@ -353,7 +389,7 @@ class AutomaticDispatch extends Command
                 'work_status'=>1,
                 'work_status'=>1,
                 'estimated_finish_time' => $estimated_finish_time,
                 'estimated_finish_time' => $estimated_finish_time,
                 'dispatch_time'=>time(),
                 'dispatch_time'=>time(),
-                'exec_time' => time(),
+                'exec_num' => Db::raw('exec_num + 1'),
             ]);
             ]);
             MasterWorker::setWorktotal('inc',$masterWorkerId);
             MasterWorker::setWorktotal('inc',$masterWorkerId);
             $work_log = [
             $work_log = [

+ 11 - 3
app/common/command/CancelDispatch.php

@@ -7,6 +7,7 @@ use think\console\Output;
 use think\console\Command;
 use think\console\Command;
 use app\common\model\works\ServiceWork;
 use app\common\model\works\ServiceWork;
 use app\common\model\master_worker\MasterWorkerTeam;
 use app\common\model\master_worker\MasterWorkerTeam;
+use app\common\model\works\ServiceWorkAnomalous;
 
 
 class CancelDispatch extends Command
 class CancelDispatch extends Command
 {
 {
@@ -30,7 +31,7 @@ class CancelDispatch extends Command
         $list = ServiceWork::where('work_status',1)
         $list = ServiceWork::where('work_status',1)
                 ->where('dispatch_time','<',strtotime('-10 minutes'))
                 ->where('dispatch_time','<',strtotime('-10 minutes'))
                 ->where('dispatch_time','>=',strtotime('-1 days'))
                 ->where('dispatch_time','>=',strtotime('-1 days'))
-                ->field('id,tenant_id,master_worker_id,appointment_time')
+                ->field('id,tenant_id,master_worker_id,appointment_time,exec_num')
                 ->limit(100)
                 ->limit(100)
                 ->select()
                 ->select()
                 ->toArray();
                 ->toArray();
@@ -43,12 +44,19 @@ class CancelDispatch extends Command
                             'dispatch_time' => 0,
                             'dispatch_time' => 0,
                             'first_contact_time' => 0,
                             'first_contact_time' => 0,
                             'estimated_finish_time' => 0,
                             'estimated_finish_time' => 0,
-                            'exec_time' => 0,
                         ]);
                         ]);
             if ($item['tenant_id'] > 0) {
             if ($item['tenant_id'] > 0) {
                 $updateData = date("H",strtotime($item['appointment_time'])) < 12 ? ['am_order' => Db::raw('am_order - 1')] : ['pm_order' => Db::raw('pm_order - 1')];
                 $updateData = date("H",strtotime($item['appointment_time'])) < 12 ? ['am_order' => Db::raw('am_order - 1')] : ['pm_order' => Db::raw('pm_order - 1')];
                 MasterWorkerTeam::where('master_worker_id',$item['master_worker_id'])->where('tenant_id',$item['tenant_id'])->update($updateData);
                 MasterWorkerTeam::where('master_worker_id',$item['master_worker_id'])->where('tenant_id',$item['tenant_id'])->update($updateData);
-                
+            }
+
+            //自动派单2次后,标记工单异常
+            if ($item['exec_num'] >= 2) {
+                ServiceWorkAnomalous::create([
+                    'work_id' => $item['id'],
+                    'reason_type' => 2,
+                    'reason' => '自动派单:2次无人接单',
+                ]);
             }
             }
         }
         }
         
         

+ 42 - 0
app/common/command/ExcelExport.php

@@ -0,0 +1,42 @@
+<?php
+namespace app\common\command;
+
+use app\common\model\bank_account\BankAccount;
+use app\common\model\export\Export;
+use app\common\model\master_worker\MasterWorker;
+use app\common\model\master_worker\MasterWorkerInfo;
+use app\common\service\ExcelExportService;
+use think\console\Command;
+use think\console\Input;
+use think\console\Output;
+use think\facade\Log;
+
+/**
+ *  表格导出
+ * Class OpenObtainOrder
+ * @package app\command
+ */
+class ExcelExport extends Command
+{
+    protected function configure()
+    {
+        $this->setName('excel_export')->setDescription('表格导出');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        set_time_limit(180);
+        ini_set('memory_limit', '1024M');
+        try {
+            Export::where('generate_status',0)->where('createtime','<',(time()-86400*2))->delete();
+            $result = Export::where('generate_status',0)->findOrEmpty();
+            if(!$result->isEmpty()){
+                (new ExcelExportService)->download($result->id,true);
+            }
+            return true;
+        } catch (\Exception $e) {
+            Log::write('ExcelExport:'.$e->getMessage());
+            return $e->getMessage();
+        }
+    }
+}

+ 6 - 2
app/common/service/ExcelExportService.php

@@ -46,7 +46,7 @@ class ExcelExportService
         $this->download_type = config('export.download_type');
         $this->download_type = config('export.download_type');
         $this->sheet = new ExcelWriter();
         $this->sheet = new ExcelWriter();
     }
     }
-    public function download($id)
+    public function download($id,$isCmd = false)
     {
     {
         try{
         try{
             $infoExport = Export::findOrEmpty($id);
             $infoExport = Export::findOrEmpty($id);
@@ -64,12 +64,16 @@ class ExcelExportService
                         break;
                         break;
                     default:
                     default:
                         $use_file = explode('.',$download_fun);
                         $use_file = explode('.',$download_fun);
-                        $this->getDownloadFileUrl(invoke(str_replace('.', '\\', App::getNamespace() . '\\lists\\' . $use_file[0] . '\\'. ucwords($use_file[1]))));
+                        $this->sheet->savePath = ($isCmd?'./public/exports/':'');
+                        $this->getDownloadFileUrl(invoke(str_replace('.', '\\', App::getNamespace() . ($isCmd?'\\adminapi':'') . '\\lists\\' . $use_file[0] . '\\'. ucwords($use_file[1]))));
                        break;
                        break;
                 }
                 }
             }
             }
         }catch (\Exception $e){
         }catch (\Exception $e){
             Log::info("download-error:{$id}:".$e->getMessage());
             Log::info("download-error:{$id}:".$e->getMessage());
+            $this->infoExport->generate_status = 2;
+            $this->infoExport->updatetime = time();
+            $this->infoExport->save();
             throw new Exception($e->getMessage());
             throw new Exception($e->getMessage());
         }
         }
     }
     }

+ 2 - 0
config/console.php

@@ -23,5 +23,7 @@ return [
         'update_worker_score' => 'app\common\command\UpdateWorkerScore',
         'update_worker_score' => 'app\common\command\UpdateWorkerScore',
         //拼团订单结束
         //拼团订单结束
         'group_order' => 'app\common\command\GroupOrder',
         'group_order' => 'app\common\command\GroupOrder',
+        // 导出表格
+        'excel_export' => 'app\common\command\ExcelExport',
     ],
     ],
 ];
 ];

+ 1 - 0
config/export.php

@@ -21,5 +21,6 @@ return [
         '11' =>  'group_activity.GroupUserOrderLists',
         '11' =>  'group_activity.GroupUserOrderLists',
         '12' =>  'sale.SaleMasterWorkerLists',
         '12' =>  'sale.SaleMasterWorkerLists',
         '13' =>  'sale.SaleCommissionLists',
         '13' =>  'sale.SaleCommissionLists',
+        '14' =>  'master_worker_register.MasterWorkerRegisterLists',
     ],
     ],
 ];
 ];

+ 1 - 1
extend/excel/ExcelWriter.php

@@ -42,7 +42,7 @@ class ExcelWriter
         $filePath = $savePath . $filename;
         $filePath = $savePath . $filename;
         $writer = new Xlsx($this->spreadsheet);
         $writer = new Xlsx($this->spreadsheet);
         $writer->save($filePath);
         $writer->save($filePath);
-        $this->fileUrl = ($this->savePath?:"/exports/"). $filename;
+        $this->fileUrl = "/exports/". $filename;
     }
     }
     public function fileUrl()
     public function fileUrl()
     {
     {