| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace app\common\command;
- use think\facade\Log;
- use think\console\Input;
- use think\console\Output;
- use think\console\Command;
- use app\common\model\master_worker\MasterWorker;
- use app\common\model\works\ServiceWorkAllocateWorkerLog;
- /*
- ** 工程师连续拒单统计
- */
- class RejectionStatistics extends Command
- {
- protected function configure()
- {
- $this->setName('rejection_statistics')
- ->setDescription('工程师连续拒单统计,不包含退款和未支付订单');
- }
- protected function execute(Input $input, Output $output)
- {
- $this->updateRejectionNum();
- }
- /**
- * 更新工程师连续拒单最大值
- */
- protected function updateRejectionNum()
- {
- MasterWorker::setRejectionNum(1, 5);//记录到缓存中
- die;
- $where = [
- ['a.type', '=', 0],
- ['a.create_time', '>=', strtotime('-1 year')], // 一年内的数据
- ['s.service_status', '<', 4], // 未退款和未支付的订单
- ['s.refund_approval', '=', 0], // 未退款的订单
- ];
- try {
- $list = MasterWorker::field('id')->where([
- 'work_status' => 0, //工作状态:正常
- 'audit_state' => 1, //审核状态:通过
- 'is_disable' => 0, //是否禁用:否
- ])
- ->select()
- ->toArray();
- foreach($list as $item) {
- $logs = ServiceWorkAllocateWorkerLog::alias('a')
- ->leftJoin('service_work s','s.id = a.work_id')
- ->where($where)
- ->where('a.master_worker_id', $item['id'])
- ->field('a.id,a.work_id,a.master_worker_id, s.master_worker_id as service_master_worker_id, s.service_status, s.refund_approval')
- ->order('a.id','asc')
- ->select()->toArray();
- if ($logs) {
- $num = 0; //连续拒单次数
- $num_list = []; //连续拒单次数list
- foreach($logs as $k => $v) {
- if ($v['master_worker_id'] != $v['service_master_worker_id']) {
- $num++;
- } else {
- if ($num > 0) {
- $num_list[] = $num;
- }
- $num = 0;//如果有接单的情况,则重新统计
- }
- }
- //取num_list的最大值
- $max_num = max($num_list);
- if ($max_num > 0) {
- //更新工程师连续拒单次数
- MasterWorker::where('id', $item['id'])->update([
- 'rejection_num' => $max_num, //连续拒单次数
- ]);
- }
- }
- die;
- }
- } catch (\Exception $e) {
- echo $e->getMessage();
- Log::error('更新工程师拒单数量失败:'.$e->getMessage());
- }
- }
-
- }
|