| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace addons\Album\common\models;
- use common\models\goods\Goods;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "qimall_addons_album_goods_visit".
- *
- * @property int $id ID
- * @property int $mall_id 商城ID
- * @property int $album_id 内容 id
- * @property int $goods_id 商品 id
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- * @property int|null $visit_count 访问人数
- * @property int|null $pay_count 支付人数
- * @property float|null $amount 支付金额
- */
- class AddonsAlbumGoodsVisit extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_album_goods_visit}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'album_id', 'goods_id'], 'required'],
- [['mall_id', 'album_id', 'goods_id', 'created_at', 'updated_at', 'visit_count', 'pay_count'], 'integer'],
- [['amount'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'album_id' => '相册 id',
- 'goods_id' => '商品 id',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- 'visit_count' => '访问人数',
- 'pay_count' => '支付人数',
- 'amount' => '支付金额',
- ];
- }
- //管理商品
- public function getGoods()
- {
- return $this->hasOne(Goods::class, ['id' => 'goods_id'])->select('id,goods_name,price,cover_pic,sales_num,virtual_sales');
- }
- /**
- * @Author: ltm
- * @DateTime: 2022/2/16 0016 9:17
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $data
- * @return string
- */
- public static function setData(array $params){
- try{
- $model = self::findOne(['goods_id'=>$params['goods_id'],'mall_id'=>$params['mall_id'],'album_id'=>$params['album_id']]);
- if (!$model){
- $model = new self();
- $model->created_at = time();
- $model->loadDefaultValues();
- if(!$model->load($params,'')){
- throw new Exception($model->getErrorMessage());
- }
- }else{
- $model->updated_at = time();
- if($params['visit_count']) $model->visit_count += $params['visit_count'];
- if($params['pay_count']) $model->pay_count += $params['pay_count'];
- if($params['goods_amount']) $model->amount += $params['goods_amount'];
- unset($params['visit_count'],$params['pay_count'],$params['goods_amount']);
- }
- $model->mall_id = $params['mall_id'];
- if(!$model->save()){
- throw new Exception($model->getErrorMessage());
- }
- return $model;
- }catch(\Exception $e){
- var_dump($e->getMessage());
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|