| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\controller\merchant;
- use app\extra\basic\Base;
- use app\middleware\AuthMiddleware;
- use app\model\saas\SaasGoodsOff;
- use app\service\saas\GoodsOffService;
- use DI\Attribute\Inject;
- use LinFly\Annotation\Attributes\Route\Controller;
- use LinFly\Annotation\Attributes\Route\GetMapping;
- use LinFly\Annotation\Attributes\Route\Middleware;
- use LinFly\Annotation\Attributes\Route\PostMapping;
- use support\Request;
- use support\Response;
- #[Controller("/api/merchant/goodsoff"),Middleware(AuthMiddleware::class)]
- class GoodsOff extends Base
- {
- #[Inject]
- protected GoodsOffService $service;
- #[Inject]
- protected SaasGoodsOff $model;
- #[GetMapping('list')]
- public function getDataList(Request $request): Response
- {
- try {
- $param = $request->all();
- $param['poi_id'] = $request->user['store_id'];
- $param['is_deleted'] = 1;
- $data = $this->service->setModel()->getList($param,['store' => function($query){
- $query->field("poi_id,poi_name,poi_address,poi_city");
- },'goods' => function($query){
- $query->field("goods_id,image_list,product_name,price,line_price");
- }]);
- return successTrans("success.data",pageFormat($data),200);
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- #[PostMapping('save')]
- public function setDataDetail(Request $request): Response
- {
- try {
- [$state,$msg] = $this->checkDeposit($request->user['store_id']);
- if (!$state) return error($msg);
- $param = $request->all();
- $param['poi_id'] = $request->user['store_id'];
- $state = $this->model->setAutoData($param);
- if (!$state) return errorTrans("error.data");
- return successTrans("success.data");
- } catch (\Throwable $th) {
- return error($th->getMessage());
- }
- }
- #[PostMapping("del")]
- public function delGoods(Request $request): Response
- {
- try {
- $param = $this->_valid([
- "id.require" => trans("empty.require"),
- ],$request->method());
- if (!is_array($param)) return error($param);
- $detail = $this->model->where("id",$param["id"])->findOrEmpty();
- if ($detail->isEmpty()) return errorTrans("empty.data");
- if ($detail['poi_id'] <> $request->user['store_id']) return error("非法操作");
- $detail->is_deleted = 0;
- $state = $detail->save();
- if (!$state) return errorTrans("error.data");
- return successTrans("success.data");
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- }
|