AddonsSudokuLog.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace addons\Sudoku\common\models;
  3. use addons\Coupon\common\models\AddonsCoupon;
  4. use common\enums\StatusEnum;
  5. use common\models\goods\Goods;
  6. use common\models\order\Order;
  7. use common\models\user\User;
  8. use common\models\user\UserAddress;
  9. use Yii;
  10. use yii\db\Exception;
  11. /**
  12. * This is the model class for table "qimall_addons_sudoku_log".
  13. *
  14. * @property int $id
  15. * @property int $mall_id 商城ID
  16. * @property int|null $sudoku_id 九宫格奖品ID
  17. * @property int $user_id 用户ID
  18. * @property int $status 0未领取1 已领取
  19. * @property int $type 1.红包2.优惠卷3.积分4.实物5无
  20. * @property int|null $coupon_id 优惠券ID
  21. * @property int|null $goods_id 商品id
  22. * @property int $order_id 主订单ID
  23. * @property int|null $receive_at 领取时间
  24. * @property int $created_at 创建时间
  25. * @property float $score 积分
  26. * @property float $red_packet_amount 金额
  27. */
  28. class AddonsSudokuLog extends \common\models\base\BaseActiveRecord
  29. {
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public static function tableName()
  34. {
  35. return '{{%addons_sudoku_log}}';
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function rules()
  41. {
  42. return [
  43. [['mall_id','order_id','sudoku_id', 'user_id', 'status', 'type', 'coupon_id', 'goods_id', 'receive_at', 'created_at'], 'integer'],
  44. [['user_id', 'type'], 'required'],
  45. [['score','red_packet_amount'], 'number'],
  46. ];
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function attributeLabels()
  52. {
  53. return [
  54. 'id' => 'ID',
  55. 'mall_id' => '商城ID',
  56. 'sudoku_id' => '九宫格奖品ID',
  57. 'user_id' => '用户ID',
  58. 'status' => ' 0未领取1 已领取',
  59. 'type' => '1.红包2.优惠卷3.积分4.实物5无',
  60. 'coupon_id' => '优惠券ID',
  61. 'goods_id' => '商品id',
  62. 'order_id' => '主订单ID',
  63. 'receive_at' => '领取时间',
  64. 'created_at' => '创建时间',
  65. 'score' => '积分',
  66. 'red_packet_amount' => '金额',
  67. ];
  68. }
  69. //管理奖品
  70. public function getSudoku()
  71. {
  72. return $this->hasOne(AddonsSudoku::class, ['id' => 'sudoku_id'])->select('id,name,image_url');
  73. }
  74. //管理优惠卷
  75. public function getCoupon()
  76. {
  77. return $this->hasOne(AddonsCoupon::class, ['id' => 'coupon_id'])->select('id,name,discount,min_price,sub_price,pic_url');
  78. }
  79. //管理商品
  80. public function getGoods()
  81. {
  82. return $this->hasOne(Goods::class, ['id' => 'goods_id'])
  83. ->select('id,mall_id,mch_id,goods_name,price,original_price,cost_price,unit,cover_pic,bannar_pic,video_url,video_cover_pic,is_on_sale,is_attr,status,is_show_sales,virtual_sales,sales_num,stock,freight_type,freight_rules_type,freight_id,shipping_fee,free_shipping_num,free_shipping_money,detail');
  84. }
  85. //订单
  86. public function getOrder()
  87. {
  88. return $this->hasOne(Order::class, ['id' => 'order_id'])->select('id,order_no,order_status,created_at');
  89. }
  90. public function getUser()
  91. {
  92. return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id,username');
  93. }
  94. //获取用户默认地址
  95. public function getAddress()
  96. {
  97. return $this->hasOne(UserAddress::class, ['user_id' => 'user_id'])
  98. ->select('id,user_id,name,province_id,province,city_id,city,district_id,district,town_id,town,mobile,detail,')
  99. ->where(['is_default' => StatusEnum::ENABLED, "status" => StatusEnum::ENABLED]);
  100. }
  101. /**
  102. * 保存数据
  103. * @Author: ltm
  104. * @DateTime: 2021/12/18 0022 17:13
  105. * @Copyright: copyright (c) 2021 广东七件事集团
  106. * @param array $params
  107. * @return AddonsMaterial|bool
  108. */
  109. public static function setData(array $params){
  110. try{
  111. if (!empty($params['id'])) {
  112. $model = self::findOne(['and',['id'=>$params['id'],'mall_id'=>$params['mall_id']]]);
  113. if (empty($model)) throw new Exception('记录不存在或已删除');
  114. }else{
  115. $model = new self();
  116. $model->loadDefaultValues();
  117. $model->mall_id = $params['mall_id'];
  118. }
  119. if(!$model->load($params,'') || !$model->save()){
  120. throw new Exception($model->getErrorMessage());
  121. }
  122. return $model;
  123. }catch(\Exception $e){
  124. self::$static_error = $e->getMessage();
  125. return false;
  126. }
  127. }
  128. }