1
0

RejectionStatistics.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. $where = [
  29. ['a.type', '=', 0],
  30. ['a.create_time', '>=', strtotime('-1 year')], // 一年内的数据
  31. ['s.service_status', '<', 4], // 未退款和未支付的订单
  32. ['s.refund_approval', '=', 0], // 未退款的订单
  33. ];
  34. try {
  35. $list = MasterWorker::field('id')->where([
  36. 'work_status' => 0, //工作状态:正常
  37. 'audit_state' => 1, //审核状态:通过
  38. 'is_disable' => 0, //是否禁用:否
  39. ])
  40. ->select()
  41. ->toArray();
  42. foreach($list as $item) {
  43. $logs = ServiceWorkAllocateWorkerLog::alias('a')
  44. ->leftJoin('service_work s','s.id = a.work_id')
  45. ->where($where)
  46. ->where('a.master_worker_id', $item['id'])
  47. ->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')
  48. ->order('a.id','asc')
  49. ->select()->toArray();
  50. if ($logs) {
  51. $num = 0; //连续拒单次数
  52. $num_list = []; //连续拒单次数list
  53. foreach($logs as $k => $v) {
  54. if ($v['master_worker_id'] != $v['service_master_worker_id']) {
  55. $num++;
  56. } else {
  57. if ($num > 0) {
  58. $num_list[] = $num;
  59. }
  60. $num = 0;//如果有接单的情况,则重新统计
  61. }
  62. }
  63. //取num_list的最大值
  64. $max_num = max($num_list);
  65. if ($max_num > 0) {
  66. //更新工程师连续拒单次数
  67. MasterWorker::where('id', $item['id'])->update([
  68. 'rejection_num' => $max_num, //连续拒单次数
  69. ]);
  70. }
  71. }
  72. }
  73. } catch (\Exception $e) {
  74. echo $e->getMessage();
  75. Log::error('更新工程师拒单数量失败:'.$e->getMessage());
  76. }
  77. }
  78. }