PublicApi.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <?php
  2. namespace app\ebapi\controller;
  3. use app\core\model\user\UserBill;
  4. use app\core\model\system\SystemUserLevel;
  5. use app\core\model\system\SystemUserTask;
  6. use app\core\model\user\UserLevel;
  7. use app\ebapi\model\store\StoreCategory;
  8. use app\core\model\routine\RoutineFormId;//待完善
  9. use app\ebapi\model\store\StoreCouponIssue;
  10. use app\ebapi\model\store\StoreProduct;
  11. use app\core\util\GroupDataService;
  12. use service\HttpService;
  13. use service\JsonService;
  14. use app\core\util\SystemConfigService;
  15. use service\UploadService;
  16. use service\UtilService;
  17. use service\CacheService;
  18. use think\Cache;
  19. /**
  20. * 小程序公共接口
  21. * Class PublicApi
  22. * @package app\ebapi\controller
  23. *
  24. */
  25. class PublicApi extends AuthController
  26. {
  27. /*
  28. * 白名单不验证token 如果传入token执行验证获取信息,没有获取到用户信息
  29. * */
  30. public static function whiteList()
  31. {
  32. return [
  33. 'index',
  34. 'get_index_groom_list',
  35. 'get_hot_product',
  36. 'refresh_cache',
  37. 'clear_cache',
  38. 'get_logo_url',
  39. 'get_my_naviga',
  40. ];
  41. }
  42. /*
  43. * 获取个人中心菜单
  44. * */
  45. public function get_my_naviga()
  46. {
  47. return JsonService::successful(['routine_my_menus'=>GroupDataService::getData('routine_my_menus')]);
  48. }
  49. /*
  50. * 获取授权登录log
  51. * */
  52. public function get_logo_url()
  53. {
  54. $routine_logo=SystemConfigService::get('routine_logo');
  55. return JsonService::successful(['logo_url'=>str_replace('\\','/',$routine_logo)]);
  56. }
  57. /**
  58. * TODO 获取首页推荐不同类型产品的轮播图和产品
  59. * @param int $type
  60. */
  61. public function get_index_groom_list($type = 1){
  62. $info['banner'] = [];
  63. $info['list'] = [];
  64. if($type == 1){//TODO 精品推荐
  65. $info['banner'] = GroupDataService::getData('routine_home_bast_banner')?:[];//TODO 首页精品推荐图片
  66. $info['list'] = StoreProduct::getBestProduct('id,image,store_name,cate_id,price,ot_price,IFNULL(sales,0) + IFNULL(ficti,0) as sales,unit_name,sort');//TODO 精品推荐个数
  67. }else if($type == 2){//TODO 热门榜单
  68. $info['banner'] = GroupDataService::getData('routine_home_hot_banner')?:[];//TODO 热门榜单 猜你喜欢推荐图片
  69. $info['list'] = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,ot_price,unit_name,sort,IFNULL(sales,0) + IFNULL(ficti,0) as sales',0,$this->uid);//TODO 热门榜单 猜你喜欢
  70. }else if($type == 3){//TODO 首发新品
  71. $info['banner'] = GroupDataService::getData('routine_home_new_banner')?:[];//TODO 首发新品推荐图片
  72. $info['list'] = StoreProduct::getNewProduct('id,image,store_name,cate_id,price,ot_price,unit_name,sort,IFNULL(sales,0) + IFNULL(ficti,0) as sales',0,$this->uid);//TODO 首发新品
  73. }else if($type == 4){//TODO 促销单品
  74. $info['banner'] = GroupDataService::getData('routine_home_benefit_banner')?:[];//TODO 促销单品推荐图片
  75. $info['list'] = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name,sort');//TODO 促销单品
  76. }
  77. return JsonService::successful($info);
  78. }
  79. /**
  80. * 首页
  81. */
  82. public function index(){
  83. $banner = GroupDataService::getData('routine_home_banner')?:[];//TODO 首页banner图
  84. $menus = GroupDataService::getData('routine_home_menus')?:[];//TODO 首页按钮
  85. $roll = GroupDataService::getData('routine_home_roll_news')?:[];//TODO 首页滚动新闻
  86. $activity = GroupDataService::getData('routine_home_activity',3)?:[];//TODO 首页活动区域图片
  87. $info['fastInfo'] = SystemConfigService::get('fast_info');//TODO 快速选择简介
  88. $info['bastInfo'] = SystemConfigService::get('bast_info');//TODO 精品推荐简介
  89. $info['firstInfo'] = SystemConfigService::get('first_info');//TODO 首发新品简介
  90. $info['salesInfo'] = SystemConfigService::get('sales_info');//TODO 促销单品简介
  91. $logoUrl = SystemConfigService::get('routine_index_logo');//TODO 促销单品简介
  92. if(strstr($logoUrl,'http')===false) $logoUrl=SystemConfigService::get('site_url').$logoUrl;
  93. $logoUrl=str_replace('\\','/',$logoUrl);
  94. $fastNumber = (int)SystemConfigService::get('fast_number');//TODO 快速选择分类个数
  95. $bastNumber = (int)SystemConfigService::get('bast_number');//TODO 精品推荐个数
  96. $firstNumber = (int)SystemConfigService::get('first_number');//TODO 首发新品个数
  97. $info['fastList'] = StoreCategory::byIndexList($fastNumber);//TODO 快速选择分类个数
  98. $info['bastList'] = StoreProduct::getBestProduct('id,image,store_name,cate_id,price,ot_price,IFNULL(sales,0) + IFNULL(ficti,0) as sales,unit_name,sort',$bastNumber,$this->uid);//TODO 精品推荐个数
  99. $info['firstList'] = StoreProduct::getNewProduct('id,image,store_name,cate_id,price,unit_name,sort',$firstNumber);//TODO 首发新品个数
  100. $info['bastBanner'] = GroupDataService::getData('routine_home_bast_banner')?:[];//TODO 首页精品推荐图片
  101. $benefit = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name,sort',3);//TODO 首页促销单品
  102. $lovely =[];//TODO 首发新品顶部图
  103. $likeInfo = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,unit_name,sort',3);//TODO 热门榜单 猜你喜欢
  104. $couponList=StoreCouponIssue::getIssueCouponList($this->uid,3);
  105. return $this->successful(compact('banner','menus','roll','info','activity','lovely','benefit','likeInfo','logoUrl','couponList'));
  106. }
  107. /**
  108. * 猜你喜欢 加载
  109. * @param Request $request
  110. */
  111. public function get_hot_product(){
  112. $data = UtilService::getMore([['offset',0],['limit',0]],$this->request);
  113. $hot = StoreProduct::getHotProductLoading('id,image,store_name,cate_id,price,unit_name,sort',$data['offset'],$data['limit']);//猜你喜欢
  114. return $this->successful($hot);
  115. }
  116. /*
  117. * 根据经纬度获取当前地理位置
  118. * */
  119. public function getlocation($latitude='',$longitude=''){
  120. $location=HttpService::getRequest('https://apis.map.qq.com/ws/geocoder/v1/',
  121. ['location'=>$latitude.','.$longitude,'key'=>'U65BZ-F2IHX-CGZ4I-73I7L-M6FZF-TEFCH']);
  122. $location=$location ? json_decode($location,true) : [];
  123. if($location && isset($location['result']['address'])){
  124. try{
  125. $address=$location['result']['address_component']['street'];
  126. return $this->successful(['address'=>$address]);
  127. }catch (\Exception $e){
  128. return $this->fail('获取位置信息失败!');
  129. }
  130. }else{
  131. return $this->fail('获取位置信息失败!');
  132. }
  133. }
  134. /*
  135. * 根据key来取系统的值
  136. * */
  137. public function get_system_config_value($name=''){
  138. if($name=='') return JsonService::fail('缺少参数');
  139. $name=str_replace(SystemConfigService::$ProtectedKey,'',$name);
  140. if(strstr($name,',')!==false){
  141. return $this->successful(SystemConfigService::more($name));
  142. }else{
  143. $value=SystemConfigService::get($name);
  144. $value=is_array($value) ? $value[0] : $value;
  145. return $this->successful([$name=>$value]);
  146. }
  147. }
  148. /*
  149. * 获取系统
  150. * */
  151. public function get_system_group_data_value($name='',$multi=0){
  152. if($name=='') return $this->successful([$name=>[]]);
  153. if($multi==1){
  154. $name=json_decode($name,true);
  155. $value=[];
  156. foreach ($name as $item){
  157. $value[$item]=GroupDataService::getData($item)?:[];
  158. }
  159. return $this->successful($value);
  160. }else{
  161. $value= GroupDataService::getData($name)?:[];
  162. return $this->successful([$name=>$value]);
  163. }
  164. }
  165. /*
  166. * 删除指定资源
  167. *
  168. * */
  169. public function delete_image(){
  170. $post=UtilService::postMore([
  171. ['pic',''],
  172. ]);
  173. if($post['pic']=='') return $this->fail('缺少删除资源');
  174. $type=['php','js','css','html','ttf','otf'];
  175. $post['pic']=substr($post['pic'],1);
  176. $ext=substr($post['pic'],-3);
  177. if(in_array($ext,$type)) return $this->fail('非法操作');
  178. if(strstr($post['pic'],'uploads')===false) return $this->fail('非法操作');
  179. try{
  180. if(file_exists($post['pic'])) unlink($post['pic']);
  181. if(strstr($post['pic'],'s_')!==false){
  182. $pic=str_replace(['s_'],'',$post['pic']);
  183. if(file_exists($pic)) unlink($pic);
  184. }
  185. return $this->successful('删除成功');
  186. }catch (\Exception $e){
  187. return $this->fail('刪除失败',['line'=>$e->getLine(),'message'=>$e->getMessage()]);
  188. }
  189. }
  190. /**
  191. * 上传图片
  192. * @param string $filename
  193. * @return \think\response\Json
  194. */
  195. public function upload($dir='')
  196. {
  197. $data = UtilService::postMore([
  198. ['filename',''],
  199. ],$this->request);
  200. if(Cache::has('start_uploads_'.$this->uid) && Cache::get('start_uploads_'.$this->uid) >= 100) return $this->fail('非法操作');
  201. $res = UploadService::image($data['filename'],$dir ? $dir: 'store/comment');
  202. if($res->status == 200){
  203. if(Cache::has('start_uploads_'.$this->uid))
  204. $start_uploads=(int)Cache::get('start_uploads_'.$this->uid);
  205. else
  206. $start_uploads=0;
  207. $start_uploads++;
  208. Cache::set('start_uploads_'.$this->uid,$start_uploads,86400);
  209. return $this->successful('图片上传成功!', ['name' => $res->fileInfo->getSaveName(), 'url' => UploadService::pathToUrl($res->dir)]);
  210. }else
  211. return $this->fail($res->error);
  212. }
  213. /**
  214. * 获取退款理由
  215. */
  216. public function get_refund_reason(){
  217. $reason = SystemConfigService::get('stor_reason')?:[];//退款理由
  218. $reason = str_replace("\r\n","\n",$reason);//防止不兼容
  219. $reason = explode("\n",$reason);
  220. return $this->successful($reason);
  221. }
  222. /**
  223. * 获取提现银行
  224. */
  225. public function get_user_extract_bank(){
  226. $extractBank = SystemConfigService::get('user_extract_bank')?:[];//提现银行
  227. $extractBank = str_replace("\r\n","\n",$extractBank);//防止不兼容
  228. $data['extractBank'] = explode("\n",$extractBank);
  229. $data['minPrice'] = SystemConfigService::get('user_extract_min_price');//提现最低金额
  230. return $this->successful($data);
  231. }
  232. /**
  233. * 收集发送模板信息的formID
  234. * @param string $formId
  235. */
  236. public function get_form_id($formId = ''){
  237. if($formId==''){
  238. list($formIds)=UtilService::postMore([
  239. ['formIds',[]]
  240. ],$this->request,true);
  241. foreach ($formIds as $formId){
  242. RoutineFormId::SetFormId($formId,$this->uid);
  243. }
  244. }else
  245. RoutineFormId::SetFormId($formId,$this->uid);
  246. return $this->successful('');
  247. }
  248. /**
  249. * 刷新数据缓存
  250. */
  251. public function refresh_cache(){
  252. `php think optimize:schema`;
  253. `php think optimize:autoload`;
  254. `php think optimize:route`;
  255. `php think optimize:config`;
  256. }
  257. /*
  258. * 清除系统全部缓存
  259. * @return
  260. * */
  261. public function clear_cache()
  262. {
  263. \think\Cache::clear();
  264. }
  265. /*
  266. * 获取会员等级
  267. * */
  268. public function get_level_list()
  269. {
  270. return JsonService::successful(SystemUserLevel::getLevelList($this->uid));
  271. }
  272. /*
  273. * 获取某个等级的任务
  274. * @param int $level_id 等级id
  275. * @return json
  276. * */
  277. public function get_task($level_id=''){
  278. return JsonService::successful(SystemUserTask::getTashList($level_id,$this->uid));
  279. }
  280. /*
  281. * 检测用户是否可以成为会员
  282. * */
  283. public function set_level_complete()
  284. {
  285. return JsonService::successful(UserLevel::setLevelComplete($this->uid));
  286. }
  287. /*
  288. * 记录用户分享次数
  289. * */
  290. public function set_user_share()
  291. {
  292. return JsonService::successful(UserBill::setUserShare($this->uid));
  293. }
  294. }