BiddingDeal.php 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace app\common\command;
  3. use app\common\service\CommonService;
  4. use app\common\service\DemandBiddingService;
  5. use app\common\service\EasyWeChatService;
  6. use app\common\service\SubscribeMessageService;
  7. use think\console\Command;
  8. use think\console\Input;
  9. use think\console\Output;
  10. use app\common\service\DemandService;
  11. class BiddingDeal extends Command
  12. {
  13. protected function configure()
  14. {
  15. $this->setName('bidding:deal')->setDescription('bidding deal command!');
  16. }
  17. protected function execute(Input $input, Output $output)
  18. {
  19. $output->writeln("bidding:deal:");
  20. //超时确定接单处理
  21. $this->confirmDemandTimeoutDeal($input, $output);
  22. //开标处理
  23. $this->openBiddingDeal($input, $output);
  24. }
  25. /**
  26. * 开标处理
  27. * @param Input $input
  28. * @param Output $output
  29. * @return void
  30. */
  31. protected function openBiddingDeal(Input $input, Output $output)
  32. {
  33. $open_bidding_time = intval(config('site.general_open_bidding_time') ?? 300);
  34. $EasyWeChatService = new EasyWeChatService();
  35. DemandService::$Model::hasWhere('demandBiddings', ['bidding_status' => DemandBiddingService::STATUS_BIDDING_ONGOING])->with(['demandBiddings' => function ($query) {
  36. $query->order('createtime asc');
  37. }])->where(['status' => DemandService::STATUS_BIDDING])->chunk(100, function ($list) use ($open_bidding_time, $EasyWeChatService) {
  38. foreach ($list as $item) {
  39. $bidList = $item->demandBiddings;
  40. foreach ($bidList as $bid) {
  41. //排除掉不符合中标状态的
  42. if ($bid->bidding_status != CommonService::ONGOING) {
  43. continue;
  44. }
  45. //判断首个投标记录的开始时间距现在是否有配置的时间5分钟
  46. if (time() - $bid->createtime >= $open_bidding_time) {
  47. //根据匹配度及信誉分获取一个人选,并修改状态为已中标
  48. $bid->bidding_status = DemandBiddingService::STATUS_BIDDING_WIN;
  49. $bid->process_status = DemandBiddingService::STATUS_PROCESS_ONGOING;
  50. $res = $bid->save();
  51. //发送接单成功提醒消息
  52. $msgData = [
  53. 'values' => [
  54. $item->parent_order_no,
  55. mb_substr($item->desc, 0, 8),
  56. mb_substr($item->desc, 0, 11),
  57. SubscribeMessageService::MSG_MAP[SubscribeMessageService::MSG_TEMP_DEMAND_RECEIVE]['remark'],
  58. ]
  59. ];
  60. $EasyWeChatService->sendMsg($bid->user_id, SubscribeMessageService::MSG_TEMP_DEMAND_RECEIVE, $msgData);
  61. break;
  62. }
  63. }
  64. }
  65. }, 'Demands.id');
  66. }
  67. /**
  68. * 确认接单超时处理
  69. * @param Input $input
  70. * @param Output $output
  71. * @return void
  72. */
  73. protected function confirmDemandTimeoutDeal(Input $input, Output $output)
  74. {
  75. $demand_confirm_timeout = intval(config('site.demand_confirm_timeout_time') ?? 300);
  76. $where = [
  77. 'bidding_status' => DemandBiddingService::STATUS_BIDDING_WIN,
  78. 'process_status' => DemandBiddingService::STATUS_PROCESS_ONGOING,
  79. ];
  80. DemandBiddingService::where($where)->chunk(100, function ($biddingList) use ($demand_confirm_timeout) {
  81. foreach ($biddingList as $bidding) {
  82. //如果中标后5分钟未确认接单则弃权
  83. if (time() - $bidding->updatetime > $demand_confirm_timeout) {
  84. $bidding->bidding_status = DemandBiddingService::STATUS_BIDDING_NO;
  85. $bidding->process_status = DemandBiddingService::STATUS_PROCESS_TIMEOUT;
  86. $bidding->save();
  87. }
  88. }
  89. });
  90. }
  91. }