PublicController.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\v1;
  12. use app\jobs\integral\IntegralJob;
  13. use app\jobs\order\ShareOrderJob;
  14. use app\jobs\supplier\SupplierFinanceJob;
  15. use app\listener\order\Pay;
  16. use app\model\order\StoreOrder;
  17. use app\model\user\UserExtract;
  18. use app\model\user\UserIntegral;
  19. use app\model\user\User;
  20. use app\services\activity\combination\StorePinkServices;
  21. use app\services\diy\DiyServices;
  22. use app\services\message\service\StoreServiceServices;
  23. use app\services\order\StoreOrderServices;
  24. use app\services\store\DeliveryServiceServices;
  25. use app\services\other\CacheServices;
  26. use app\services\product\category\StoreProductCategoryServices;
  27. use app\services\product\product\StoreProductServices;
  28. use app\services\other\ExpressServices;
  29. use app\services\other\SystemCityServices;
  30. use app\services\supplier\finance\SupplierFlowingWaterServices;
  31. use app\services\system\attachment\SystemAttachmentServices;
  32. use app\services\system\config\SystemConfigServices;
  33. use app\services\store\SystemStoreServices;
  34. use app\services\store\SystemStoreStaffServices;
  35. use app\services\user\level\UserLevelServices;
  36. use app\services\user\UserAwardIntegralServices;
  37. use app\services\user\UserBillServices;
  38. use app\services\user\UserInvoiceServices;
  39. use app\services\user\UserServices;
  40. use app\services\wechat\WechatUserServices;
  41. use app\webscoket\SocketPush;
  42. use crmeb\services\AliAuthService;
  43. use crmeb\services\WithdrawService;
  44. use Joypack\Tencent\Map\Bundle\Location;
  45. use Joypack\Tencent\Map\Bundle\LocationOption;
  46. use app\Request;
  47. use crmeb\services\CacheService;
  48. use crmeb\services\UploadService;
  49. use crmeb\basic\BaseController;
  50. use think\facade\Cache;
  51. use think\facade\Log;
  52. /**
  53. * 公共类
  54. * Class PublicController
  55. * @package app\controller\api
  56. */
  57. class PublicController extends BaseController
  58. {
  59. public function version()
  60. {
  61. $version = sys_config('app_version', '');
  62. $apk = sys_config('app_apk', '');
  63. return app('json')->successful(compact('version', 'apk'));
  64. }
  65. public function test()
  66. {
  67. // $orders = StoreOrder::where('pid', '>', 0)->where('supplier_id', '>', 0)->select();
  68. // var_dump(count($orders));
  69. // foreach ($orders as $v) {
  70. // SupplierFinanceJob::dispatch([$v['id'], 1]);
  71. // }
  72. $list = UserExtract::where('uid', 'in', ['60', '72'])->order('id', 'asc')->select();
  73. foreach ($list as $v) {
  74. if ($v['id'] == 183) {
  75. continue;
  76. }
  77. $sum_money = UserExtract::where('uid', 'in', ['60', '72'])
  78. ->whereTime('add_time', 'month')
  79. ->where('user_type', 0)
  80. ->where('extract_type', '<>', 'balance')
  81. ->where('status', 1)->where('id', '<', $v['id'])->sum('extract_price');
  82. $sum_fee = UserExtract::where('uid', 'in', ['60', '72'])
  83. ->whereTime('add_time', 'month')
  84. ->where('user_type', 0)
  85. ->where('extract_type', '<>', 'balance')
  86. ->where('status', 1)->where('id', '<', $v['id'])->sum('extract_fee');
  87. $money_sum = bcadd(bcadd((string)$sum_money, (string)$sum_fee, 2), bcadd((string)$v['extract_price'], (string)$v['extract_fee'], 2), 2);
  88. $max_range = 0;
  89. $range = [];
  90. $fee = sys_data('withdraw_fee');
  91. foreach ($fee as $vv) {
  92. if ($money_sum > $vv['month_number']) {
  93. if ($max_range < $vv['month_number']) {
  94. $range = $vv;
  95. $max_range = $vv['month_number'];
  96. }
  97. }
  98. }
  99. if ($range != []) {
  100. if ($range['free_type'] == 1) {
  101. $free = bcdiv(bcmul((string)$money_sum, (string)$range['free']), '100', 2);
  102. } else {
  103. $free = $range['free'];
  104. }
  105. $the_fee = bcdiv(bcmul(bcsub((string)$money_sum, (string)$free, 2), (string)$range['fee']), '100', 2);
  106. $the_fee = bcsub((string)$the_fee, (string)$range['dec'], 2);
  107. $extract_fee = bcsub((string)$the_fee, (string)$sum_fee, 2);
  108. UserExtract::where('id', $v['id'])
  109. ->update(['extract_fee' => $extract_fee, 'extract_price' => bcsub(bcadd((string)$v['extract_price'], (string)$v['extract_fee'], 2), $extract_fee, 2)]);
  110. }
  111. }
  112. }
  113. public function dealOrderIntegral($order)
  114. {
  115. var_dump($order['id']);
  116. /** @var UserAwardIntegralServices $awardIntegralService */
  117. $awardIntegralService = app()->make(UserAwardIntegralServices::class);
  118. /** @var UserServices $userService */
  119. $userService = app()->make(UserServices::class);
  120. /** @var UserLevelServices $levelServices */
  121. $levelServices = app()->make(UserLevelServices::class);
  122. $integralJob = app()->make(IntegralJob::class);
  123. $user = $userService->getUserInfo($order['uid']);
  124. $integral_price = $awardIntegralService->getPrice($order['id']);
  125. $total_price = $order['total_price'];
  126. return $awardIntegralService->transaction(function () use ($integralJob, $levelServices, $awardIntegralService, $userService, $user, $integral_price, $total_price, $order) {
  127. try {
  128. $spread = $userService->getUserInfo($user['spread_uid']);
  129. $rate = sys_config('static_integral_rate', 3);
  130. $pass = [$user['uid']];
  131. $send = 0;
  132. while ($spread && !in_array($spread['uid'], $pass)) {
  133. //先发奖,再结算等级
  134. $level = $levelServices->getUserLevel($spread['uid']);
  135. $ratio = $level['levelInfo']['group_award'] ?? 0;
  136. var_dump($spread['uid']);
  137. var_dump($ratio);
  138. $give_action_integral = bcdiv(bcmul($total_price, $ratio), 100, 2);
  139. if ($give_action_integral > $send) {
  140. $real_send = bcsub($give_action_integral, $send, 2);
  141. if ($awardIntegralService->getPaySum($spread['uid']) >= 0 || $awardIntegralService->getHourExtractPaySum($spread['uid'], 24) > 0 || $spread['award_switch']) {
  142. $extract_sum = bcmul($real_send, $rate, 2);
  143. $mark = '团队用户' . $user['nickname'] . "({$user['uid']})" . '购买商品,获得团队级差积分';
  144. var_dump($spread['uid']);
  145. var_dump($integral_price);
  146. var_dump($real_send);
  147. var_dump($total_price);
  148. var_dump($extract_sum);
  149. var_dump($order['id']);
  150. var_dump($mark);
  151. $awardIntegralService->incIntegral($spread['uid'], $integral_price, $real_send, $total_price, 1, $extract_sum, $order['id'], $mark);
  152. }
  153. $send = $give_action_integral;
  154. }
  155. $levelServices->detection((int)$spread['uid']);
  156. $pass[] = $spread['uid'];
  157. $spread = $userService->getUserInfo($spread['spread_uid']);
  158. }
  159. $integralJob->autoExtract($awardIntegralService->getPrice());
  160. return true;
  161. } catch (\Throwable $e) {
  162. var_dump($e->getMessage());
  163. return false;
  164. }
  165. });
  166. }
  167. /**
  168. * 主页获取
  169. * @param Request $request
  170. * @return mixed
  171. */
  172. public function index(Request $request)
  173. {
  174. $uid = $request->hasMacro('uid') ? (int)$request->uid() : 0;
  175. $banner = sys_data('routine_home_banner') ?: [];// 首页banner图
  176. $menus = sys_data('routine_home_menus') ?: [];// 首页按钮
  177. $roll = sys_data('routine_home_roll_news') ?: [];// 首页滚动新闻
  178. $activity = sys_data('routine_home_activity', 3) ?: [];// 首页活动区域图片
  179. $explosive_money = sys_data('index_categy_images') ?: [];// 首页超值爆款
  180. $site_name = sys_config('site_name');
  181. $routine_index_page = sys_data('routine_index_page');
  182. $info['fastInfo'] = $routine_index_page[0]['fast_info'] ?? '';// 快速选择简介
  183. $info['bastInfo'] = $routine_index_page[0]['bast_info'] ?? '';// 精品推荐简介
  184. $info['firstInfo'] = $routine_index_page[0]['first_info'] ?? '';// 首发新品简介
  185. $info['salesInfo'] = $routine_index_page[0]['sales_info'] ?? '';// 促销单品简介
  186. $logoUrl = sys_config('routine_index_logo');// 促销单品简介
  187. if (strstr($logoUrl, 'http') === false && $logoUrl) {
  188. $logoUrl = sys_config('site_url') . $logoUrl;
  189. }
  190. $logoUrl = str_replace('\\', '/', $logoUrl);
  191. $fastNumber = (int)sys_config('fast_number', 0);// 快速选择分类个数
  192. $bastNumber = (int)sys_config('bast_number', 0);// 精品推荐个数
  193. $firstNumber = (int)sys_config('first_number', 0);// 首发新品个数
  194. $promotionNumber = (int)sys_config('promotion_number', 0);// 首发新品个数
  195. /** @var StoreProductCategoryServices $categoryService */
  196. $categoryService = app()->make(StoreProductCategoryServices::class);
  197. $info['fastList'] = $fastNumber ? $categoryService->byIndexList($fastNumber, 'id,cate_name,pid,pic') : [];// 快速选择分类个数
  198. /** @var StoreProductServices $storeProductServices */
  199. $storeProductServices = app()->make(StoreProductServices::class);
  200. $info['bastList'] = $bastNumber ? $storeProductServices->getRecommendProduct($uid, ['is_best' => 1], $bastNumber) : [];// 精品推荐个数
  201. $info['firstList'] = $firstNumber ? $storeProductServices->getRecommendProduct($uid, ['is_new' => 1], $firstNumber) : [];// 首发新品个数
  202. $info['bastBanner'] = sys_data('routine_home_bast_banner') ?? [];// 首页精品推荐图片
  203. $benefit = $promotionNumber ? $storeProductServices->getRecommendProduct($uid, ['is_benefit' => 1], $promotionNumber) : [];// 首页促销单品
  204. $lovely = sys_data('routine_home_new_banner') ?: [];// 首发新品顶部图
  205. $likeInfo = $storeProductServices->getRecommendProduct($uid, ['is_hot' => 1], 3);// 热门榜单 猜你喜欢
  206. if ($uid) {
  207. /** @var WechatUserServices $wechatUserService */
  208. $wechatUserService = app()->make(WechatUserServices::class);
  209. $subscribe = (bool)$wechatUserService->value(['uid' => $uid], 'subscribe');
  210. } else {
  211. $subscribe = true;
  212. }
  213. $newGoodsBananr = sys_config('new_goods_bananr');
  214. $tengxun_map_key = sys_config('tengxun_map_key');
  215. $award_integral_service = app()->make(UserAwardIntegralServices::class);
  216. $award_lack = $award_integral_service->getLake();
  217. $integral_price = $award_integral_service->getPrice();
  218. return app('json')->successful(compact('award_lack', 'integral_price', 'banner', 'menus', 'roll', 'info', 'activity', 'lovely', 'benefit', 'likeInfo', 'logoUrl', 'site_name', 'subscribe', 'newGoodsBananr', 'tengxun_map_key', 'explosive_money'));
  219. }
  220. /**
  221. * 获取分享配置
  222. * @return mixed
  223. */
  224. public function share()
  225. {
  226. $data['img'] = sys_config('wechat_share_img');
  227. if (strstr($data['img'], 'http') === false) {
  228. $data['img'] = sys_config('site_url') . $data['img'];
  229. }
  230. $data['img'] = str_replace('\\', '/', $data['img']);
  231. $data['title'] = sys_config('wechat_share_title');
  232. $data['synopsis'] = sys_config('wechat_share_synopsis');
  233. return app('json')->successful($data);
  234. }
  235. /**
  236. * 获取网站配置
  237. * @return mixed
  238. */
  239. public function getSiteConfig()
  240. {
  241. $data['record_No'] = sys_config('record_No');
  242. return app('json')->success($data);
  243. }
  244. /**
  245. * 获取个人中心菜单
  246. * @param Request $request
  247. * @return mixed
  248. * @throws \think\db\exception\DataNotFoundException
  249. * @throws \think\db\exception\ModelNotFoundException
  250. * @throws \think\exception\DbException
  251. */
  252. public function menu_user(Request $request)
  253. {
  254. $menusInfo = sys_data('routine_my_menus') ?? [];
  255. $uid = 0;
  256. $userInfo = [];
  257. if ($request->hasMacro('user')) $userInfo = $request->user();
  258. if ($request->hasMacro('uid')) $uid = $request->uid();
  259. $vipOpen = sys_config('member_func_status');
  260. $brokerageFuncStatus = sys_config('brokerage_func_status');
  261. $balanceFuncStatus = sys_config('balance_func_status');
  262. $vipCard = sys_config('member_card_status', 0);
  263. $svipOpen = (bool)sys_config('member_card_status');
  264. $userService = $invoiceStatus = $deliveryUser = $isUserPromoter = $userVerifyStatus = $userOrder = $isStaff = $isDelivery = true;
  265. if ($uid && $userInfo) {
  266. /** @var StoreServiceServices $storeService */
  267. $storeService = app()->make(StoreServiceServices::class);
  268. $userService = $storeService->checkoutIsService(['uid' => $uid, 'status' => 1, 'account_status' => 1]);
  269. $userOrder = $storeService->checkoutIsService(['uid' => $uid, 'account_status' => 1, 'customer' => 1]);
  270. /** @var SystemStoreStaffServices $systemStoreStaff */
  271. $systemStoreStaff = app()->make(SystemStoreStaffServices::class);
  272. /** @var UserServices $user */
  273. $user = app()->make(UserServices::class);
  274. /** @var UserInvoiceServices $userInvoice */
  275. $userInvoice = app()->make(UserInvoiceServices::class);
  276. $invoiceStatus = $userInvoice->invoiceFuncStatus(false);
  277. /** @var DeliveryServiceServices $deliveryService */
  278. $deliveryService = app()->make(DeliveryServiceServices::class);
  279. $deliveryUser = $deliveryService->checkoutIsService($uid);
  280. $isUserPromoter = $user->checkUserPromoter($uid, $userInfo);
  281. $userVerifyStatus = $systemStoreStaff->verifyStatus($uid);
  282. try {
  283. $isStaff = $systemStoreStaff->getStaffInfoByUid($uid);
  284. } catch (\Throwable $e) {
  285. $isStaff = false;
  286. }
  287. try {
  288. $isDelivery = $deliveryService->getDeliveryInfoByUid($uid);
  289. } catch (\Throwable $e) {
  290. $isDelivery = false;
  291. }
  292. }
  293. $auth = [];
  294. $auth['/pages/users/user_vip/index'] = !$vipOpen;
  295. $auth['/pages/users/user_spread_user/index'] = !$brokerageFuncStatus || !$isUserPromoter || $uid == 0;
  296. $auth['/pages/users/user_money/index'] = !$balanceFuncStatus;
  297. $auth['/pages/admin/order/index'] = !$userOrder || $uid == 0;
  298. $auth['/pages/admin/order_cancellation/index'] = (!$userVerifyStatus && !$deliveryUser) || $uid == 0;
  299. $auth['/pages/users/user_invoice_list/index'] = !$invoiceStatus;
  300. $auth['/pages/annex/vip_paid/index'] = !$vipCard || !$svipOpen;
  301. $auth['/kefu/mobile_list'] = !$userService || $uid == 0;
  302. $auth['/pages/admin/store/index'] = $uid == 0 || !$isStaff;
  303. $auth['/pages/admin/distribution/index'] = $uid == 0 || !$isDelivery;
  304. $auth['/pages/store_spread/index'] = $uid == 0 || !$isStaff;
  305. foreach ($menusInfo as $key => &$value) {
  306. $value['pic'] = set_file_url($value['pic'] ?? '');
  307. $value['url'] = $value['url'] ?? '';
  308. if (isset($auth[$value['url']]) && $auth[$value['url']]) {
  309. unset($menusInfo[$key]);
  310. continue;
  311. }
  312. if ($value['url'] == '/kefu/mobile_list') {
  313. $value['url'] = sys_config('site_url') . $value['url'];
  314. if ($request->isRoutine()) {
  315. $value['url'] = str_replace('http://', 'https://', $value['url']);
  316. }
  317. }
  318. }
  319. /** @var SystemConfigServices $systemConfigServices */
  320. $systemConfigServices = app()->make(SystemConfigServices::class);
  321. $bannerInfo = $systemConfigServices->getSpreadBanner() ?? [];
  322. $my_banner = sys_data('routine_my_banner');
  323. $routine_contact_type = sys_config('routine_contact_type', 0);
  324. /** @var DiyServices $diyServices */
  325. $diyServices = app()->make(DiyServices::class);
  326. $diy_data = $diyServices->cacheRemember('diy_data_member_3', function () use ($diyServices) {
  327. $diy_data = $diyServices->get(['template_name' => 'member', 'type' => 3], ['value', 'status', 'order_status', 'my_banner_status', 'menu_status', 'service_status']);
  328. $diy_data = $diy_data ? $diy_data->toArray() : [];
  329. return $diy_data;
  330. });
  331. if ($diy_data) {
  332. $diy_value = json_decode($diy_data['value'], true);
  333. $new_value = [];
  334. if (is_int($diy_value)) {
  335. $new_value['status'] = $diy_value;
  336. $new_value['vip_type'] = 1;
  337. $new_value['newcomer_status'] = 1;
  338. $new_value['newcomer_style'] = 1;
  339. } else {
  340. $new_value = $diy_value;
  341. }
  342. $diy_data = array_merge($diy_data, $new_value);
  343. $diy_data['order_status'] = (int)$diy_data['order_status'];
  344. }
  345. unset($diy_data['value']);
  346. return app('json')->successful(['routine_my_menus' => array_merge($menusInfo), 'routine_my_banner' => $my_banner, 'routine_spread_banner' => $bannerInfo, 'routine_contact_type' => $routine_contact_type, 'diy_data' => $diy_data]);
  347. }
  348. /**
  349. * 热门搜索关键字获取
  350. * @return mixed
  351. * @throws \think\db\exception\DataNotFoundException
  352. * @throws \think\db\exception\ModelNotFoundException
  353. * @throws \think\exception\DbException
  354. */
  355. public function search()
  356. {
  357. $routineHotSearch = sys_data('routine_hot_search') ?? [];
  358. $searchKeyword = [];
  359. if (count($routineHotSearch)) {
  360. foreach ($routineHotSearch as $key => &$item) {
  361. array_push($searchKeyword, $item['title'] ?? '');
  362. }
  363. }
  364. return app('json')->successful($searchKeyword);
  365. }
  366. /**
  367. * 图片上传
  368. * @param Request $request
  369. * @return mixed
  370. * @throws \Psr\SimpleCache\InvalidArgumentException
  371. */
  372. public function upload_image(Request $request, SystemAttachmentServices $services)
  373. {
  374. $data = $request->postMore([
  375. ['filename', 'file'],
  376. ]);
  377. if (!$data['filename']) return app('json')->fail('参数有误');
  378. if (CacheService::has('start_uploads_' . $request->uid()) && CacheService::get('start_uploads_' . $request->uid()) >= 100) return app('json')->fail('非法操作');
  379. $upload = UploadService::init();
  380. $info = $upload->to('store/comment')->validate()->move($data['filename']);
  381. if ($info === false) {
  382. return app('json')->fail($upload->getError());
  383. }
  384. $res = $upload->getUploadInfo();
  385. $services->attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 1, (int)sys_config('upload_type', 1), $res['time'], 3);
  386. if (CacheService::has('start_uploads_' . $request->uid()))
  387. $start_uploads = (int)CacheService::get('start_uploads_' . $request->uid());
  388. else
  389. $start_uploads = 0;
  390. $start_uploads++;
  391. CacheService::set('start_uploads_' . $request->uid(), $start_uploads, 86400);
  392. $res['dir'] = path_to_url($res['dir']);
  393. if (strpos($res['dir'], 'http') === false) $res['dir'] = sys_config('site_url') . $res['dir'];
  394. return app('json')->successful('图片上传成功!', ['name' => $res['name'], 'url' => $res['dir']]);
  395. }
  396. /**
  397. * 物流公司
  398. * @return mixed
  399. */
  400. public function logistics(Request $request, ExpressServices $services)
  401. {
  402. [$status] = $request->getMore([
  403. ['status', ''],
  404. ], true);
  405. if ($status == 1) $data['status'] = $status;
  406. $data['is_show'] = 1;
  407. $expressList = $services->expressList($data);
  408. return app('json')->successful($expressList ?? []);
  409. }
  410. /**
  411. * 反向解析地址
  412. * @param Request $request
  413. * @return mixed
  414. */
  415. public function geoLbscoder(Request $request)
  416. {
  417. [$data] = $request->getMore([
  418. ['location', '']
  419. ], true);
  420. $locationOption = new LocationOption(sys_config('tengxun_map_key'));
  421. $data = explode(',', $data);
  422. $locationOption->setLocation($data[0] ?? '', $data[1] ?? '');
  423. $location = new Location($locationOption);
  424. $res = $location->request();
  425. if ($res->error) {
  426. return app('json')->fail($res->error);
  427. }
  428. if ($res->status) {
  429. return app('json')->fail($res->message);
  430. }
  431. if (!$res->result) {
  432. return app('json')->fail('获取失败');
  433. }
  434. return app('json')->success($res->result);
  435. }
  436. /**
  437. * 短信购买异步通知
  438. *
  439. * @param Request $request
  440. * @return mixed
  441. */
  442. public function sms_pay_notify(Request $request)
  443. {
  444. [$order_id, $price, $status, $num, $pay_time, $attach] = $request->postMore([
  445. ['order_id', ''],
  446. ['price', 0.00],
  447. ['status', 400],
  448. ['num', 0],
  449. ['pay_time', time()],
  450. ['attach', 0],
  451. ], true);
  452. if ($status == 200) {
  453. try {
  454. SocketPush::admin()->type('PAY_SMS_SUCCESS')->data(['price' => $price, 'number' => $num])->push();
  455. } catch (\Throwable $e) {
  456. }
  457. return app('json')->successful();
  458. }
  459. return app('json')->fail();
  460. }
  461. /**
  462. * 记录用户分享
  463. * @param Request $request
  464. * @param UserBillServices $services
  465. * @return mixed
  466. */
  467. public function user_share(Request $request, UserBillServices $services)
  468. {
  469. $uid = (int)$request->uid();
  470. return app('json')->successful($services->setUserShare($uid));
  471. }
  472. /**
  473. * 获取图片base64
  474. * @param Request $request
  475. * @return mixed
  476. */
  477. public function get_image_base64(Request $request)
  478. {
  479. [$imageUrl, $codeUrl] = $request->postMore([
  480. ['image', ''],
  481. ['code', ''],
  482. ], true);
  483. if ($imageUrl !== '' && !preg_match('/.*(\.png|\.jpg|\.jpeg|\.gif)$/', $imageUrl)) {
  484. return app('json')->success(['code' => false, 'image' => false]);
  485. }
  486. if ($codeUrl !== '' && !(preg_match('/.*(\.png|\.jpg|\.jpeg|\.gif)$/', $codeUrl) || strpos($codeUrl, 'https://mp.weixin.qq.com/cgi-bin/showqrcode') !== false)) {
  487. return app('json')->success(['code' => false, 'image' => false]);
  488. }
  489. try {
  490. $code = CacheService::get($codeUrl, function () use ($codeUrl) {
  491. $codeTmp = $code = $codeUrl ? image_to_base64($codeUrl) : false;
  492. if (!$codeTmp) {
  493. $codeUrl = explode('?', $codeUrl)[0] ?? $codeUrl;
  494. $putCodeUrl = put_image($codeUrl);
  495. $code = $putCodeUrl ? image_to_base64(public_path() . $putCodeUrl) : false;
  496. $code ?? unlink(public_path() . $putCodeUrl);
  497. }
  498. return $code;
  499. });
  500. $image = CacheService::get($imageUrl, function () use ($imageUrl) {
  501. $imageTmp = $image = $imageUrl ? image_to_base64($imageUrl) : false;
  502. if (!$imageTmp) {
  503. $imageUrl = explode('?', $imageUrl)[0] ?? $imageUrl;
  504. $putImageUrl = put_image($imageUrl);
  505. $image = $putImageUrl ? image_to_base64(public_path() . $putImageUrl) : false;
  506. $image ?? unlink(public_path() . $putImageUrl);
  507. }
  508. return $image;
  509. });
  510. return app('json')->successful(compact('code', 'image'));
  511. } catch (\Exception $e) {
  512. return app('json')->fail($e->getMessage());
  513. }
  514. }
  515. /**
  516. * 门店列表
  517. * @param Request $request
  518. * @param SystemStoreServices $services
  519. * @return mixed
  520. * @throws \think\db\exception\DataNotFoundException
  521. * @throws \think\db\exception\DbException
  522. * @throws \think\db\exception\ModelNotFoundException
  523. */
  524. public function store_list(Request $request, SystemStoreServices $services)
  525. {
  526. [$latitude, $longitude, $product_id, $type, $is_store, $store_id] = $request->getMore([
  527. ['latitude', ''],
  528. ['longitude', ''],
  529. ['product_id', 0],
  530. ['type', 0],//商品类型 0:普通 1:秒杀
  531. ['is_store', 1], //前端传值为 1|商城配送 2|门店自提 3|门店配送
  532. ['store_id', 0], //前端传值为 1|商城配送 2|门店自提 3|门店配送
  533. ], true);
  534. //判断是否门店自提
  535. $is_store == 2 ? $is_store = 1 : $is_store = '';
  536. $where = ['type' => 0, 'is_store' => $is_store];
  537. $field = ['id', 'name', 'phone', 'image', 'latitude', 'longitude', 'address', 'detailed_address', 'is_show', 'is_store', 'day_time', 'day_start', 'day_end', 'valid_range'];
  538. $data['list'] = $services->getStoreList($where, $field, $latitude, $longitude, (int)$product_id, [], (int)$type, $store_id);
  539. $data['tengxun_map_key'] = sys_config('tengxun_map_key');
  540. return app('json')->successful($data);
  541. }
  542. /**
  543. * 查找城市数据
  544. * @param Request $request
  545. * @return mixed
  546. */
  547. public function city_list(Request $request)
  548. {
  549. /** @var SystemCityServices $systemCity */
  550. $systemCity = app()->make(SystemCityServices::class);
  551. return app('json')->successful($systemCity->cityList());
  552. }
  553. /**
  554. * 获取拼团数据
  555. * @return mixed
  556. */
  557. public function pink(Request $request, StorePinkServices $pink, UserServices $user)
  558. {
  559. [$type] = $request->getMore([
  560. ['type', 1],
  561. ], true);
  562. $where = ['is_refund' => 0];
  563. if ($type == 1) {
  564. $where['status'] = 2;
  565. }
  566. $data['pink_count'] = $pink->getCount($where);
  567. $uids = array_flip($pink->getColumn($where, 'uid'));
  568. if (count($uids)) {
  569. mt_srand();
  570. $uids = array_rand($uids, count($uids) < 3 ? count($uids) : 3);
  571. }
  572. $data['avatars'] = $uids ? $user->getColumn(is_array($uids) ? [['uid', 'in', $uids]] : ['uid' => $uids], 'avatar') : [];
  573. return app('json')->successful($data);
  574. }
  575. /**
  576. * 复制口令接口
  577. * @return mixed
  578. */
  579. public function copy_words()
  580. {
  581. $data['words'] = sys_config('copy_words');
  582. return app('json')->successful($data);
  583. }
  584. /**
  585. * 生成口令关键字
  586. * @param Request $request
  587. * @return mixed
  588. * @throws \think\db\exception\DataNotFoundException
  589. * @throws \think\db\exception\DbException
  590. * @throws \think\db\exception\ModelNotFoundException
  591. */
  592. public function copy_share_words(Request $request)
  593. {
  594. [$productId] = $request->getMore([
  595. ['product_id', ''],
  596. ], true);
  597. /** @var StoreProductServices $productService */
  598. $productService = app()->make(StoreProductServices::class);
  599. $keyWords['key_words'] = $productService->getProductWords($productId);
  600. return app('json')->successful($keyWords);
  601. }
  602. /**
  603. * 获取页面数据
  604. * @return mixed
  605. * @throws \think\db\exception\DataNotFoundException
  606. * @throws \think\db\exception\DbException
  607. * @throws \think\db\exception\ModelNotFoundException
  608. */
  609. public function getDiy(DiyServices $services, $id = 0)
  610. {
  611. return app('json')->successful($services->getDiyInfo((int)$id));
  612. }
  613. /**
  614. * @param DiyServices $services
  615. * @param int $id
  616. * @return mixed
  617. * @author 等风来
  618. * @email 136327134@qq.com
  619. * @date 2022/11/9
  620. */
  621. public function getDiyVersion(DiyServices $services, $id = 0)
  622. {
  623. return app('json')->successful(['version' => $services->getDiyVersion((int)$id)]);
  624. }
  625. /**
  626. * 获取底部导航
  627. * @param DiyServices $services
  628. * @param string $template_name
  629. * @return mixed
  630. */
  631. public function getNavigation(DiyServices $services, string $template_name = '')
  632. {
  633. return app('json')->success($services->getNavigation($template_name));
  634. }
  635. /**
  636. * 获取用户协议内容
  637. * @return mixed
  638. */
  639. public function getUserAgreement(Request $request, $type = 1)
  640. {
  641. /** @var CacheServices $cache */
  642. $cache = app()->make(CacheServices::class);
  643. /** @var UserServices $userService */
  644. $userService = app()->make(UserServices::class);
  645. $content = $cache->getDbCache($type, '');
  646. $uid = $request->uid() ?? 0;
  647. $userInfo = $userService->get($uid);
  648. $name = $userInfo['nickname'] ?? '';
  649. $avatar = $userInfo['avatar'] ?? '';
  650. return app('json')->success(compact('content', 'uid', 'name', 'avatar'));
  651. }
  652. /**
  653. * 统计代码
  654. * @return array|string
  655. */
  656. public function getScript()
  657. {
  658. return sys_config('system_statistics', '');
  659. }
  660. /**
  661. * 首页开屏广告
  662. * @return mixed
  663. */
  664. public function getOpenAdv()
  665. {
  666. /** @var CacheServices $cache */
  667. $cache = app()->make(CacheServices::class);
  668. $data = $cache->getDbCache('open_adv', '');
  669. $data['time'] = (float)($data['time'] ?? 3);
  670. $data['interval_time'] = (float)($data['interval_time'] ?? 24);
  671. return app('json')->success($data);
  672. }
  673. /**
  674. * 用户注销
  675. * @param Request $request
  676. * @return mixed
  677. */
  678. public function cancelUser(Request $request)
  679. {
  680. $uid = $request->uid();
  681. if (!$uid) return app('json')->fail('用户不存在');
  682. event('user.cancelUser', [$uid]);
  683. return app('json')->success('注销成功');
  684. }
  685. /**
  686. * 获取版权
  687. * @return mixed
  688. */
  689. public function getCopyright()
  690. {
  691. try {
  692. $copyright = $this->__z6uxyJQ4xYa5ee1mx5();
  693. } catch (\Throwable $e) {
  694. $copyright = [
  695. 'copyrightContext' => '',
  696. 'copyrightImage' => '',
  697. ];
  698. }
  699. $copyright['record_No'] = sys_config('record_No');
  700. $copyright['version'] = get_crmeb_version();
  701. $copyright['routine_contact_type'] = sys_config('routine_contact_type');
  702. $copyright['store_user_agreement'] = (int)sys_config('store_user_agreement');
  703. $copyright['routine_auth_type'] = sys_config('routine_auth_type', []);
  704. $copyright['wechat_auth_switch'] = (int)in_array(1, $copyright['routine_auth_type']);//微信登录开关
  705. $copyright['phone_auth_switch'] = (int)in_array(2, $copyright['routine_auth_type']);//手机号登录开关
  706. $copyright['site_name'] = sys_config('site_name', '');
  707. $copyright['site_logo'] = sys_config('wap_login_logo', '');
  708. $copyright['wechat_status'] = sys_config('wechat_appid') && sys_config('wechat_appsecret');
  709. return $this->success($copyright);
  710. }
  711. /**
  712. * 登录页面获取logo以及版本全新
  713. * @return mixed
  714. */
  715. public function getLogo()
  716. {
  717. try {
  718. $copyright = $this->__z6uxyJQ4xYa5ee1mx5();
  719. } catch (\Throwable $e) {
  720. $copyright = [
  721. 'copyrightContext' => '',
  722. 'copyrightImage' => '',
  723. ];
  724. }
  725. $copyright['record_No'] = sys_config('record_No');
  726. $copyright['version'] = get_crmeb_version();
  727. $logo = sys_config('wap_login_logo');
  728. if (strstr($logo, 'http') === false && $logo) $logo = sys_config('site_url') . $logo;
  729. $copyright['site_name'] = sys_config('site_name');
  730. $copyright['logo_url'] = str_replace('\\', '/', $logo);
  731. $copyright['store_user_agreement'] = (int)sys_config('store_user_agreement');
  732. $copyright['routine_auth_type'] = sys_config('routine_auth_type', []);
  733. $copyright['wechat_auth_switch'] = (int)in_array(1, $copyright['routine_auth_type']);//微信登录开关
  734. $copyright['phone_auth_switch'] = (int)in_array(2, $copyright['routine_auth_type']);//手机号登录开关
  735. $copyright['wechat_status'] = sys_config('wechat_appid') && sys_config('wechat_appsecret');
  736. return app('json')->successful($copyright);
  737. }
  738. public function authNotify(Request $request)
  739. {
  740. $data = $request->param();
  741. $token = $data['callbackToken'];
  742. $certifyId = $data['certifyId'];
  743. $check_token = Cache::get($certifyId, '');
  744. if ($token != $check_token) {
  745. return app('json')->fail('已过期');
  746. }
  747. $uid = Cache::get($token, 0);
  748. $user = User::where(['uid' => $uid])->find();
  749. if (!$user || $user['is_auth'] == 2 || $user['is_auth'] == 3) {
  750. return app('json')->fail('信息已审核或不存在');
  751. }
  752. $info = AliAuthService::result($certifyId);
  753. if (!$info) {
  754. return app('json')->fail(AliAuthService::getError());
  755. }
  756. if ($info['passed'] == 'T') {
  757. User::where(['uid' => $uid])->update(['is_auth' => 2, 'off' => ""]);
  758. } else {
  759. User::where(['uid' => $uid])->update(['off' => AliAuthService::getCodeError($info['subCode']), 'is_auth' => "3"]);
  760. }
  761. return app('json')->success('OK');
  762. }
  763. }