TimestampBehavior::class, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['updated_at', 'created_at'], ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at' ] ] ]; } /** * @inheritdoc */ public function rules() { return [ [['id', 'centralize_goods_id', 'created_at', 'updated_at', 'is_delete', 'goods_num', 'md_id', 'sorting_num', 'status', 'pre_sorting_num'], 'integer'], [['sort_key', 'sort_time'], 'number'] ]; } public function attributeLabels() { return [ 'id' => '', 'centralize_goods_id' => '集采商品表ID', 'md_id' => '门店ID', 'goods_num' => '商品数量', 'sorting_num' => '待分拣数量', 'sort_key' => '门店排序 根据司机以及门店进行排序', 'sort_time' => '门店排序时间方便未分拣完重置时间', 'is_delete' => '', 'created_at' => '', 'updated_at' => '' ]; } public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub if ($insert || isset($changedAttributes['goods_num'])) { $admin = get_admin(); $staff_id = 0; $front_agent_admin_id = $admin->id; if ($admin->type === Admin::ADMIN_TYPE_FRONT_AGENT_STAFF) { $staff_id = $admin->type_id; $agentFrontStaff = AgentFrontStaff::findOne($staff_id); $front_agent_admin_id = $agentFrontStaff->front_agent_admin_id; } $AgentFrontCentralizeGoods = AgentFrontCentralizeGoods::findOne($this->centralize_goods_id); if ($AgentFrontCentralizeGoods) { $attr_info = json_decode($AgentFrontCentralizeGoods->attr_info, true); $attr_name = ""; if ($attr_info) { $attr_name = implode(';', array_column($attr_info['attr_list'], 'attr_name')); } AgentFrontStaffOperateLog::addOperateLog( AgentFrontStaffOperateLog::OPERATE_TYPE_GOODS_CONFIRM, $staff_id, $front_agent_admin_id, $this->id, "商品收货:" . $AgentFrontCentralizeGoods->goods_name. ';规格:' . $attr_name . ';货号:' . $AgentFrontCentralizeGoods->goods_no . ';件数:' . $AgentFrontCentralizeGoods->goods_num, ); } if ($insert) { $mdBind = DriverMdBind::findOne(['md_id' => $this->md_id, 'is_delete' => 0]); if ($mdBind) { $driver_id = $mdBind->driver_id; $driver = Driver::findOne($driver_id); $driver_reset_time = Option::get('driver_reset_time_' . $driver->admin_id, 0, 'agent_front', '00:00')['value']; $driver_reset_start_time = strtotime(date('Y-m-d ' . $driver_reset_time . ':00')); //查询出当前仓库所有的门店下的单 然后统一排序 // $driver_id = \app\models\Driver::find()->where(['admin_id' => $driver->admin_id, 'is_delete' => 0])->select('id')->column(); $md_id = DriverMdBind::find()->where(['driver_id' => $driver_id, 'is_delete' => 0]) ->select('md_id')->column(); //查询出当前仓库门店下的团货商品订单 $goodsExt = self::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' => self::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) { //查询今天已经分拣过的 $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 = self::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 = self::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' => self::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 = self::findOne($item['id']); $item_info->sort_time = time(); $item_info->sort_key = $sort_key; $item_info->save(); } } } } } } }