1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace app\common\command;
- use app\common\service\CommonService;
- use app\common\service\DemandBiddingService;
- use app\common\service\EasyWeChatService;
- use app\common\service\SubscribeMessageService;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use app\common\service\DemandService;
- class BiddingDeal extends Command
- {
- protected function configure()
- {
- $this->setName('bidding:deal')->setDescription('bidding deal command!');
- }
- protected function execute(Input $input, Output $output)
- {
- $output->writeln("bidding:deal:");
- //超时确定接单处理
- $this->confirmDemandTimeoutDeal($input, $output);
- //开标处理
- $this->openBiddingDeal($input, $output);
- }
- /**
- * 开标处理
- * @param Input $input
- * @param Output $output
- * @return void
- */
- protected function openBiddingDeal(Input $input, Output $output)
- {
- $open_bidding_time = intval(config('site.general_open_bidding_time') ?? 300);
- $EasyWeChatService = new EasyWeChatService();
- DemandService::$Model::hasWhere('demandBiddings', ['bidding_status' => DemandBiddingService::STATUS_BIDDING_ONGOING])->with(['demandBiddings' => function ($query) {
- $query->order('createtime asc');
- }])->where(['status' => DemandService::STATUS_BIDDING])->chunk(100, function ($list) use ($open_bidding_time, $EasyWeChatService) {
- foreach ($list as $item) {
- $bidList = $item->demandBiddings;
- foreach ($bidList as $bid) {
- //排除掉不符合中标状态的
- if ($bid->bidding_status != CommonService::ONGOING) {
- continue;
- }
- //判断首个投标记录的开始时间距现在是否有配置的时间5分钟
- if (time() - $bid->createtime >= $open_bidding_time) {
- //根据匹配度及信誉分获取一个人选,并修改状态为已中标
- $bid->bidding_status = DemandBiddingService::STATUS_BIDDING_WIN;
- $bid->process_status = DemandBiddingService::STATUS_PROCESS_ONGOING;
- $res = $bid->save();
- //发送接单成功提醒消息
- $msgData = [
- 'values' => [
- $item->parent_order_no,
- mb_substr($item->desc, 0, 8),
- mb_substr($item->desc, 0, 11),
- SubscribeMessageService::MSG_MAP[SubscribeMessageService::MSG_TEMP_DEMAND_RECEIVE]['remark'],
- ]
- ];
- $EasyWeChatService->sendMsg($bid->user_id, SubscribeMessageService::MSG_TEMP_DEMAND_RECEIVE, $msgData);
- break;
- }
- }
- }
- }, 'Demands.id');
- }
- /**
- * 确认接单超时处理
- * @param Input $input
- * @param Output $output
- * @return void
- */
- protected function confirmDemandTimeoutDeal(Input $input, Output $output)
- {
- $demand_confirm_timeout = intval(config('site.demand_confirm_timeout_time') ?? 300);
- $where = [
- 'bidding_status' => DemandBiddingService::STATUS_BIDDING_WIN,
- 'process_status' => DemandBiddingService::STATUS_PROCESS_ONGOING,
- ];
- DemandBiddingService::where($where)->chunk(100, function ($biddingList) use ($demand_confirm_timeout) {
- foreach ($biddingList as $bidding) {
- //如果中标后5分钟未确认接单则弃权
- if (time() - $bidding->updatetime > $demand_confirm_timeout) {
- $bidding->bidding_status = DemandBiddingService::STATUS_BIDDING_NO;
- $bidding->process_status = DemandBiddingService::STATUS_PROCESS_TIMEOUT;
- $bidding->save();
- }
- }
- });
- }
- }
|