| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- namespace addons\ScoreExpansion\common\models;
- use common\enums\StatusEnum;
- use Exception;
- use RuntimeException;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_score_expansion_recommend_reward_order".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id 下单User Id
- * @property string|null $user_ids 第一轮之后定下来的关系链
- * @property string|null $exclude_user_ids 第二轮开始谁不满足条件排除的user id,存在这里面的user id之后循环都不会奖励
- * @property int $order_id 订单ID
- * @property int $order_detail_id 订单详情ID
- * @property int $reward_period 奖励周期 0每天
- * @property float $frozen_score_issued_total 已发放的冻结积分
- * @property float $reward_frozen_score 每轮奖励多少个冻结积分
- * @property int $reward_person_count 奖励人数
- * @property int $loop_num 循环轮数
- * @property int $current_loop_num 当前循环到第几轮了
- * @property int $current_reward_person_index 本轮奖励到第几人
- * @property int $is_end 是否结束
- * @property int $last_exec_date 最后一次执行奖励时间
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class ScoreExpansionRecommendRewardOrder extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_score_expansion_recommend_reward_order';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'order_id', 'order_detail_id', 'reward_period', 'reward_person_count', 'loop_num', 'current_loop_num', 'current_reward_person_index', 'is_end', 'last_exec_date', 'status', 'created_at', 'updated_at'], 'integer'],
- [['user_ids', 'exclude_user_ids'], 'safe'],
- [['frozen_score_issued_total', 'reward_frozen_score'], 'number'],
- [['reward_person_count', 'loop_num'], 'required'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => '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++;
- }
- }
- }
|