|
@@ -6,6 +6,8 @@ use App\Model\ArticleData;
|
|
|
use App\Model\Category;
|
|
|
use App\Model\WebsiteCategory;
|
|
|
use App\Model\ArticleSurvey;
|
|
|
+use App\Model\Good;
|
|
|
+
|
|
|
use Hyperf\DbConnection\Db;
|
|
|
use Hyperf\RpcServer\Annotation\RpcService;
|
|
|
use App\Tools\Result;
|
|
@@ -552,4 +554,88 @@ class NewsService implements NewsServiceInterface
|
|
|
return Result::success($result);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ //20250226 产品列表
|
|
|
+
|
|
|
+ public function getGoodList(array $data): array
|
|
|
+ {
|
|
|
+ $where = [];
|
|
|
+ //类型
|
|
|
+ if (isset($data['type_id']) && $data['type_id']) {
|
|
|
+ $where = [
|
|
|
+ 'type_id' => $data['type_id'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ //名称
|
|
|
+ if (isset($data['name']) && $data['name']) {
|
|
|
+ $where = [
|
|
|
+ 'name' => $data['name'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ //website_id
|
|
|
+ if (isset($data['website_id']) && $data['website_id']) {
|
|
|
+ $where = [
|
|
|
+ 'website_id' => $data['website_id'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ //catid
|
|
|
+ if (isset($data['catid']) && $data['catid']) {
|
|
|
+ $where = [
|
|
|
+ 'catid' => $data['catid'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // $result = Good::where($where)
|
|
|
+ // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
|
|
|
+ $result = Good::where($where)
|
|
|
+ ->orderBy("updated_at", "desc")
|
|
|
+ ->limit($data['page_size'])
|
|
|
+ ->offset(($data['page'] - 1) * $data['page_size'])
|
|
|
+ ->get();
|
|
|
+ $count = Good::where($where)->count();
|
|
|
+ $data = [
|
|
|
+ 'rows' => $result->toArray(),
|
|
|
+ 'count' => $count,
|
|
|
+ ];
|
|
|
+
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("此栏目暂无相关产品", 0);
|
|
|
+ }
|
|
|
+ return Result::success($data);
|
|
|
+ }
|
|
|
+ public function getGoodInfo(array $data): array
|
|
|
+ {
|
|
|
+ $result = Good::where('id', $data['id'])->first();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("此产品不存在", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ public function addGood(array $data): array
|
|
|
+ {
|
|
|
+
|
|
|
+ $result = Good::create($data);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("添加失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ public function updateGood(array $data): array
|
|
|
+ {
|
|
|
+ $result = Good::where('id', $data['id'])->update($data);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("更新失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ public function delGood(array $data): array
|
|
|
+ {
|
|
|
+ $result = Good::where('id', $data['id'])->delete();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("删除失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ //20250226 产品列表
|
|
|
}
|