where(['is_delete' => 0, 'type' => Admin::ADMIN_TYPE_FRONT_AGENT]) ->select('id, name')->asArray()->all(); foreach($admin_list as $admin_item) { try { $driver_reset_time = Option::get('driver_reset_time_' . $admin_item['id'], 0, 'agent_front', '00:00')['value']; $driver_reset_start_time = strtotime(date('Y-m-d ' . $driver_reset_time . ':00')); $driver_reset_end_time = $driver_reset_start_time + 120; if ($driver_reset_start_time < time() && $driver_reset_end_time > time()) { $driverArray = Driver::find()->where(['is_delete' => 0, 'admin_id' => $admin_item['id']])->asArray()->all(); $driver_array_id = array_column($driverArray, 'id'); foreach ($driver_array_id as $driver_id) { $md_id = DriverMdBind::find()->where(['driver_id' => $driver_id, 'is_delete' => 0]) ->select('md_id')->column(); //查询出当前仓库门店下的团货商品订单 $goodsExt = AgentFrontCentralizeGoodsExt::find()->alias('ge') ->leftJoin(['g' => AgentFrontCentralizeGoods::tableName()], 'ge.centralize_goods_id = g.id') ->where([ 'ge.md_id' => $md_id, 'ge.is_delete' => 0, 'ge.status' => AgentFrontCentralizeGoodsExt::STATUS_WAIT_SORTING, 'g.centralize_goods_type' => 1 ])->andWhere(['<=', 'sort_time', $driver_reset_start_time])->groupBy('ge.md_id') ->select('ge.md_id, GROUP_CONCAT(ge.centralize_goods_id) as centralize_goods_id')->asArray()->all(); foreach ($goodsExt as $goodsExtIndex => $goodsExtItem) { //将团货的商品进行排序 debug_log(['MaxSortKey' => ($goodsExtMaxSortKey + $goodsExtIndex + 1)], '20250507.log'); //查询今天已经分拣过的 $agentFrontCentralizeGoodsExtSub = AgentFrontCentralizeGoodsExt::find()->where([ 'AND', [ 'md_id' => $goodsExtItem['md_id'], 'is_delete' => 0 ],[ '>', 'sort_time', $driver_reset_start_time ] ])->asArray()->one(); //如果存在分拣过的 就给直接赋值 if ($agentFrontCentralizeGoodsExtSub) { $sort_key = $agentFrontCentralizeGoodsExtSub['sort_key']; } else { $goodsExtMaxSortKey = AgentFrontCentralizeGoodsExt::find()->where([ 'md_id' => $md_id, 'is_delete' => 0, ])->andWhere(['>', 'sort_time', $driver_reset_start_time]) ->groupBy('md_id') ->max('sort_key') ?: 0; $sort_key = $goodsExtMaxSortKey + 1; } $goods_ext_edit_info = AgentFrontCentralizeGoodsExt::find()->alias('ge') ->leftJoin(['g' => AgentFrontCentralizeGoods::tableName()], 'ge.centralize_goods_id = g.id') ->where([ 'ge.md_id' => $goodsExtItem['md_id'], 'ge.is_delete' => 0, 'ge.status' => AgentFrontCentralizeGoodsExt::STATUS_WAIT_SORTING, 'g.centralize_goods_type' => 1 ])->andWhere(['<=', 'sort_time', $driver_reset_start_time])->select('ge.id')->asArray()->all(); foreach ($goods_ext_edit_info as $item) { $item_info = AgentFrontCentralizeGoodsExt::findOne($item['id']); $item_info->sort_time = time(); $item_info->sort_key = $sort_key; $item_info->save(); } } } } }catch(\Exception $e) { debug_log($e->getMessage(), '20250507.log'); } } } }