visible([ 'id','goods_image','goods_video', 'goods_number','good_unit','base_service_fee', 'service_total','service_fee','service_image','fee_schedule','warranty_period' ])->select()->toArray(); return $goods; } public static function getHotData() { return Goods::where('is_hot', '=', 1) ->with('goodsCategory') ->visible(['id','goods_name','goods_category_id','goods_image','goods_video','goodsCategory']) ->order(['top_weight' => 'desc', 'id' => 'desc']) ->select()->toArray(); } public static function sync(array $params,int $userId): bool { Db::startTrans(); try { if(isset($params['id'])){ $model = Goods::findOrEmpty($params['id']); if($model->isEmpty()){ throw new \Exception('数据异常'); } } else{ $model = new Goods(); } $model->goods_category_id = end($params['goods_category_ids']); $model->category_type = GoodsCategory::where('id', end($params['goods_category_ids']))->value('category_type'); $model->goods_category_ids = $params['goods_category_ids']; $model->goods_category_id = $params['goods_category_id']; $model->goods_name = $params['goods_name']; $model->goods_image = $params['goods_image']; $model->goods_video = $params['goods_video']; $model->goods_number = $params['goods_number']; $model->good_unit = $params['good_unit']; $model->goods_size = $params['goods_size']; $model->goods_type = $params['goods_type']; $model->goods_brand = $params['goods_brand']; $model->install_guide = $params['install_guide']; $model->goods_payment_type = $params['goods_payment_type']; $model->base_service_fee = $params['base_service_fee']; $model->service_total = $params['service_total']; $model->service_fee = $params['service_fee']; $model->service_image = $params['service_image']; $model->warranty_period = $params['warranty_period']; $model->fee_schedule = $params['fee_schedule']; $model->goods_status = $params['goods_status']; $model->is_recommend = $params['is_recommend'] ?:0; $model->recommend_weight = $params['recommend_weight'] ?:0; $model->is_top = $params['is_top'] ?:0; $model->top_weight = $params['top_weight'] ?:0; $model->is_hot = $params['is_hot'] ?:0; $model->hot_weight = $params['hot_weight'] ?:0; $model->user_id = $userId; $model->save(); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } }