| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- namespace addons\CardSecret\common\models;
- use addons\CardSecret\common\models\Cate;
- use addons\CardSecret\common\models\CardSecret;
- use common\models\goods\Goods;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "{{%addons_CardSecret_use}}".
- *
- * @property int $id
- * @property int|null $mall_id 商城ID
- * @property int|null $user_id 用户ID
- * @property int|null $card_secret_id 密码ID
- * @property int|null $order_id 订单ID
- * @property int|null $use_status 使用状态 (1.未领取,2.待领取,3.已失效)
- * @property string|null $status 状态(-1是已删除,0是禁用,1是正常)
- * @property int|null $cate_id 分类ID
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 更新时间
- * * @property int|null $goods_id 更新时间
- */
- class CardSecretUse extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_card_secret_use}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id','status', 'card_secret_id','goods_id', 'order_id', 'use_status', 'cate_id', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '用户ID',
- 'card_secret_id' => '密码ID',
- 'order_id' => '订单ID',
- 'use_status' => '使用状态 (1.未领取,2.待领取,3已领取,4.已失效)',
- 'status' => '状态(-1是已删除,0是禁用,1是正常)',
- 'cate_id' => '分类ID',
- 'goods_id' => '商品',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2022/5/6 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return string
- */
- public static function setData(array $params){
- try{
- $model = self::findOne(['order_id'=>$params['order_id'],'goods_id'=>$params['goods_id']]);
- if (!$model) {
- $model = new self();
- $model->loadDefaultValues();
- }else{
- if (empty($model)) throw new Exception('记录以存在,不可以在领取');
- }
- $model->mall_id = $params['mall_id'];
- if(!$model->load($params,'') || !$model->save()){
- throw new Exception($model->getErrorMessage());
- }
- return $model;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 关联用户信息
- * @Author:ltm
- * @DateTime: 2022/5/6 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/6 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getCardSecret()
- {
- return $this->hasOne(CardSecret::class, ['id' => 'card_secret_id'])->select('id,name,password,use_status');
- }
- /**
- * 关联商品信息
- * @Author:ltm
- * @DateTime: 2022/5/6 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getGoods()
- {
- return $this->hasOne(Goods::class, ['id' => 'goods_id'])->select('id,goods_name,cover_pic');
- }
- /**
- *
- * 关联分类信息
- * @Author:ltm
- * @DateTime: 2022/5/6 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getCate()
- {
- return $this->hasOne(Cate::class, ['id' => 'cate_id'])->select('id,name');
- }
- }
|