PublicApi.php 13 KB

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