Store.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * 店铺API
  4. */
  5. namespace app\ais\controller\api\v1;
  6. use app\ais\controller\api\Base;
  7. use app\ais\model\AisStore;
  8. use app\ais\model\AisStoreCate;
  9. use app\ais\model\AisCoupon;
  10. use app\ais\model\AisShop;
  11. use think\helper\Time;
  12. use filter\Filter;
  13. class Store extends Base{
  14. /**
  15. * 读取行业信息列表 v4.1
  16. * @param integer 读取ID
  17. * @return json
  18. */
  19. public function cate(){
  20. $param['cate_id'] = $this->request->param('cate_id/d',0);
  21. $this->apiSign($param);
  22. $where['parent_id'] = $param['cate_id'];
  23. $where['member_miniapp_id'] = $this->miniapp_id;
  24. $data = AisStoreCate::where($where)->field('id,name,picture,title')->order('sort desc,id desc')->select();
  25. if($data->isEmpty()){
  26. return enjson(204);
  27. }
  28. return enjson(200,$data);
  29. }
  30. /**
  31. * 店铺列表
  32. */
  33. public function index(){
  34. $param['keyword'] = $this->request->param('keyword');
  35. $param['cate_id'] = $this->request->param('cate_id',0);
  36. $param['cate_sid'] = $this->request->param('cate_sid/d',0);
  37. $param['page'] = $this->request->param('page/d',0);
  38. $param['citycode'] = $this->request->param('citycode/d');
  39. $this->apiSign($param);
  40. $where = [];
  41. if($param['cate_sid']){
  42. $where[] = ['cate_sid','=',$param['cate_sid']];
  43. }
  44. if($param['cate_id']){
  45. $where[] = ['cate_id','=',$param['cate_id']];
  46. }
  47. $where[] = ['member_miniapp_id','=',$this->miniapp_id];
  48. $where[] = ['is_lock','=',0];
  49. if($param['citycode']){
  50. $where[] = ['citycode','=',$param['citycode']];
  51. }
  52. $rel = AisStore::where($where)->withSearch(['name'],['name' => $param['keyword']])
  53. ->field('id,name,longitude,latitude,img,telphone,address,tags,is_top')
  54. ->order('is_top desc,sort desc,id desc')->page($param['page'],10)->select();
  55. if($rel->isEmpty()){
  56. return enjson(204,'没有内容');
  57. }
  58. return enjson(200,$rel);
  59. }
  60. /**
  61. * 店铺首页产品
  62. */
  63. public function read(){
  64. $param['store_id'] = $this->request->param('store_id/d',0);
  65. $this->apiSign($param);
  66. $info = AisStore::with(['chain'])->where(['id' => $param['store_id'],'is_lock' => 0])->field('id,name,longitude,latitude,img,telphone,address,tags,is_top,likes')->find();
  67. if(empty($info)){
  68. return enjson(404);
  69. }
  70. return enjson(200,$info);
  71. }
  72. /**
  73. * 点赞
  74. **/
  75. public function like(){
  76. $this->isUserAuth();
  77. $param['store_id'] = $this->request->param('store_id/d',0);
  78. $this->apiSign($param);
  79. $rel = AisStore::where(['id' => $param['store_id']])->setInc('likes',1);
  80. if(empty($rel)){
  81. return enjson(204);
  82. }
  83. return enjson(200);
  84. }
  85. /**
  86. * 申请入驻商家
  87. */
  88. public function reg(){
  89. $this->isUserAuth();
  90. if (request()->isPost()) {
  91. $param = [
  92. 'name' => $this->request->param('name/s'),
  93. 'address' => $this->request->param('address/s'),
  94. 'telphone' => $this->request->param('telphone/s'),
  95. 'latitude' => $this->request->param('latitude/s'),
  96. 'longitude' => $this->request->param('longitude/s'),
  97. 'charge' => $this->request->param('charge/d',10),
  98. 'citypath' => $this->request->param('citypath/s','[]','htmlspecialchars_decode'),
  99. 'imgs' => $this->request->param('imgs/s','[]','htmlspecialchars_decode'),
  100. ];
  101. $this->apiSign($param);
  102. $validate = $this->validate($param,'Store.reg');
  103. if(true !== $validate){
  104. return enjson(403,$validate);
  105. }
  106. //判断是否入驻
  107. $store = AisStore::manageStore($this->user->id);
  108. if($store){
  109. return enjson(403,'不需要重复入驻');
  110. }
  111. //所在城市
  112. $citypath = Filter::filter_escape(json_decode($param['citypath'],true));
  113. if(empty($citypath)){
  114. return enjson(403,'城市选择失败,请重新选择');
  115. }
  116. $imgs = Filter::filter_escape(json_decode($param['imgs'],true));
  117. if(empty($imgs)){
  118. return enjson(403,'请重新选择Logo');
  119. }
  120. $data['citycode'] = $citypath[2]['code'];
  121. $data['citypath'] = ['province' => $citypath[0]['code'],'city' => $citypath[1]['code'],'district' => $citypath[2]['code']];
  122. $data['member_miniapp_id'] = $this->miniapp_id;
  123. $data['manage_uid'] = $this->user->id;
  124. $data['name'] = $param['name'];
  125. $data['telphone'] = $param['telphone'];
  126. $data['address'] = $param['address'];
  127. $data['latitude'] = $param['latitude'];
  128. $data['longitude'] = $param['longitude'];
  129. $data['img'] = $imgs[0];
  130. $data['charge'] = $param['charge'];;
  131. if(AisStore::create($data)){
  132. return enjson(200,"成功,下一步申请微信商户号");
  133. }
  134. return enjson(403,"提交失败");
  135. }
  136. }
  137. }