| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace addons\Scratch\common\models;
- use addons\Coupon\common\models\AddonsCoupon;
- use addons\Scratch\common\enums\ScratchEnum;
- use common\models\base\BaseActiveRecord;
- use common\models\goods\Goods;
- use common\models\mall\MallAddons;
- use common\models\order\Order;
- /**
- * Class CouponRelationModel
- * @package addons\Scratch\common\models
- */
- class CouponRelationModel extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_scratch_log_coupon_relation}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'scratch_log_id', 'user_coupon_id'], 'required'],
- [['mall_id', 'user_id', 'scratch_log_id', 'user_coupon_id', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'status' => '状态-1 删除 0 关闭 1开启',
- ];
- }
- /**
- * @param $mallId
- * @param $params
- * @return CouponRelationModel
- * @throws \Exception
- */
- public static function setData($params)
- {
- try {
- $data = self::findOne($params);
- if(!empty($data)){
- return $data;
- }
- $model = new self();
- $model->mall_id = $params['mall_id'] ?? 0;
- $model->user_id = $params['user_id'] ?? 0;
- $model->scratch_log_id = $params['scratch_log_id'] ?? 0;
- $model->user_coupon_id = $params['user_coupon_id'] ?? 0;
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $exception) {
- throw new \Exception($exception->getMessage());
- }
- }
- }
|