CardSecretUse.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace addons\CardSecret\common\models;
  3. use addons\CardSecret\common\models\Cate;
  4. use addons\CardSecret\common\models\CardSecret;
  5. use common\models\goods\Goods;
  6. use common\models\user\User;
  7. use Yii;
  8. /**
  9. * This is the model class for table "{{%addons_CardSecret_use}}".
  10. *
  11. * @property int $id
  12. * @property int|null $mall_id 商城ID
  13. * @property int|null $user_id 用户ID
  14. * @property int|null $card_secret_id 密码ID
  15. * @property int|null $order_id 订单ID
  16. * @property int|null $use_status 使用状态 (1.未领取,2.待领取,3.已失效)
  17. * @property string|null $status 状态(-1是已删除,0是禁用,1是正常)
  18. * @property int|null $cate_id 分类ID
  19. * @property int|null $created_at 创建时间
  20. * @property int|null $updated_at 更新时间
  21. * * @property int|null $goods_id 更新时间
  22. */
  23. class CardSecretUse extends \common\models\base\BaseActiveRecord
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName()
  29. {
  30. return '{{%addons_card_secret_use}}';
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function rules()
  36. {
  37. return [
  38. [['mall_id', 'user_id','status', 'card_secret_id','goods_id', 'order_id', 'use_status', 'cate_id', 'created_at', 'updated_at'], 'integer'],
  39. ];
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function attributeLabels()
  45. {
  46. return [
  47. 'id' => 'ID',
  48. 'mall_id' => '商城ID',
  49. 'user_id' => '用户ID',
  50. 'card_secret_id' => '密码ID',
  51. 'order_id' => '订单ID',
  52. 'use_status' => '使用状态 (1.未领取,2.待领取,3已领取,4.已失效)',
  53. 'status' => '状态(-1是已删除,0是禁用,1是正常)',
  54. 'cate_id' => '分类ID',
  55. 'goods_id' => '商品',
  56. 'created_at' => '创建时间',
  57. 'updated_at' => '更新时间',
  58. ];
  59. }
  60. /**
  61. * 保存数据
  62. * @Author: ltm
  63. * @DateTime: 2022/5/6 0022 17:13
  64. * @Copyright: copyright (c) 2021 广东七件事集团
  65. * @param array $params
  66. * @return string
  67. */
  68. public static function setData(array $params){
  69. try{
  70. $model = self::findOne(['order_id'=>$params['order_id'],'goods_id'=>$params['goods_id']]);
  71. if (!$model) {
  72. $model = new self();
  73. $model->loadDefaultValues();
  74. }else{
  75. if (empty($model)) throw new Exception('记录以存在,不可以在领取');
  76. }
  77. $model->mall_id = $params['mall_id'];
  78. if(!$model->load($params,'') || !$model->save()){
  79. throw new Exception($model->getErrorMessage());
  80. }
  81. return $model;
  82. }catch(\Exception $e){
  83. self::$static_error = $e->getMessage();
  84. return false;
  85. }
  86. }
  87. /**
  88. * 关联用户信息
  89. * @Author:ltm
  90. * @DateTime: 2022/5/6 0022 17:13
  91. * @Copyright: copyright (c) 2021 广东七件事集团
  92. * @return \yii\db\ActiveQuery
  93. */
  94. public function getUser()
  95. {
  96. return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,nickname,username,mobile,avatar_url');
  97. }
  98. /**
  99. * 关联卡号信息
  100. * @Author:ltm
  101. * @DateTime: 2022/5/6 0022 17:13
  102. * @Copyright: copyright (c) 2021 广东七件事集团
  103. * @return \yii\db\ActiveQuery
  104. */
  105. public function getCardSecret()
  106. {
  107. return $this->hasOne(CardSecret::class, ['id' => 'card_secret_id'])->select('id,name,password,use_status');
  108. }
  109. /**
  110. * 关联商品信息
  111. * @Author:ltm
  112. * @DateTime: 2022/5/6 0022 17:13
  113. * @Copyright: copyright (c) 2021 广东七件事集团
  114. * @return \yii\db\ActiveQuery
  115. */
  116. public function getGoods()
  117. {
  118. return $this->hasOne(Goods::class, ['id' => 'goods_id'])->select('id,goods_name,cover_pic');
  119. }
  120. /**
  121. *
  122. * 关联分类信息
  123. * @Author:ltm
  124. * @DateTime: 2022/5/6 0022 17:13
  125. * @Copyright: copyright (c) 2021 广东七件事集团
  126. * @return \yii\db\ActiveQuery
  127. */
  128. public function getCate()
  129. {
  130. return $this->hasOne(Cate::class, ['id' => 'cate_id'])->select('id,name');
  131. }
  132. }