| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use Yii;
- use app\models\Option;
- use app\constants\OptionSetting;
- /**
- * This is the model class for table "{{%user_share_money}}".
- *
- * @property integer $id
- * @property integer $store_id
- * @property integer $order_id
- * @property integer $user_id
- * @property integer $type
- * @property integer $source
- * @property string $money
- * @property integer $is_delete
- * @property integer $created_at
- * @property integer $order_type
- * @property string $version
- * @property string $desc
- */
- class UserShareMoney extends \yii\db\ActiveRecord
- {
- const LEVEL_ORDER_TYPE = 4;
- const BONUS_FIRST_SHARE = 1;
- const BONUS_SECOND_SHARE = 2;
- const BONUS_THIRD_SHARE = 3;
- const BONUS_LAYER = 11;
- const BONUS_AREA = 12;
- const BONUS_SHARE_HOLDER_INVITE = 13;
- const BONUS_SHARE_HOLDER_TEAM = 14;
- const BONUS_SHARE_HOLDER_TEAM_EQUAL = 15;
- const CASE = 20;
- const SOURCE_NAME = [
- 0 => '--',
- 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;
- }
- }
|