Goods.php 1.8 KB

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