| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace addons\BlindBox\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use common\models\common\Addons;
- use common\models\mall\MallAddons;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_blind_box_user".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property int $user_id 会员id
- * @property float $frozen_commission 冻结佣金
- * @property float $total_commission 总佣金(已结算)
- * @property float $total_pay_money 总消费金额
- * @property float $remaining_pay_money 剩余消费金额
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class BlindBoxUser extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_blind_box_user}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'status', 'created_at', 'updated_at'], 'integer'],
- [['frozen_commission', 'total_commission','total_pay_money','remaining_pay_money'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'user_id' => '会员id',
- 'frozen_commission' => '冻结佣金',
- 'total_commission' => '总佣金(已结算)',
- 'total_pay_money' => '总消费金额',
- 'remaining_pay_money' => '剩余消费金额',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData(array $params)
- {
- try {
- $model = BlindBoxUser::findOne(['user_id' => $params['user_id'], 'mall_id' => $params['mall_id']]);
- if (empty($model)) {
- $model = new BlindBoxUser();
- $model->loadDefaultValues();
- $model->user_id = $params['user_id'];
- $model->mall_id = $params['mall_id'];
- }
- if (!empty($params['order_bonus'])) $model->frozen_commission = bcadd($model->frozen_commission, $params['order_bonus'], 2);
- if (!empty($params['total_pay_money'])) $model->total_pay_money = bcadd($model->total_pay_money, $params['total_pay_money'], 2);
- if (!empty($params['remaining_pay_money'])) $model->remaining_pay_money = $params['remaining_pay_money'];
- $res = $model->save();
- if ($res == false) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- 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 [];
- }
- }
|