| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace addons\Certificate\common\models;
- use common\models\user\User;
- use addons\Certificate\common\models\Certificate;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_certificate_claim}}".
- *
- * @property int $id
- * @property int|null $mall_id 商城ID
- * @property int|null $number 证书编号
- * @property int|null $certificate_id 证书ID
- * @property int|null $user_id 用户ID
- * @property string|null $status 状态(-1是已删除,0是禁用,1是正常)
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 更新时间
- */
- class CertificateClaim extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_certificate_claim}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id','status', 'number', 'certificate_id', 'user_id', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'number' => '证书编号',
- 'certificate_id' => '证书ID',
- 'user_id' => '用户ID',
- 'status' => '状态(-1是已删除,0是禁用,1是正常)',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2022/5/7 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return string
- */
- public static function setData(array $params){
- try{
- $status = 0;
- $model = self::findOne(['certificate_id'=>$params['id'],'mall_id'=>$params['mall_id'],'user_id'=>$params['user_id']]);
- if (!$model) {
- $model = new self();
- $model->number = $params['user_id'].substr($params['mobile'],-4).$params['id'];
- $model->loadDefaultValues();
- $status = 1;
- }
- $model->certificate_id = $params['id'];
- $model->mall_id = $params['mall_id'];
- $certificate = Certificate::findOne(['id'=>$params['id'],'mall_id'=>$params['mall_id']]);
- $certificate->download_num = $certificate->download_num + 1;
- if(!$model->load($params,'') || !$model->save()){
- throw new Exception($model->getErrorMessage());
- }
- $certificate->save();
- return $model;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 关联用户信息
- * @Author:ltm
- * @DateTime: 2022/5/7 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,nickname,username,mobile,avatar_url');
- }
- /**
- * 关联卡号信息
- * @Author:ltm
- * @DateTime: 2022/5/7 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getCertificate()
- {
- return $this->hasOne(Certificate::class, ['id' => 'certificate_id'])->select('id,name');
- }
- }
|