| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace addons\Xhs\common\models;
- use common\models\goods\Goods;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "qimall_addons_xhs_goods_statistics".
- *
- * @property int $id ID
- * @property int $mall_id 商城ID
- * @property int $goods_id 商品 id
- * @property int $order_num 订单数量
- * @property float $total_amount 商品总金额
- * @property int|null $goods_views_count 商品访问量
- * @property int $created_at 更新时间
- * @property int $updated_at 创建时间
- * @property int $bought_count 购买量
- */
- class AddonsXhsGoodsStatistics extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_xhs_goods_statistics}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'goods_id', 'total_amount'], 'required'],
- [['mall_id', 'goods_id', 'order_num', 'goods_views_count', 'created_at', 'updated_at', 'bought_count'], 'integer'],
- [['total_amount'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'goods_id' => '商品 id',
- 'order_num' => '订单数量',
- 'total_amount' => '商品总金额',
- 'goods_views_count' => '商品访问量',
- 'created_at' => '更新时间',
- 'updated_at' => '创建时间',
- 'bought_count' => '购买量',
- ];
- }
- //管理商品
- 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: 2021/01/10 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return AddonsMaterial|bool
- */
- public static function setData(array $params){
- try{
- $model = self::findOne(['mall_id' => $params['mall_id'],'goods_id' => $params['goods_id']]);
- if (!$model) {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $params['mall_id'];
- $model->created_at = time();
- }else{
- if($params['order_num']) {
- $model->order_num = $model->order_num + $params['order_num'];
- unset($params['order_num']);
- }
- if($params['total_amount']) {
- $model->total_amount = $model->total_amount + $params['total_amount'];
- unset($params['total_amount']);
- }
- if($params['bought_count']) {
- $model->bought_count = $model->bought_count + $params['bought_count'];
- unset($params['bought_count']);
- }
- if($params['goods_views_count']) {
- $model->goods_views_count = $model->goods_views_count + $params['goods_views_count'];
- unset($params['goods_views_count']);
- }
- $model->updated_at = time();
- }
- if(!$model->load($params,'') || !$model->save()){
- throw new Exception($model->getErrorMessage());
- }
- return $model;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|