Goods.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\data\controller\api;
  3. use app\data\service\GoodsService;
  4. use app\data\service\TruckService;
  5. use think\admin\Controller;
  6. /**
  7. * 商品数据接口
  8. * Class Goods
  9. * @package app\data\controller\api
  10. */
  11. class Goods extends Controller
  12. {
  13. /**
  14. * 获取分类数据
  15. * @throws \think\db\exception\DataNotFoundException
  16. * @throws \think\db\exception\DbException
  17. * @throws \think\db\exception\ModelNotFoundException
  18. */
  19. public function getCate()
  20. {
  21. $this->success('获取分类成功', GoodsService::instance()->getCateList());
  22. }
  23. /**
  24. * 获取标签数据
  25. */
  26. public function getMark()
  27. {
  28. $this->success('获取标签成功', GoodsService::instance()->getMarkList());
  29. }
  30. /**
  31. * 获取商品数据
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\DbException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. */
  36. public function getGoods()
  37. {
  38. if ($code = input('code', '')) {
  39. $this->app->db->name('ShopGoods')->where(['code' => $code])->update([
  40. 'num_read' => $this->app->db->raw('num_read+1'),
  41. ]);
  42. }
  43. $map = ['deleted' => 0, 'status' => 1];
  44. $query = $this->_query('ShopGoods')->like('name,mark')->equal('code,cate');
  45. $result = $query->where($map)->order('sort desc,id desc')->page(true, false, false, 10);
  46. GoodsService::instance()->buildItemData($result['list']);
  47. $this->success('获取商品成功', $result);
  48. }
  49. /**
  50. * 获取配送区域
  51. */
  52. public function getRegion()
  53. {
  54. $this->success('获取区域成功', TruckService::instance()->region(3, 1));
  55. }
  56. }