| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace addons\Sudoku\common\models;
- use addons\Coupon\common\models\AddonsCoupon;
- use common\enums\StatusEnum;
- use common\models\goods\Goods;
- use common\models\order\Order;
- use common\models\user\User;
- use common\models\user\UserAddress;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "qimall_addons_sudoku_log".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int|null $sudoku_id 九宫格奖品ID
- * @property int $user_id 用户ID
- * @property int $status 0未领取1 已领取
- * @property int $type 1.红包2.优惠卷3.积分4.实物5无
- * @property int|null $coupon_id 优惠券ID
- * @property int|null $goods_id 商品id
- * @property int $order_id 主订单ID
- * @property int|null $receive_at 领取时间
- * @property int $created_at 创建时间
- * @property float $score 积分
- * @property float $red_packet_amount 金额
- */
- class AddonsSudokuLog extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_sudoku_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id','order_id','sudoku_id', 'user_id', 'status', 'type', 'coupon_id', 'goods_id', 'receive_at', 'created_at'], 'integer'],
- [['user_id', 'type'], 'required'],
- [['score','red_packet_amount'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'sudoku_id' => '九宫格奖品ID',
- 'user_id' => '用户ID',
- 'status' => ' 0未领取1 已领取',
- 'type' => '1.红包2.优惠卷3.积分4.实物5无',
- 'coupon_id' => '优惠券ID',
- 'goods_id' => '商品id',
- 'order_id' => '主订单ID',
- 'receive_at' => '领取时间',
- 'created_at' => '创建时间',
- 'score' => '积分',
- 'red_packet_amount' => '金额',
- ];
- }
- //管理奖品
- public function getSudoku()
- {
- return $this->hasOne(AddonsSudoku::class, ['id' => 'sudoku_id'])->select('id,name,image_url');
- }
- //管理优惠卷
- public function getCoupon()
- {
- return $this->hasOne(AddonsCoupon::class, ['id' => 'coupon_id'])->select('id,name,discount,min_price,sub_price,pic_url');
- }
- //管理商品
- public function getGoods()
- {
- return $this->hasOne(Goods::class, ['id' => 'goods_id'])
- ->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');
- }
- //订单
- public function getOrder()
- {
- return $this->hasOne(Order::class, ['id' => 'order_id'])->select('id,order_no,order_status,created_at');
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id,username');
- }
- //获取用户默认地址
- public function getAddress()
- {
- return $this->hasOne(UserAddress::class, ['user_id' => 'user_id'])
- ->select('id,user_id,name,province_id,province,city_id,city,district_id,district,town_id,town,mobile,detail,')
- ->where(['is_default' => StatusEnum::ENABLED, "status" => StatusEnum::ENABLED]);
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2021/12/18 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return AddonsMaterial|bool
- */
- public static function setData(array $params){
- try{
- if (!empty($params['id'])) {
- $model = self::findOne(['and',['id'=>$params['id'],'mall_id'=>$params['mall_id']]]);
- if (empty($model)) throw new Exception('记录不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- $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;
- }
- }
- }
|