Product.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller\v1;
  4. use app\BaseController;
  5. use app\model\admin\Product as ProductModel;
  6. use app\model\admin\SiteProduct;
  7. use app\Request;
  8. use library\services\UtilService;
  9. // +----------------------------------------------------------------------
  10. // | [ WE CAN DO IT MORE SIMPLE ]
  11. // +----------------------------------------------------------------------
  12. // | Copyright (c) 2018-2020 rights reserved.
  13. // +----------------------------------------------------------------------
  14. // | Author: TABLE ME
  15. // +----------------------------------------------------------------------
  16. // | Date: 2020-09-06 21:53
  17. // +----------------------------------------------------------------------
  18. class Product extends BaseController
  19. {
  20. /**
  21. * 基本设置
  22. */
  23. public function list(Request $request) {
  24. $pageSize = 20;
  25. $post = UtilService::getMore([
  26. ['page',1],
  27. ['warehouse',0],
  28. ['name',''],
  29. ['artType','all']
  30. ],$request);
  31. $sassid = $request->site['sassid'];
  32. $siteProduct = new SiteProduct;
  33. $siteProduct->setSassId($sassid);
  34. list($pageCount,$data) = $siteProduct->getList($post['page'],$post,$pageSize);
  35. $totalCount['count'] = $siteProduct->where('sassid',$sassid)->count();
  36. $totalCount['downCount'] = $siteProduct->where('sassid',$sassid)->where('status',0)->count();
  37. $totalCount['upCount'] = $siteProduct->where('sassid',$sassid)->where('status',1)->count();
  38. return app('json')->success([
  39. 'list' => $data,
  40. 'pageCount' => $pageCount,
  41. 'pageSize' => $pageSize,
  42. 'page' => $post['page'],
  43. 'totalCount'=>$totalCount
  44. ]);
  45. }
  46. /**
  47. * 保存数据
  48. * @param Request $request
  49. */
  50. public function save(Request $request) {
  51. $post = UtilService::getMore([
  52. ['id',0],
  53. ['is_host',0],
  54. ['is_new',0],
  55. ['status',''],
  56. ['ver_bug_count',0],
  57. ['price',0]
  58. ],$request);
  59. $post["status"]=$post["status"]==1?1:0;
  60. $sassid = $request->site['sassid'];
  61. $siteProduct = new SiteProduct;
  62. $siteProduct->setSassId($sassid);
  63. $bool = $siteProduct->saveProduct($post);
  64. if(!$bool) {
  65. return app('json')->fail(SiteProduct::getErrorInfo());
  66. }
  67. return app('json')->success("数据保存成功");
  68. }
  69. /**
  70. * 获取产品基本信息
  71. * @param Request $request
  72. */
  73. public function info(Request $request) {
  74. [$id] = UtilService::getMore([
  75. ['id','','empty','参数错误']
  76. ],$request,true);
  77. $sassid = $request->site['sassid'];
  78. $siteProduct = new SiteProduct;
  79. $siteProduct->setSassId($sassid);
  80. $info = $siteProduct->getProInfo(compact('id'));
  81. return app('json')->success($info);
  82. }
  83. }