PublicController.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 = sysConfig('site_name');
  38. $routine_index_page = GroupDataService::getData('routine_index_page');
  39. $info['fastInfo'] = $routine_index_page[0]['fast_info'] ?? '';//sysConfig('fast_info');//TODO 快速选择简介
  40. $info['bastInfo'] = $routine_index_page[0]['bast_info'] ?? '';//sysConfig('bast_info');//TODO 精品推荐简介
  41. $info['firstInfo'] = $routine_index_page[0]['first_info'] ?? '';//sysConfig('first_info');//TODO 首发新品简介
  42. $info['salesInfo'] = $routine_index_page[0]['sales_info'] ?? '';//sysConfig('sales_info');//TODO 促销单品简介
  43. $logoUrl = sysConfig('routine_index_logo');//TODO 促销单品简介
  44. if (strstr($logoUrl, 'http') === false) $logoUrl = sysConfig('site_url') . $logoUrl;
  45. $logoUrl = str_replace('\\', '/', $logoUrl);
  46. $fastNumber = $routine_index_page[0]['fast_number'] ?? 6;//sysConfig('fast_number');//TODO 快速选择分类个数
  47. $bastNumber = $routine_index_page[0]['bast_number'] ?? 6;//sysConfig('bast_number');//TODO 精品推荐个数
  48. $firstNumber = $routine_index_page[0]['first_number'] ?? 6;//sysConfig('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'] = sysConfig('wechat_share_img');
  66. if (strstr($data['img'], 'http') === false) $data['img'] = sysConfig('site_url') . $data['img'];
  67. $data['img'] = str_replace('\\', '/', $data['img']);
  68. $data['title'] = sysConfig('wechat_share_title');
  69. $data['synopsis'] = sysConfig('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. $vipOpen = sysConfig('vip_open');
  85. $vipOpen = is_string($vipOpen) ? (int)$vipOpen : $vipOpen;
  86. foreach ($menusInfo as $key=>&$value){
  87. $value['pic'] = UtilService::setSiteUrl($value['pic']);
  88. if($value['id'] == 137 && !(intval(sysConfig('store_brokerage_statu')) == 2 || $user->is_promoter == 1))
  89. unset($menusInfo[$key]);
  90. if($value['id'] == 174 && !StoreService::orderServiceStatus($user->uid))
  91. unset($menusInfo[$key]);
  92. if(!StoreService::orderServiceStatus($user->uid) && $value['wap_url'] === '/order/order_cancellation')
  93. unset($menusInfo[$key]);
  94. if($value['wap_url'] == '/user/vip' && !$vipOpen)
  95. unset($menusInfo[$key]);
  96. if($value['wap_url'] == '/customer/index' && !StoreService::orderServiceStatus($user->uid))
  97. unset($menusInfo[$key]);
  98. }
  99. return app('json')->successful(['routine_my_menus'=>$menusInfo]);
  100. }
  101. /**
  102. * 热门搜索关键字获取
  103. * @return mixed
  104. * @throws \think\db\exception\DataNotFoundException
  105. * @throws \think\db\exception\ModelNotFoundException
  106. * @throws \think\exception\DbException
  107. */
  108. public function search()
  109. {
  110. $routineHotSearch = GroupDataService::getData('routine_hot_search') ?? [];
  111. $searchKeyword = [];
  112. if(count($routineHotSearch)){
  113. foreach ($routineHotSearch as $key=>&$item){
  114. array_push($searchKeyword, $item['title']);
  115. }
  116. }
  117. return app('json')->successful($searchKeyword);
  118. }
  119. /**
  120. * 图片上传
  121. * @param Request $request
  122. * @return mixed
  123. * @throws \Psr\SimpleCache\InvalidArgumentException
  124. */
  125. public function upload_image(Request $request)
  126. {
  127. $data = UtilService::postMore([
  128. ['filename','file'],
  129. ],$request);
  130. if(!$data['filename']) return app('json')->fail('参数有误');
  131. if(Cache::has('start_uploads_'.$request->uid()) && Cache::get('start_uploads_'.$request->uid()) >= 100) return app('json')->fail('非法操作');
  132. $res = UploadService::getInstance()->setUploadPath('store/comment')->image($data['filename']);
  133. if(!is_array($res)) return app('json')->fail($res);
  134. SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'],1, $res['image_type'], $res['time'], 2);
  135. if(Cache::has('start_uploads_'.$request->uid()))
  136. $start_uploads=(int)Cache::get('start_uploads_'.$request->uid());
  137. else
  138. $start_uploads = 0;
  139. $start_uploads++;
  140. Cache::set('start_uploads_'.$request->uid(),$start_uploads,86400);
  141. $res['dir'] = UploadService::pathToUrl($res['dir']);
  142. if(strpos($res['dir'],'http') === false) $res['dir'] = $request->domain().$res['dir'];
  143. return app('json')->successful('图片上传成功!', ['name' => $res['name'], 'url' => $res['dir']]);
  144. }
  145. /**
  146. * 物流公司
  147. * @return mixed
  148. */
  149. public function logistics()
  150. {
  151. $expressList = Express::lst();
  152. if(!$expressList) return app('json')->successful([]);
  153. return app('json')->successful($expressList->hidden(['code', 'id', 'sort', 'is_show'])->toArray());
  154. }
  155. /**
  156. * 短信购买异步通知
  157. *
  158. * @param Request $request
  159. * @return mixed
  160. */
  161. public function sms_pay_notify(Request $request)
  162. {
  163. list($order_id, $price, $status, $num, $pay_time, $attach) = UtilService::postMore([
  164. ['order_id', ''],
  165. ['price', 0.00],
  166. ['status', 400],
  167. ['num', 0],
  168. ['pay_time', time()],
  169. ['attach', 0],
  170. ], $request, true);
  171. if($status == 200){
  172. ChannelService::instance()->send('PAY_SMS_SUCCESS', ['price'=> $price, 'number'=> $num], [$attach]);
  173. return app('json')->successful();
  174. }
  175. return app('json')->fail();
  176. }
  177. /**
  178. * 记录用户分享
  179. * @param Request $request
  180. * @return mixed
  181. */
  182. public function user_share(Request $request){
  183. return app('json')->successful(UserBill::setUserShare($request->uid()));
  184. }
  185. /**
  186. * 获取图片base64
  187. * @param Request $request
  188. * @return mixed
  189. */
  190. public function get_image_base64(Request $request){
  191. list($imageUrl,$codeUrl) = UtilService::postMore([
  192. ['image',''],
  193. ['code',''],
  194. ],$request,true);
  195. try{
  196. $code = $codeUrl ? UtilService::setImageBase64($codeUrl) : false;
  197. $image = $imageUrl ? UtilService::setImageBase64($imageUrl) : false;
  198. return app('json')->successful(compact('code','image'));
  199. }catch (\Exception $e){
  200. return app('json')->fail($e->getMessage());
  201. }
  202. }
  203. }