PublicController.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. if(!StoreService::orderServiceStatus($user->uid) && $value['wap_url'] === '/order/order_cancellation'){
  91. unset($menusInfo[$key]);
  92. }
  93. }
  94. return app('json')->successful(['routine_my_menus'=>$menusInfo]);
  95. }
  96. /**
  97. * 热门搜索关键字获取
  98. * @return mixed
  99. * @throws \think\db\exception\DataNotFoundException
  100. * @throws \think\db\exception\ModelNotFoundException
  101. * @throws \think\exception\DbException
  102. */
  103. public function search()
  104. {
  105. $routineHotSearch = GroupDataService::getData('routine_hot_search') ?? [];
  106. $searchKeyword = [];
  107. if(count($routineHotSearch)){
  108. foreach ($routineHotSearch as $key=>&$item){
  109. array_push($searchKeyword, $item['title']);
  110. }
  111. }
  112. return app('json')->successful($searchKeyword);
  113. }
  114. /**
  115. * 图片上传
  116. * @param Request $request
  117. * @return mixed
  118. * @throws \Psr\SimpleCache\InvalidArgumentException
  119. */
  120. public function upload_image(Request $request)
  121. {
  122. $data = UtilService::postMore([
  123. ['filename','file'],
  124. ],$request);
  125. if(!$data['filename']) return app('json')->fail('参数有误');
  126. if(Cache::has('start_uploads_'.$request->uid()) && Cache::get('start_uploads_'.$request->uid()) >= 100) return app('json')->fail('非法操作');
  127. $res = UploadService::getInstance()->setUploadPath('store/comment')->image($data['filename']);
  128. if(!is_array($res)) return app('json')->fail($res);
  129. SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'],1, $res['image_type'], $res['time'], 2);
  130. if(Cache::has('start_uploads_'.$request->uid()))
  131. $start_uploads=(int)Cache::get('start_uploads_'.$request->uid());
  132. else
  133. $start_uploads = 0;
  134. $start_uploads++;
  135. Cache::set('start_uploads_'.$request->uid(),$start_uploads,86400);
  136. $res['dir'] = UploadService::pathToUrl($res['dir']);
  137. if(strpos($res['dir'],'http') === false) $res['dir'] = $request->domain().$res['dir'];
  138. return app('json')->successful('图片上传成功!', ['name' => $res['name'], 'url' => $res['dir']]);
  139. }
  140. /**
  141. * 物流公司
  142. * @return mixed
  143. */
  144. public function logistics()
  145. {
  146. $expressList = Express::lst();
  147. if(!$expressList) return app('json')->successful([]);
  148. return app('json')->successful($expressList->hidden(['code', 'id', 'sort', 'is_show'])->toArray());
  149. }
  150. /**
  151. * 短信购买异步通知
  152. *
  153. * @param Request $request
  154. * @return mixed
  155. */
  156. public function sms_pay_notify(Request $request)
  157. {
  158. list($order_id, $price, $status, $num, $pay_time, $attach) = UtilService::postMore([
  159. ['order_id', ''],
  160. ['price', 0.00],
  161. ['status', 400],
  162. ['num', 0],
  163. ['pay_time', time()],
  164. ['attach', 0],
  165. ], $request, true);
  166. if($status == 200){
  167. ChannelService::instance()->send('PAY_SMS_SUCCESS', ['price'=> $price, 'number'=> $num], [$attach]);
  168. return app('json')->successful();
  169. }
  170. return app('json')->fail();
  171. }
  172. /**
  173. * 记录用户分享
  174. * @param Request $request
  175. * @return mixed
  176. */
  177. public function user_share(Request $request){
  178. return app('json')->successful(UserBill::setUserShare($request->uid()));
  179. }
  180. /**
  181. * 获取图片base64
  182. * @param Request $request
  183. * @return mixed
  184. */
  185. public function get_image_base64(Request $request){
  186. list($imageUrl,$codeUrl) = UtilService::postMore([
  187. ['image',''],
  188. ['code',''],
  189. ],$request,true);
  190. try{
  191. $code = $codeUrl ? UtilService::setImageBase64($codeUrl) : false;
  192. $image = $imageUrl ? UtilService::setImageBase64($imageUrl) : false;
  193. return app('json')->successful(compact('code','image'));
  194. }catch (\Exception $e){
  195. return app('json')->fail($e->getMessage());
  196. }
  197. }
  198. }