GoodsOff.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\controller\merchant;
  3. use app\extra\basic\Base;
  4. use app\middleware\AuthMiddleware;
  5. use app\model\saas\SaasGoodsOff;
  6. use app\service\saas\GoodsOffService;
  7. use DI\Attribute\Inject;
  8. use LinFly\Annotation\Attributes\Route\Controller;
  9. use LinFly\Annotation\Attributes\Route\GetMapping;
  10. use LinFly\Annotation\Attributes\Route\Middleware;
  11. use LinFly\Annotation\Attributes\Route\PostMapping;
  12. use support\Request;
  13. use support\Response;
  14. #[Controller("/api/merchant/goodsoff"),Middleware(AuthMiddleware::class)]
  15. class GoodsOff extends Base
  16. {
  17. #[Inject]
  18. protected GoodsOffService $service;
  19. #[Inject]
  20. protected SaasGoodsOff $model;
  21. #[GetMapping('list')]
  22. public function getDataList(Request $request): Response
  23. {
  24. try {
  25. $param = $request->all();
  26. $param['poi_id'] = $request->user['store_id'];
  27. $param['is_deleted'] = 1;
  28. $data = $this->service->setModel()->getList($param,['store' => function($query){
  29. $query->field("poi_id,poi_name,poi_address,poi_city");
  30. },'goods' => function($query){
  31. $query->field("goods_id,image_list,product_name,price,line_price,is_new");
  32. }]);
  33. return successTrans("success.data",pageFormat($data),200);
  34. } catch (\Throwable $throwable) {
  35. return error($throwable->getMessage());
  36. }
  37. }
  38. #[PostMapping('save')]
  39. public function setDataDetail(Request $request): Response
  40. {
  41. try {
  42. [$state,$msg] = $this->checkDeposit($request->user['store_id']);
  43. if (!$state) return error($msg);
  44. $param = $request->all();
  45. $param['poi_id'] = $request->user['store_id'];
  46. $state = $this->model->setAutoData($param);
  47. if (!$state) return errorTrans("error.data");
  48. return successTrans("success.data");
  49. } catch (\Throwable $th) {
  50. return error($th->getMessage());
  51. }
  52. }
  53. #[PostMapping("del")]
  54. public function delGoods(Request $request): Response
  55. {
  56. try {
  57. $param = $this->_valid([
  58. "id.require" => trans("empty.require"),
  59. ],$request->method());
  60. if (!is_array($param)) return error($param);
  61. $detail = $this->model->where("id",$param["id"])->findOrEmpty();
  62. if ($detail->isEmpty()) return errorTrans("empty.data");
  63. if ($detail['poi_id'] <> $request->user['store_id']) return error("非法操作");
  64. $detail->is_deleted = 0;
  65. $state = $detail->save();
  66. if (!$state) return errorTrans("error.data");
  67. return successTrans("success.data");
  68. } catch (\Throwable $throwable) {
  69. return error($throwable->getMessage());
  70. }
  71. }
  72. }