'ID', 'mall_id' => 'Mall ID', 'user_id' => 'User ID', 'user_ids' => 'User Ids', 'exclude_user_ids' => 'Exclude User Ids', 'order_id' => 'Order ID', 'order_detail_id' => 'Order Detail ID', 'reward_period' => 'Reward Period', 'frozen_score_issued_total' => 'Frozen Score Issued Total', 'reward_frozen_score' => 'Reward Frozen Score', 'reward_person_count' => 'Reward Person Count', 'loop_num' => 'Loop Num', 'current_loop_num' => 'Current Loop Num', 'current_reward_person_index' => 'Current Reward Person Index', 'is_end' => 'Is End', 'last_exec_date' => 'Last Exec Date', 'status' => 'Status', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } /** * @param array $params * * @return bool|self */ public static function setData(array $params) { try { if (!empty($params['id'])) { $model = static::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); if (!$model) { throw new RuntimeException('数据不存在或已删除'); } if ($model->mall_id != $params['mall_id']) { throw new RuntimeException('不允许操作此数据'); } } else { $model = new static(); $model->loadDefaultValues(); } if (!$model->load($params, '')) { throw new RuntimeException($model->getErrorMessage()); } if (!$model->save()) { throw new RuntimeException($model->getErrorMessage()); } return $model; } catch (Exception $e) { static::$static_error = $e->getMessage(); return false; } } public function getRecommendRewardDetails() { return $this->hasOne(ScoreExpansionRecommendRewardDetails::class, ['recommend_reward_order_id' => 'id']) ->where(['status' => StatusEnum::ENABLED]); } /** * 移动到下一个奖励人身上 * * @return void */ public function next() { if ($this->current_loop_num <= 1) { if (!$this->user_ids) { $this->is_end = StatusEnum::ENABLED; return; } if ($this->current_loop_num + 1 > $this->loop_num) { $this->is_end = StatusEnum::ENABLED; } else { $this->current_loop_num++; } return; } if (!isset($this->user_ids[$this->current_reward_person_index + 1])) { if ($this->current_loop_num + 1 > $this->loop_num) { $this->is_end = StatusEnum::ENABLED; } else { $this->current_loop_num++; $this->current_reward_person_index = 0; } } else { $this->current_reward_person_index++; } } }