'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; } } }