| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace addons\ElectronCoupon\common\models;
- use Yii;
- class ElectronCouponUsageLog extends \common\models\base\BaseActiveRecord
- {
- public static function tableName()
- {
- return '{{%addons_electron_coupon_usage_log}}';
- }
- public function rules()
- {
- return [
- [['e_coupon_id', 'user_id', 'mall_id', 'user_e_coupon_id'], 'required'],
- [['e_coupon_id', 'user_id', 'mall_id', 'user_e_coupon_id', 'clerk_user_id', 'clerk_admin_id', 'proper_user_id', 'receive_time', 'usage_time', 'status', 'created_at', 'updated_at', 'amount'], 'integer'],
- [['e_coupon_name'], 'string'],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'e_coupon_id' => '电子券id',
- 'e_coupon_name' => '电子券名称',
- 'user_id' => '使用者',
- 'clerk_user_id' => '核销员',
- 'clerk_admin_id' => '核销员(管理员)',
- 'proper_user_id' => '专有者',
- 'receive_time' => '领取时间',
- 'usage_time' => '使用时间',
- 'amount' => '兑换数量',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- /**
- * 数据设置
- */
- 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;
- }
- }
- }
|