PublicController.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\model\system\SystemAttachment;
  4. use app\models\store\StoreCategory;
  5. use app\models\store\StoreCouponIssue;
  6. use app\models\store\StoreProduct;
  7. use app\models\store\StoreService;
  8. use app\models\system\Express;
  9. use app\models\user\UserBill;
  10. use app\Request;
  11. use crmeb\services\GroupDataService;
  12. use crmeb\services\SystemConfigService;
  13. use crmeb\services\UploadService;
  14. use crmeb\services\UtilService;
  15. use crmeb\services\workerman\ChannelService;
  16. use think\facade\Cache;
  17. /**
  18. * 公共类
  19. * Class PublicController
  20. * @package app\api\controller
  21. */
  22. class PublicController
  23. {
  24. /**
  25. * @param Request $request
  26. * @return mixed
  27. * @throws \think\db\exception\DataNotFoundException
  28. * @throws \think\db\exception\ModelNotFoundException
  29. * @throws \think\exception\DbException
  30. */
  31. public function index(Request $request)
  32. {
  33. $banner = GroupDataService::getData('routine_home_banner') ?: [];//TODO 首页banner图
  34. $menus = GroupDataService::getData('routine_home_menus') ?: [];//TODO 首页按钮
  35. $roll = GroupDataService::getData('routine_home_roll_news') ?: [];//TODO 首页滚动新闻
  36. $activity = GroupDataService::getData('routine_home_activity', 3) ?: [];//TODO 首页活动区域图片
  37. $site_name = SystemConfigService::get('site_name');
  38. $routine_index_page = GroupDataService::getData('routine_index_page');
  39. $info['fastInfo'] = $routine_index_page[0]['fast_info'] ?? '';//SystemConfigService::get('fast_info');//TODO 快速选择简介
  40. $info['bastInfo'] = $routine_index_page[0]['bast_info'] ?? '';//SystemConfigService::get('bast_info');//TODO 精品推荐简介
  41. $info['firstInfo'] = $routine_index_page[0]['first_info'] ?? '';//SystemConfigService::get('first_info');//TODO 首发新品简介
  42. $info['salesInfo'] = $routine_index_page[0]['sales_info'] ?? '';//SystemConfigService::get('sales_info');//TODO 促销单品简介
  43. $logoUrl = SystemConfigService::get('routine_index_logo');//TODO 促销单品简介
  44. if (strstr($logoUrl, 'http') === false) $logoUrl = SystemConfigService::get('site_url') . $logoUrl;
  45. $logoUrl = str_replace('\\', '/', $logoUrl);
  46. $fastNumber = $routine_index_page[0]['fast_number'] ?? 6;//SystemConfigService::get('fast_number');//TODO 快速选择分类个数
  47. $bastNumber = $routine_index_page[0]['bast_number'] ?? 6;//SystemConfigService::get('bast_number');//TODO 精品推荐个数
  48. $firstNumber = $routine_index_page[0]['first_number'] ?? 6;//SystemConfigService::get('first_number');//TODO 首发新品个数
  49. $info['fastList'] = StoreCategory::byIndexList((int)$fastNumber);//TODO 快速选择分类个数
  50. $info['bastList'] = StoreProduct::getBestProduct('id,image,store_name,cate_id,price,ot_price,IFNULL(sales,0) + IFNULL(ficti,0) as sales,unit_name', (int)$bastNumber, $request->uid());//TODO 精品推荐个数
  51. $info['firstList'] = StoreProduct::getNewProduct('id,image,store_name,cate_id,price,unit_name,IFNULL(sales,0) + IFNULL(ficti,0) as sales', (int)$firstNumber,$request->uid());//TODO 首发新品个数
  52. $info['bastBanner'] = GroupDataService::getData('routine_home_bast_banner') ?? [];//TODO 首页精品推荐图片
  53. $benefit = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name', 3);//TODO 首页促销单品
  54. $lovely = GroupDataService::getData('routine_home_new_banner') ?: [];//TODO 首发新品顶部图
  55. $likeInfo = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,unit_name', 3);//TODO 热门榜单 猜你喜欢
  56. $couponList = StoreCouponIssue::getIssueCouponList($request->uid(), 3);
  57. return app('json')->successful(compact('banner', 'menus', 'roll', 'info', 'activity', 'lovely', 'benefit', 'likeInfo', 'logoUrl', 'couponList','site_name'));
  58. }
  59. /**
  60. * 获取分享配置
  61. * @return mixed
  62. */
  63. public function share()
  64. {
  65. $data['img'] = SystemConfigService::get('wechat_share_img');
  66. if (strstr($data['img'], 'http') === false) $data['img'] = SystemConfigService::get('site_url') . $data['img'];
  67. $data['img'] = str_replace('\\', '/', $data['img']);
  68. $data['title'] = SystemConfigService::get('wechat_share_title');
  69. $data['synopsis'] = SystemConfigService::get('wechat_share_synopsis');
  70. return app('json')->successful(compact('data'));
  71. }
  72. /**
  73. * 获取个人中心菜单
  74. * @param Request $request
  75. * @return mixed
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\ModelNotFoundException
  78. * @throws \think\exception\DbException
  79. */
  80. public function menu_user(Request $request)
  81. {
  82. $menusInfo = GroupDataService::getData('routine_my_menus') ?? [];
  83. $user = $request->user();
  84. foreach ($menusInfo as $key=>&$value){
  85. $value['pic'] = UtilService::setSiteUrl($value['pic']);
  86. if($value['id'] == 137 && !(intval(SystemConfigService::get('store_brokerage_statu')) == 2 || $user->is_promoter == 1))
  87. unset($menusInfo[$key]);
  88. if($value['id'] == 174 && !StoreService::orderServiceStatus($user->uid))
  89. unset($menusInfo[$key]);
  90. }
  91. return app('json')->successful(['routine_my_menus'=>$menusInfo]);
  92. }
  93. /**
  94. * 热门搜索关键字获取
  95. * @return mixed
  96. * @throws \think\db\exception\DataNotFoundException
  97. * @throws \think\db\exception\ModelNotFoundException
  98. * @throws \think\exception\DbException
  99. */
  100. public function search()
  101. {
  102. $routineHotSearch = GroupDataService::getData('routine_hot_search') ?? [];
  103. $searchKeyword = [];
  104. if(count($routineHotSearch)){
  105. foreach ($routineHotSearch as $key=>&$item){
  106. array_push($searchKeyword, $item['title']);
  107. }
  108. }
  109. return app('json')->successful($searchKeyword);
  110. }
  111. /**
  112. * 图片上传
  113. * @param Request $request
  114. * @return mixed
  115. * @throws \Psr\SimpleCache\InvalidArgumentException
  116. */
  117. public function upload_image(Request $request)
  118. {
  119. $data = UtilService::postMore([
  120. ['filename','file'],
  121. ],$request);
  122. if(!$data['filename']) return app('json')->fail('参数有误');
  123. if(Cache::has('start_uploads_'.$request->uid()) && Cache::get('start_uploads_'.$request->uid()) >= 100) return app('json')->fail('非法操作');
  124. $res = UploadService::image($data['filename'],'store/comment');
  125. if(!is_array($res)) return app('json')->fail($res);
  126. SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'],1, $res['image_type'], $res['time'], 2);
  127. if(Cache::has('start_uploads_'.$request->uid()))
  128. $start_uploads=(int)Cache::get('start_uploads_'.$request->uid());
  129. else
  130. $start_uploads = 0;
  131. $start_uploads++;
  132. Cache::set('start_uploads_'.$request->uid(),$start_uploads,86400);
  133. $res['dir'] = UploadService::pathToUrl($res['dir']);
  134. if(strpos($res['dir'],'http') === false) $res['dir'] = $request->domain().$res['dir'];
  135. return app('json')->successful('图片上传成功!', ['name' => $res['name'], 'url' => $res['dir']]);
  136. }
  137. /**
  138. * 物流公司
  139. * @return mixed
  140. */
  141. public function logistics()
  142. {
  143. $expressList = Express::lst();
  144. if(!$expressList) return app('json')->successful([]);
  145. return app('json')->successful($expressList->hidden(['code', 'id', 'sort', 'is_show'])->toArray());
  146. }
  147. /**
  148. * 短信购买异步通知
  149. *
  150. * @param Request $request
  151. * @return mixed
  152. */
  153. public function sms_pay_notify(Request $request)
  154. {
  155. list($order_id, $price, $status, $num, $pay_time, $attach) = UtilService::postMore([
  156. ['order_id', ''],
  157. ['price', 0.00],
  158. ['status', 400],
  159. ['num', 0],
  160. ['pay_time', time()],
  161. ['attach', 0],
  162. ], $request, true);
  163. if($status == 200){
  164. ChannelService::instance()->send('PAY_SMS_SUCCESS', ['price'=> $price, 'number'=> $num], [$attach]);
  165. return app('json')->successful();
  166. }
  167. return app('json')->fail();
  168. }
  169. /*
  170. * 记录用户分享
  171. * @return json
  172. * */
  173. public function user_share(Request $request){
  174. return app('json')->successful(UserBill::setUserShare($request->uid));
  175. }
  176. }