| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace addons\ElectronCoupon\common\models;
- use common\enums\StatusEnum;
- use Yii;
- use common\models\user\User;
- /**
- * This is the model class for table "{{%addons_electron_coupon_approval_income_log}}".
- *
- * @property int $id 自增id
- * @property int $e_coupon_code_id 核销码id
- * @property int $user_e_coupon_id 会员电子券id
- * @property int $e_coupon_id 电子券id
- * @property int $created_at
- * @property int $updated_at
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int $user_id 使用会员user_id
- * @property string $e_coupon_name 电子券名称
- * @property int $amount 数量
- * @property int|null $mall_id 商城id
- * @property int $price_type 收益类型1积分2佣金
- * @property float $commission 积分或佣金金额
- * @property int $clerk_user_id 核销员user_id
- */
- class ElectronCouponApprovalIncomeLog extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_electron_coupon_approval_income_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['e_coupon_code_id', 'user_e_coupon_id', 'e_coupon_id', 'user_id', 'e_coupon_name', 'clerk_user_id'], 'required'],
- [['e_coupon_code_id', 'user_e_coupon_id', 'e_coupon_id', 'created_at', 'updated_at', 'status', 'user_id', 'amount', 'mall_id', 'price_type', 'clerk_user_id', 'clerk_admin_id'], 'integer'],
- [['commission'], 'number'],
- [['e_coupon_name'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => '自增id',
- 'e_coupon_code_id' => '核销码id',
- 'user_e_coupon_id' => '会员电子券id',
- 'e_coupon_id' => '电子券id',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'user_id' => '使用会员user_id',
- 'e_coupon_name' => '电子券名称',
- 'amount' => '数量',
- 'mall_id' => '商城id',
- 'price_type' => '收益类型1积分2佣金',
- 'commission' => '积分或佣金金额',
- 'clerk_user_id' => '核销员user_id',
- 'clerk_admin_id' => '核销员admin_id(后台核销)',
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,username');
- }
- /**
- * 数据设置
- */
- public static function setData(array $params)
- {
- try{
- if (!isset($params['mall_id']) || empty($params['mall_id'])) throw new Exception('缺少商城ID');
- $mall_id = $params['mall_id'];
- if (isset($params['id']) && !empty($params['id'])) {
- $model = self::findOne(['id' => $params['id'], 'mall_id' => $mall_id, 'status' => StatusEnum::ENABLED]);
- if(empty($model)) throw new Exception('收益记录不存在或已删除');
- } else {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- }
- if (!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- }catch(Exception $e){
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|