PublicController.php 9.7 KB

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