| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- namespace addons\Sudoku\common\models;
- use addons\Coupon\common\models\AddonsCoupon;
- use common\enums\StatusEnum;
- use common\models\goods\Goods;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "qimall_addons_sudoku".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property string|null $name 别名
- * @property int|null $type 1.红包2.优惠券3.积分4.实物.5.无
- * @property int|null $goods_id 商品
- * @property int|null $score 积分
- * @property float|null $red_packet_amount 红包价格
- * @property string|null $image_url 图片
- * @property int|null $coupon_id 优惠券
- * @property int|null $stock 库存
- * @property float|null $probability 概率
- * @property int|null $prize_id 奖品ID
- * @property int $created_at 创建时间
- * @property int|null $updated_at 更新时间
- */
- class AddonsSudoku extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_sudoku}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'created_at'], 'required'],
- [['mall_id', 'type', 'goods_id', 'coupon_id', 'stock', 'prize_id', 'created_at', 'updated_at'], 'integer'],
- [['red_packet_amount','score', 'probability'], 'number'],
- [['name', 'image_url'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'name' => '别名',
- 'type' => '1.红包2.优惠卷3.积分4.实物.5.无',
- 'goods_id' => '商品',
- 'score' => '积分',
- 'red_packet_amount' => '红包价格',
- 'image_url' => '图片',
- 'coupon_id' => '优惠券',
- 'stock' => '库存',
- 'probability' => '概率',
- 'prize_id' => '奖品ID',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- //管理优惠卷
- public function getCoupon()
- {
- return $this->hasOne(AddonsCoupon::class, ['id' => 'coupon_id'])->select('id,name,discount,min_price,sub_price,total_count,receive_count,status');
- }
- //管理商品
- public function getGoods()
- {
- return $this->hasOne(Goods::class, ['id' => 'goods_id'])->select('id,goods_name,price,cover_pic,status,stock,is_on_sale');
- }
- /**
- * 保存数据
- * @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(['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;
- }
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2021/12/27 0022 14:12
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return AddonsMaterial|bool
- */
- public static function getPrizeName($list){
- if($list){
- foreach ($list as $k=>$v){
- switch ($v['type']){
- case '1': //奖励金额
- $list[$k]['prize_name'] = '余额 +'.$v['red_packet_amount'].'';
- break;
- case '2': //奖励优惠卷
- $list[$k]['prize_name'] = '优惠券 '.$v['coupon']['name'];
- break;
- case '3': //奖励积分
- $list[$k]['prize_name'] = '积分 +'.$v['score'];
- break;
- case '4': //奖励商品
- $list[$k]['prize_name'] = '商品:'.$v['goods']['goods_name'].'商品一件';
- break;
- case '5': //谢谢参与
- $list[$k]['prize_name'] = '谢谢参与';
- break;
- }
- }
- return $list;
- }
- }
- }
|