Goods.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\data\controller\api;
  3. use app\data\service\ExpressService;
  4. use app\data\service\GoodsService;
  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()->getCateTree());
  22. }
  23. /**
  24. * 获取标签数据
  25. */
  26. public function getMark()
  27. {
  28. $this->success('获取标签成功', GoodsService::instance()->getMarkData());
  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. // 更新访问统计
  39. $map = $this->_vali(['code.default' => '']);
  40. if ($map['code']) $this->app->db->name('ShopGoods')->where($map)->inc('num_read')->update();
  41. // 商品数据处理
  42. $query = $this->_query('ShopGoods')->like('name,marks,cateids,payment')->equal('code,vip_entry');
  43. $result = $query->where(['deleted' => 0, 'status' => 1])->order('sort desc,id desc')->page(true, false, false, 10);
  44. if (count($result['list']) > 0) GoodsService::instance()->bindData($result['list']);
  45. $this->success('获取商品数据', $result);
  46. }
  47. /**
  48. * 获取配送区域
  49. */
  50. public function getRegion()
  51. {
  52. $this->success('获取区域成功', ExpressService::instance()->region(3, 1));
  53. }
  54. }