1
0

RejectionStatistics.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\common\command;
  3. use think\facade\Log;
  4. use think\console\Input;
  5. use think\console\Output;
  6. use think\console\Command;
  7. use app\common\model\master_worker\MasterWorker;
  8. use app\common\model\works\ServiceWorkAllocateWorkerLog;
  9. /*
  10. ** 工程师连续拒单统计
  11. */
  12. class RejectionStatistics extends Command
  13. {
  14. protected function configure()
  15. {
  16. $this->setName('rejection_statistics')
  17. ->setDescription('工程师连续拒单统计,不包含退款和未支付订单');
  18. }
  19. protected function execute(Input $input, Output $output)
  20. {
  21. $this->updateRejectionNum();
  22. }
  23. /**
  24. * 更新工程师连续拒单最大值
  25. */
  26. protected function updateRejectionNum()
  27. {
  28. MasterWorker::setRejectionNum(1, 5);//记录到缓存中
  29. die;
  30. $where = [
  31. ['a.type', '=', 0],
  32. ['a.create_time', '>=', strtotime('-1 year')], // 一年内的数据
  33. ['s.service_status', '<', 4], // 未退款和未支付的订单
  34. ['s.refund_approval', '=', 0], // 未退款的订单
  35. ];
  36. try {
  37. $list = MasterWorker::field('id')->where([
  38. 'work_status' => 0, //工作状态:正常
  39. 'audit_state' => 1, //审核状态:通过
  40. 'is_disable' => 0, //是否禁用:否
  41. ])
  42. ->select()
  43. ->toArray();
  44. foreach($list as $item) {
  45. $logs = ServiceWorkAllocateWorkerLog::alias('a')
  46. ->leftJoin('service_work s','s.id = a.work_id')
  47. ->where($where)
  48. ->where('a.master_worker_id', $item['id'])
  49. ->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')
  50. ->order('a.id','asc')
  51. ->select()->toArray();
  52. if ($logs) {
  53. $num = 0; //连续拒单次数
  54. $num_list = []; //连续拒单次数list
  55. foreach($logs as $k => $v) {
  56. if ($v['master_worker_id'] != $v['service_master_worker_id']) {
  57. $num++;
  58. } else {
  59. if ($num > 0) {
  60. $num_list[] = $num;
  61. }
  62. $num = 0;//如果有接单的情况,则重新统计
  63. }
  64. }
  65. //取num_list的最大值
  66. $max_num = max($num_list);
  67. if ($max_num > 0) {
  68. //更新工程师连续拒单次数
  69. MasterWorker::where('id', $item['id'])->update([
  70. 'rejection_num' => $max_num, //连续拒单次数
  71. ]);
  72. }
  73. }
  74. die;
  75. }
  76. } catch (\Exception $e) {
  77. echo $e->getMessage();
  78. Log::error('更新工程师拒单数量失败:'.$e->getMessage());
  79. }
  80. }
  81. }