| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
- namespace addons\DoubleCopy\common\models;
- use addons\DoubleCopy\common\enums\DoubleCopyEnum;
- use common\enums\StatusEnum;
- use common\models\common\Addons;
- use common\models\mall\MallAddons;
- use common\models\user\User;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_double_copy_commission}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id
- * @property int $buy_uid
- * @property int $is_frozen 是否冻结[0:否,1:是]
- * @property int $order_id 订单ID
- * @property string $order_no 订单编号
- * @property float $pay_money 支付金额,单位:元
- * @property float $money 金额,单位:元
- * @property string $goods_name 商品名称
- * @property string $pic_url 商品封面
- * @property float $price 商品价格
- * @property string $source_table 来源表
- * @property int $source_table_id 操作来源业务id
- * @property string $capital_type 资金类型
- * @property int $settlement_type 结算状态[-1:已失效,0:未结算,1:已结算,2:部分结算]
- * @property int $frozen_status 是否已转移到冻结基金钱包[0=否,1=是]
- * @property int $setting 生成数据时配置
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 添加时间戳
- * @property int $updated_at 更新时间戳
- * @property string $reward_currency 奖励类型:佣金-commission,积分-score
- * @property string $operation_type 操作类型(主要是为了标识扣减原因)
- * @property string $operation_id 配合operation_type使用
- */
- class DoubleCopyCommission extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_double_copy_commission}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'buy_uid', 'order_id', 'is_frozen', 'source_table_id', 'settlement_type', 'frozen_status', 'status', 'created_at', 'updated_at', 'operation_id'], 'integer'],
- [['pay_money', 'money', 'price'], 'number'],
- [['order_no'], 'string', 'max' => 60],
- [['source_table'], 'string', 'max' => 100],
- [['capital_type'], 'string', 'max' => 255],
- [['setting'], 'string'],
- [['reward_currency'], 'string'],
- [['goods_name'],'string'],
- [['operation_type'], 'string', 'max' => 50],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'buy_uid' => '下单用户id',
- 'is_frozen' => '是否冻结[0:否,1:是]',
- 'order_id' => '订单ID',
- 'order_no' => '订单编号',
- 'pay_money' => '支付金额,单位:元',
- 'money' => '金额,单位:元',
- 'goods_name' => '商品名称',
- 'pic_url' => '商品图片',
- 'price' => '商品金额',
- 'source_table' => '来源表',
- 'source_table_id' => '操作来源业务id',
- 'capital_type' => '资金类型',
- 'settlement_type' => '结算状态[-1:已失效,0:未结算,1:已结算,2:部分结算]',
- 'frozen_status' => '是否已转移到冻结基金钱包[0=否,1=是]',
- 'setting' => '生成数据时配置',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => '添加时间戳',
- 'updated_at' => '更新时间戳',
- 'operation_type' => '操作类型',
- 'operation_id' => '操作ID,配合operation_type使用',
- ];
- }
- /**
- * 获取用户
- * @Author: lun
- * @DateTime: 2022/5/14 0014 15:31
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,nickname,mobile,avatar_url,parent_id');
- }
- /**
- * 关联链动用户
- * @Author: lun
- * @DateTime: 2022/5/14 0014 17:47
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getLduser()
- {
- return $this->hasOne(DoubleCopyUser::class, ['user_id' => 'user_id'])->andWhere(['<>', 'status', StatusEnum::DELETE])->select('user_id,level');
- }
- /**
- * 获取下单用户
- * @Author: lun
- * @DateTime: 2022/5/14 0014 15:31
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getBuyuser()
- {
- return $this->hasOne(User::class, ['id' => 'buy_uid'])->select('id,nickname,mobile,avatar_url,parent_id');
- }
- public static function getAddons(array $params){
- $addons_name = $params['addons_name'];
- $is_install = MallAddons::isInstall($params['mall_id'], $addons_name);
- if($is_install){
- $detail = Addons::getOne([['name' =>$addons_name], ['is_online' => 1]], true);
- return [
- 'addons_name'=>$addons_name,
- 'title'=>$detail['title'],
- ];
- }
- return [];
- }
- /**
- * 获取未结算的冻结基金
- * @Author:lun
- * @Date:2023-12-04 10:04
- * @Copyright:copyright(c)2023 广东七件事集团
- * @param $user_id
- * @return bool|int|mixed|string
- */
- public static function getNoSettlementForzen($user_id, $reward_currency = 'commission')
- {
- return self::find()->where(['user_id' => $user_id, 'is_frozen' => StatusEnum::ENABLED, 'reward_currency' => $reward_currency, 'settlement_type' => [DoubleCopyEnum::NOT_SETTLEMENT,DoubleCopyEnum::PART_SETTLED], 'frozen_status' => StatusEnum::DISABLED, 'status' => StatusEnum::ENABLED])->sum('money') ?? 0;
- }
- public static function setData($params)
- {
- try {
- $model = new self();
- $model->loadDefaultValues();
- if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model->toArray();
- } catch (\Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- /**
- * 处理已结算的冻结基金,将状态改为已转入冻结基金钱包
- * @Author:lun
- * @Date:2024-03-16 11:37
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return void
- */
- public static function handleFrozenStatus()
- {
- $part = 1;
- $limit = 1000;
- while ($frozen_order_ids = self::find()->where(['capital_type' => DoubleCopyEnum::SECOND_PRIZE, 'settlement_type' => StatusEnum::ENABLED, 'status' => StatusEnum::ENABLED])->select('order_id')->orderBy('id asc')
- ->offset(($part - 1) * $limit)->limit($limit)->column()) {
- $frozen_order_ids = implode(',', $frozen_order_ids);
- echo $frozen_order_ids.'<br>';
- self::updateAll(['frozen_status' => StatusEnum::ENABLED], "order_id in({$frozen_order_ids}) and capital_type='".DoubleCopyEnum::FREEZE_FUND."'");
- $part ++;
- }
- }
- }
|