'--', self::BONUS_FIRST_SHARE => '一级分销', self::BONUS_SECOND_SHARE => '二级分销', self::BONUS_THIRD_SHARE => '三级分销', 4 => '自购返利', 5 => '订单佣金', 6 => '临时关系', 7 => '推广佣金', 8 => '一级返现奖励', 9 => '二级返现奖励', 10 => '后台修改', self::BONUS_LAYER => '见点层级奖励', self::BONUS_AREA => '区域分红', self::BONUS_SHARE_HOLDER_INVITE => '股东直推', self::BONUS_SHARE_HOLDER_TEAM => '团队奖励', self::BONUS_SHARE_HOLDER_TEAM_EQUAL => '团队平级奖励', self::CASE => '佣金提现', ]; /** * @inheritdoc */ public static function tableName() { return '{{%user_share_money}}'; } /** * @inheritdoc */ public function rules() { return [ [['store_id', 'order_id', 'user_id', 'type', 'source', 'is_delete', 'created_at', 'order_type'], 'integer'], [['money'], 'number'], [['version', 'desc'], 'string', 'max' => 255], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'store_id' => 'Store ID', 'order_id' => '订单ID', 'user_id' => '用户ID', 'type' => '类型 0--佣金 1--提现 2--股东 3--见点', 'source' => '佣金来源 1--一级分销 2--二级分销 3--三级分销 4--自购返利 5--订单佣金 6--临时佣金', 'money' => '金额', 'is_delete' => 'Is Delete', 'created_at' => 'Addtime', 'order_type' => '订单类型 0--商城订单 1--秒杀订单 2--拼团订单 3--预约订单 4--会员订单', 'version' => '版本', ]; } public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); if (!cache_lock(['ShareLevelJob', $this->store_id, $this->user_id], 30)) { \queue_push(new \app\jobs\ShareLevelJob(['store_id' => $this->store_id, 'user_id' => $this->user_id]), 30, 1); } } public static function set($money, $user_id, $order_id, $type, $source = 1, $store_id = 0, $order_type = 0, $desc = '') { $model = new UserShareMoney(); $model->store_id = $store_id; $model->order_id = $order_id; $model->user_id = $user_id; $model->type = $type; $model->source = $source; $model->money = $money; $model->is_delete = 0; $model->created_at = time(); $model->order_type = $order_type; $model->version = cyy_version(); $model->desc = $desc; return $model->save(); } public function getStore(){ return $this->hasOne(Store::className(), ['id'=>'store_id']); } public function getOrder(){ return $this->hasOne(Order::className(), ['id'=>'order_id']); } public static function getSourceName($source, $store_id) { $name = self::SOURCE_NAME[$source] ?? '--'; if (in_array($source, [1, 2, 3])) { $option = Option::get('share_money_setting', $store_id, OptionSetting::SHARE_GROUP_NAME); if ($option) { $data = json_decode($option['value'], true); if ($source == 1) { $name = $data['level_one']['text'] ?? $name; } if ($source == 2) { $name = $data['level_two']['text'] ?? $name; } if ($source == 3) { $name = $data['level_three']['text'] ?? $name; } } } return $name; } }