Goods.php 1.8 KB

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