BiddingDeal.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. if ($item->id != 30) {
  40. continue;
  41. }
  42. $bidList = $item->demandBiddings;
  43. foreach ($bidList as $bid) {
  44. //排除掉不符合中标状态的
  45. if ($bid->bidding_status != CommonService::ONGOING) {
  46. continue;
  47. }
  48. //判断首个投标记录的开始时间距现在是否有配置的时间5分钟
  49. if (time() - $bid->createtime >= $open_bidding_time) {
  50. //根据匹配度及信誉分获取一个人选,并修改状态为已中标
  51. $bid->bidding_status = DemandBiddingService::STATUS_BIDDING_WIN;
  52. $bid->process_status = DemandBiddingService::STATUS_PROCESS_ONGOING;
  53. $res = $bid->save();
  54. //发送接单成功提醒消息
  55. $msgData = [
  56. 'values' => [
  57. $item->parent_order_no,
  58. mb_substr($item->desc, 0, 8),
  59. mb_substr($item->desc, 0, 11),
  60. SubscribeMessageService::MSG_MAP[SubscribeMessageService::MSG_TEMP_DEMAND_RECEIVE]['remark'],
  61. ]
  62. ];
  63. $EasyWeChatService->sendMsg($bid->user_id, SubscribeMessageService::MSG_TEMP_DEMAND_RECEIVE, $msgData);
  64. break;
  65. }
  66. }
  67. }
  68. }, 'Demands.id');
  69. }
  70. /**
  71. * 确认接单超时处理
  72. * @param Input $input
  73. * @param Output $output
  74. * @return void
  75. */
  76. protected function confirmDemandTimeoutDeal(Input $input, Output $output)
  77. {
  78. $demand_confirm_timeout = intval(config('site.demand_confirm_timeout_time') ?? 300);
  79. $where = [
  80. 'bidding_status' => DemandBiddingService::STATUS_BIDDING_WIN,
  81. 'process_status' => DemandBiddingService::STATUS_PROCESS_ONGOING,
  82. ];
  83. DemandBiddingService::where($where)->chunk(100, function ($biddingList) use ($demand_confirm_timeout) {
  84. foreach ($biddingList as $bidding) {
  85. //如果中标后5分钟未确认接单则弃权
  86. if (time() - $bidding->updatetime > $demand_confirm_timeout) {
  87. $bidding->bidding_status = DemandBiddingService::STATUS_BIDDING_NO;
  88. $bidding->process_status = DemandBiddingService::STATUS_PROCESS_TIMEOUT;
  89. $bidding->save();
  90. }
  91. }
  92. });
  93. }
  94. }