| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- namespace addons\Boss\common\models;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_boss_reward_log}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $order_id 订单ID
- * @property string $order_no 订单编号
- * @property int $user_id 用户ID
- * @property int $type 结算类型:1永久分红,2额外分红
- * @property int $level 结算时用户的股东等级
- * @property int $average_count 结算人数
- * @property float $amounts 结算的总金额,单位:元
- * @property float $commission 结算的佣金,单位:元
- * @property string|null $settlement_config 结算时的配置
- * @property string|null $settlement_data 结算时的数据
- * @property string $from_type 结算时的数据
- * @property int $is_settlement 是否已结算【0否,1是】
- * @property int $date 数据生成日期
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class AddonsBossRewardLog extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_boss_reward_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'order_id', 'user_id', 'type', 'level', 'average_count', 'is_settlement', 'date', 'status', 'created_at', 'updated_at'], 'integer'],
- [['amounts', 'commission'], 'number'],
- [['settlement_config', 'settlement_data'], 'string'],
- [['order_no'], 'string', 'max' => 100],
- [['from_type'], 'string', 'max' => 50],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'order_id' => '订单ID',
- 'order_no' => '订单编号',
- 'user_id' => '用户ID',
- 'type' => '结算类型:1永久分红,2额外分红',
- 'level' => '结算时用户的股东等级',
- 'average_count' => '结算人数',
- 'amounts' => '结算的总金额,单位:元',
- 'commission' => '结算的佣金,单位:元',
- 'settlement_config' => '结算时的配置',
- 'settlement_data' => '结算时的数据',
- 'is_settlement' => '是否已结算【0否,1是】',
- 'date' => '数据生成日期',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 关联用户表
- * @Author: lun
- * @DateTime: 2023/7/18 0018 17:37
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,nickname,mobile,username,avatar_url');
- }
- /**
- * 生成沉淀池数据
- * @Author: lun
- * @DateTime: 2022/9/21 0021 15:43
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $params
- * @param $sediment_percent
- * @param $job_id
- * @return array
- * @throws Exception
- */
- public static function createSediment($mall_id, $params, $sediment_percent, $job_id)
- {
- // 按照比例计算沉淀池金额,不四舍五入保留两位小数
- $sedimen_money = sprintf("%.2f",substr(sprintf("%.3f", ($params['commission'] * $sediment_percent / 100)), 0, -1));
- // 剩余分红金额,不四舍五入保留两位小数
- $surplus_commission = sprintf("%.2f",substr(sprintf("%.3f", ($params['commission'] - $sedimen_money)), 0, -1));
- // 必须大于一分钱才可以进入
- $data = [];$time = time();
- if ($sedimen_money >= 0.01) {
- $data['mall_id'] = $mall_id;
- $data['user_id'] = $params['user_id'];
- $data['type'] = $params['type'];
- $data['level'] = $params['level'];
- $data['amounts'] = $params['commission'];
- $data['commission'] = $sedimen_money;
- $data['settlement_config'] = json_encode(['sediment_percent' => $sediment_percent]);
- $data['settlement_data'] = json_encode(['job_id' => $job_id]);
- $data['is_settlement'] = StatusEnum::DISABLED;
- $data['date'] = date('Ymd', $time);
- $data['created_at'] = $time;
- $data['updated_at'] = $time;
- }
- return ['commission' => $surplus_commission, 'sedimen_money' => $sedimen_money, 'reward' => $data];
- }
- /**
- * 获取未结算的分红
- *
- * @param int $user_id
- * @param int $mall_id
- * @return float
- */
- public static function getUnsettledCommission(int $user_id, int $mall_id)
- {
- return self::find()
- ->where(['user_id' => $user_id, 'mall_id' => $mall_id, 'is_settlement' => 0, 'status' => StatusEnum::ENABLED])
- ->sum('commission') ?: 0.00;
- }
- }
|