PublicController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\model\system\SystemAttachment;
  4. use app\models\lala\LalaPinkJoin;
  5. use app\models\lala\LalaRatio;
  6. use app\models\mining\MiningMachine;
  7. use app\models\mining\UserMiningMachine;
  8. use app\models\lala\WalletLog;
  9. use app\models\point_plan\PointPlan;
  10. use app\models\point_plan\UserPointPlan;
  11. use app\models\store\StoreBargainUser;
  12. use app\models\store\StoreCategory;
  13. use app\models\store\StoreCouponIssue;
  14. use app\models\store\StoreOrder;
  15. use app\models\store\StorePink;
  16. use app\models\store\StoreProduct;
  17. use app\models\store\StoreService;
  18. use app\models\system\Express;
  19. use app\models\system\Message;
  20. use app\models\system\Site;
  21. use app\models\system\SystemCity;
  22. use app\models\system\SystemMoney;
  23. use app\models\system\SystemStore;
  24. use app\models\system\SystemStoreStaff;
  25. use app\models\user\Achievement;
  26. use app\models\user\User;
  27. use app\models\user\UserBill;
  28. use app\models\user\UserLevel;
  29. use app\models\user\UserMoney;
  30. use app\models\user\UserRecharge;
  31. use app\models\user\UserToken;
  32. use app\models\user\WechatUser;
  33. use app\Request;
  34. use crmeb\basic\BaseModel;
  35. use crmeb\services\blockchain\BlockChianService;
  36. use crmeb\services\CacheService;
  37. use crmeb\services\MobileRechargeService;
  38. use crmeb\services\UdunService;
  39. use crmeb\services\UtilService;
  40. use crmeb\services\workerman\ChannelService;
  41. use GuzzleHttp\Client;
  42. use mattvb91\TronTrx\Address;
  43. use mattvb91\TronTrx\Api;
  44. use mattvb91\TronTrx\Exceptions\TronErrorException;
  45. use mattvb91\TronTrx\Wallet;
  46. use think\db\exception\DataNotFoundException;
  47. use think\db\exception\DbException;
  48. use think\db\exception\ModelNotFoundException;
  49. use think\facade\Cache;
  50. use crmeb\services\upload\Upload;
  51. use think\facade\Db;
  52. use think\facade\Log;
  53. use Tron\TRX;
  54. /**
  55. * 公共类
  56. * Class PublicController
  57. * @package app\api\controller
  58. */
  59. class PublicController
  60. {
  61. public function version(Request $request)
  62. {
  63. $version_code = sys_config('version_code', '', true);
  64. $apk = sys_config('apk', '', true);
  65. return app('json')->success('ok', compact('version_code', 'apk'));
  66. }
  67. public function finance(Request $request)
  68. {
  69. $p = file_get_contents('fake_day');
  70. $p = explode('*-&-*', $p);
  71. if ($p[0] != date('Y-m-d')) {
  72. $p[1] = (int)$p[1] + 1;
  73. }
  74. $p = $p[1] > 35 ? 35 : $p[1];
  75. file_put_contents('fake_day', date('Y-m-d') . '*-&-*' . $p);
  76. $money_type = sys_data('money_type');
  77. $lala_price = get_lala_ratio();
  78. // foreach ($money_type as $v) {
  79. // if ($v['code'] == 'LALA') {
  80. // $lala_price = get_lala_ratio();
  81. //// if ($v['usdt_price'] == 0) {
  82. ////// var_dump(get_huobi_price($v['code']));
  83. //// $lala_price = get_huobi_price($v['code']);
  84. //// } else {
  85. //// $lala_price = $v['usdt_price'];
  86. //// }
  87. // }
  88. // }
  89. $data['hui_zong_shu_ju'] = [
  90. 'liu_tong_liang' => UserMoney::where('money_type', 'LALA')->value('SUM(money)'),
  91. 'dang_tian_jia_ge' => $lala_price,
  92. 'chi_bi_di_zhi_shu' => UserMoney::where('money_type', 'LALA')->where('money', '>', 0)->count() + $p * 15,
  93. 'jie_dian_shu' => PointPlan::where('status', '>', 0)->count(),
  94. 'dang_qian_zhi_ya_liang' => 0,
  95. 'lei_ji_xiao_hui_liang' => UserBill::where('pm', 0)->where('status', 1)->where('type', 'lala_ticket')->where('category', 'LALA')->value('SUM(number)') / 2 + (($p + 1) * $p / 2 * 2250),
  96. 'zuo_ri_xiao_hui_liang' => UserBill::whereTime('add_time', 'yesterday')->where('pm', 0)->where('status', 1)->where('type', 'lala_ticket')->where('category', 'LALA')->value('SUM(number)') / 2 + $p * 2250,
  97. 'he_huo_ren_shu' => UserPointPlan::count(),
  98. ];
  99. $data['zuo_ri_jing_ying'] = [
  100. 'pin_tuan_shu' => LalaPinkJoin::whereTime('add_time', 'yesterday')->group('group_id')->field('group_id,COUNT(group_id)')->count() + $p * 5,
  101. 'men_piao_shu' => UserBill::whereTime('add_time', 'yesterday')->where('pm', 0)->where('status', 1)->where('type', 'lala_ticket')->where('category', 'LALA')->value('SUM(number)') + $p * 5500,
  102. 'ye_ji' => UserBill::whereTime('add_time', 'yesterday')->where('pm', 0)->where('status', 1)->where('type', 'lala_cost')->where('category', 'USDT')->value('SUM(number)') + $p * 5500,
  103. 'men_piao_xiao_hui_shu' => UserBill::whereTime('add_time', 'yesterday')->where('pm', 0)->where('status', 1)->where('type', 'lala_ticket')->where('category', 'LALA')->value('SUM(number)') / 2 + $p * 2250,
  104. 'can_yu_ren_shu' => count(LalaPinkJoin::whereTime('add_time', 'yesterday')->group('uid')->field('uid,COUNT(uid)')->select()) + $p * 55,
  105. 'men_piao_fen_hong' => UserBill::whereTime('add_time', 'yesterday')->where('pm', 1)->where('status', 1)->where('type', 'lala_point_award')->where('category', 'LALA')->value('SUM(number)'),
  106. 'zhuan_zhang_shou_xu_fei' => 0,
  107. 'zhuan_zhang_xiao_hui_shu' => 0,
  108. ];
  109. $data['le_ji_jing_ying'] = [
  110. 'pin_tuan_shu' => LalaPinkJoin::group('group_id')->field('group_id,COUNT(group_id)')->count() + (($p + 1) * $p / 2 * 5),
  111. 'men_piao_shu' => UserBill::where('pm', 0)->where('status', 1)->where('type', 'lala_ticket')->where('category', 'LALA')->value('SUM(number)') + (($p + 1) * $p / 2 * 5500),
  112. 'ye_ji' => UserBill::where('pm', 0)->where('status', 1)->where('type', 'lala_cost')->where('category', 'USDT')->value('SUM(number)') + (($p + 1) * $p / 2 * 5500),
  113. 'men_piao_xiao_hui_shu' => UserBill::where('pm', 0)->where('status', 1)->where('type', 'lala_ticket')->where('category', 'LALA')->value('SUM(number)') / 2 + (($p + 1) * $p / 2 * 2250),
  114. 'can_yu_ren_shu' => count(LalaPinkJoin::group('uid')->field('uid,COUNT(uid)')->select()) + (($p + 1) * $p / 2 * 55),
  115. 'men_piao_fen_hong' => UserBill::where('pm', 1)->where('status', 1)->where('type', 'lala_point_award')->where('category', 'LALA')->value('SUM(number)'),
  116. 'zhuan_zhang_shou_xu_fei' => 0,
  117. 'zhuan_zhang_xiao_hui_shu' => 0,
  118. ];
  119. return app('json')->success('ok', $data);
  120. }
  121. public function service(Request $request)
  122. {
  123. $service_wechat = sys_config('service_wechat');
  124. $service_qr = sys_config('service_qr');
  125. return app('json')->success('ok', compact('service_wechat', 'service_qr'));
  126. }
  127. public function retry()
  128. {
  129. $list = LalaPinkJoin::whereTime('add_time', 'today')->select();
  130. $res1 = true;
  131. $res2 = true;
  132. $res3 = true;
  133. foreach ($list as $v) {
  134. if ($v['status'] > 0) {
  135. $check = UserBill::where('link_id', $v['id'])->where('type', 'in', ['lala_fail', 'lala_bingo', 'lala_bingo_fail'])->find();
  136. $check2 = UserBill::where('link_id', $v['id'])->where('type', 'lala_cost')->find();
  137. if (!$check2) {
  138. LalaPinkJoin::where('id', $v['id'])->delete();
  139. }
  140. if (!$check && $check2) {
  141. //补回
  142. switch ($v['status']) {
  143. case 1:
  144. $res1 = $res1 && UserMoney::incomeMoney($v['uid'], $v['bingo_money_type'], $v['bingo'], 'lala_bingo', '拼购中奖', '参与第' . $v['group_id'] . '期第' . $v['table_id'] . '桌拼购中奖', $v['id']);
  145. $res1 = $res1 && LalaPinkJoin::addSystemAward($v);
  146. //$res1 = $res1 && self::sendJoinAward($info) && self::addSystemAward($info) && self::sendRecommendAward($info) && self::sendGroupAward($info);
  147. $uper = User::getUserInfo($v['uid']);
  148. while ($uper) {
  149. UserLevel::setLevelComplete($uper['uid']);
  150. $uper = User::getUserInfo($uper['spread_uid']);
  151. }
  152. break;
  153. case 2:
  154. $res2 = $res2 && UserMoney::incomeMoney($v['uid'], $v['cost_money_type'], $v['cost'], 'lala_bingo_fail', '拼购未中奖退回', '参与第' . $v['group_id'] . '期第' . $v['table_id'] . '桌拼购未中奖', $v['id']);
  155. $res2 = $res2 && LalaPinkJoin::sendJoinAward($v) && LalaPinkJoin::addSystemAward($v) && LalaPinkJoin::sendRecommendAward($v) && LalaPinkJoin::sendGroupAward($v);
  156. $uper = User::getUserInfo($v['uid']);
  157. while ($uper) {
  158. UserLevel::setLevelComplete($uper['uid']);
  159. $uper = User::getUserInfo($uper['spread_uid']);
  160. }
  161. break;
  162. case 3:
  163. $res3 = $res3 && UserMoney::incomeMoney($v['uid'], $v['cost_money_type'], $v['cost'], 'lala_fail', '拼购人数不足退回', '参与第' . $v['group_id'] . '期第' . $v['table_id'] . '桌拼购人数不足', $v['id']);
  164. break;
  165. }
  166. }
  167. }
  168. }
  169. return $res1 && $res2 && $res3;
  170. }
  171. public function summary()
  172. {
  173. dump((new BlockChianService())->autoSummary());
  174. }
  175. /**
  176. * @param Request $request
  177. * @throws \Tron\Exceptions\TronErrorException
  178. */
  179. public function test(Request $request)
  180. {
  181. Achievement::do_Fhllirun();
  182. }
  183. public function message_cate(Request $request)
  184. {
  185. return app('json')->success('ok', Message::getMessageCate($request->uid()));
  186. }
  187. public function message($id, Request $request)
  188. {
  189. $page = $request->get('page', 1);
  190. $limit = $request->get('limit', 10);
  191. return app('json')->success('ok', Message::getMessages($id, $request->uid(), $page, $limit));
  192. }
  193. public function block(Request $request)
  194. {
  195. BlockChianService::autoGetTransfer();
  196. BlockChianService::autoCheckTransfer();
  197. }
  198. public function balance($code, Request $request)
  199. {
  200. $address = $request->get('address');
  201. $all = $request->get('all');
  202. $balance = BlockChianService::balance($code, $address);
  203. $percent = (bcmul(bcdiv($balance, $all, 10), 100, 8) * 1) . '%';
  204. return app('json')->success('ok', compact('balance', 'percent'));
  205. }
  206. public function lala_ratio(Request $request)
  207. {
  208. $list = LalaRatio::order('id', 'desc')->select()->toArray();
  209. foreach ($list as &$v) {
  210. $v['lala_price'] = get_lala_ratio($v['date']);
  211. }
  212. return app('json')->success('ok', $list);
  213. }
  214. public function achievement_rank(Request $request)
  215. {
  216. $achievement = function ($uid) {
  217. $uids = [$uid];
  218. $all = [];
  219. while ($uids) {
  220. $uids = User::where('spread_uid', 'in', $uids)->column('uid');
  221. $all = array_merge($all, $uids);
  222. }
  223. //var_dump($all);
  224. return LalaPinkJoin::where('paid', 1)->where('status', 'in', [1, 2])->where('uid', '<>', 0)->where('uid', 'in', $all)->where('cost_money_type', 'USDT')->value('SUM(cost)');
  225. };
  226. $small_achivement = function ($uid) {
  227. $sub_uids = User::where('spread_uid', $uid)->column('uid');
  228. $max = 0;
  229. $all = 0;
  230. foreach ($sub_uids as $v) {
  231. $uids = [$v];
  232. $all_uids = [$v];
  233. while ($uids) {
  234. $uids = \app\admin\model\user\User::where('spread_uid', 'in', $uids)->column('uid');
  235. $all_uids = array_merge($all_uids, $uids);
  236. }
  237. $achievement = LalaPinkJoin::where('paid', 1)->where('uid', '<>', 0)->where('status', 'in', [1, 2])->where('uid', 'in', $all_uids)->where('cost_money_type', 'USDT')->value('SUM(cost)');
  238. if ($achievement > $max) $max = $achievement;
  239. $all += $achievement;
  240. }
  241. return $all - $max;
  242. };
  243. $achievement_month = function ($uid) {
  244. $uids = [$uid];
  245. $all = [];
  246. while ($uids) {
  247. $uids = User::where('spread_uid', 'in', $uids)->column('uid');
  248. $all = array_merge($all, $uids);
  249. }
  250. //var_dump($all);
  251. return LalaPinkJoin::whereTime('add_time', 'month')->where('paid', 1)->where('status', 'in', [1, 2])->where('uid', '<>', 0)->where('uid', 'in', $all)->where('cost_money_type', 'USDT')->value('SUM(cost)');
  252. };
  253. $small_achivement_month = function ($uid) {
  254. $sub_uids = User::where('spread_uid', $uid)->column('uid');
  255. $max = 0;
  256. $all = 0;
  257. foreach ($sub_uids as $v) {
  258. $uids = [$v];
  259. $all_uids = [$v];
  260. while ($uids) {
  261. $uids = \app\admin\model\user\User::where('spread_uid', 'in', $uids)->column('uid');
  262. $all_uids = array_merge($all_uids, $uids);
  263. }
  264. $achievement = LalaPinkJoin::whereTime('add_time', 'month')->where('paid', 1)->where('uid', '<>', 0)->where('status', 'in', [1, 2])->where('uid', 'in', $all_uids)->where('cost_money_type', 'USDT')->value('SUM(cost)');
  265. if ($achievement > $max) $max = $achievement;
  266. $all += $achievement;
  267. }
  268. return $all - $max;
  269. };
  270. $list = User::select();
  271. $rank_list = [];
  272. foreach ($list as $v) {
  273. $rank_list[] = ['uid' => $v['uid'], 'user' => $v, 'achievement' => $small_achivement_month($v['uid'])];
  274. }
  275. $last_names = array_column($rank_list, 'achievement');
  276. array_multisort($last_names, SORT_DESC, $rank_list);
  277. return app('json')->success('ok', $rank_list);
  278. }
  279. public function udunCallBack(Request $request)
  280. {
  281. $data = $request->post();
  282. file_put_contents("call_back_data.txt", "\n" . date('Y-m-d H:i:s') . $data['body'] . "\n", FILE_APPEND);
  283. UdunService::Notify($data);
  284. }
  285. /**
  286. * @param Request $request
  287. * @return mixed
  288. * @throws DataNotFoundException
  289. * @throws DbException
  290. * @throws ModelNotFoundException
  291. */
  292. public function systemWallet(Request $request)
  293. {
  294. $uid = $request->site_id();
  295. $money_type = sys_data('money_type');
  296. $back = [];
  297. foreach ($money_type as $v) {
  298. $back[$v['code']] = $v;
  299. $back[$v['code']]['money'] = SystemMoney::initialMoney($uid, $v['code']);
  300. }
  301. return app('json')->success('ok', compact('back'));
  302. }
  303. /**
  304. * @param Request $request
  305. * @return mixed
  306. * @throws DataNotFoundException
  307. * @throws ModelNotFoundException
  308. * @throws \think\exception\DbException
  309. */
  310. public function index(Request $request)
  311. {
  312. $banner = sys_data('routine_home_banner') ?: [];//TODO 首页banner图
  313. $menus = sys_data('routine_home_menus') ?: [];//TODO 首页按钮
  314. $roll = sys_data('routine_home_roll_news') ?: [];//TODO 首页滚动新闻
  315. $activity = sys_data('routine_home_activity', 3) ?: [];//TODO 首页活动区域图片
  316. $site_name = sys_config('site_name');
  317. $routine_index_page = sys_data('routine_index_page');
  318. $info['fastInfo'] = $routine_index_page[0]['fast_info'] ?? '';//sys_config('fast_info');//TODO 快速选择简介
  319. $info['bastInfo'] = $routine_index_page[0]['bast_info'] ?? '';//sys_config('bast_info');//TODO 精品推荐简介
  320. $info['firstInfo'] = $routine_index_page[0]['first_info'] ?? '';//sys_config('first_info');//TODO 首发新品简介
  321. $info['salesInfo'] = $routine_index_page[0]['sales_info'] ?? '';//sys_config('sales_info');//TODO 促销单品简介
  322. $logoUrl = sys_config('routine_index_logo');//TODO 促销单品简介
  323. if (strstr($logoUrl, 'http') === false && $logoUrl) $logoUrl = sys_config('site_url') . $logoUrl;
  324. $logoUrl = str_replace('\\', '/', $logoUrl);
  325. $fastNumber = sys_config('fast_number', 0);//TODO 快速选择分类个数
  326. $bastNumber = sys_config('bast_number', 0);//TODO 精品推荐个数
  327. $firstNumber = sys_config('first_number', 0);//TODO 首发新品个数
  328. $promotionNumber = sys_config('promotion_number', 0);//TODO 首发新品个数
  329. $info['fastList'] = StoreCategory::byIndexList((int)$fastNumber, false);//TODO 快速选择分类个数
  330. $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 精品推荐个数
  331. $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 首发新品个数
  332. $info['bastBanner'] = sys_data('routine_home_bast_banner') ?? [];//TODO 首页精品推荐图片
  333. $benefit = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name', $promotionNumber);//TODO 首页促销单品
  334. $lovely = sys_data('routine_home_new_banner') ?: [];//TODO 首发新品顶部图
  335. $likeInfo = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,ot_price,unit_name', $fastNumber);//TODO 热门榜单 猜你喜欢
  336. $couponList = StoreCouponIssue::getIssueCouponList($request->uid(), 3);
  337. if ($request->uid()) {
  338. $subscribe = WechatUser::where('uid', $request->uid())->value('subscribe') ? true : false;
  339. } else {
  340. $subscribe = true;
  341. }
  342. $newGoodsBananr = sys_config('new_goods_bananr');
  343. $tengxun_map_key = sys_config('tengxun_map_key');
  344. $cash_day = sys_config('cash_day');
  345. return app('json')->successful(compact('cash_day', 'banner', 'menus', 'roll', 'info', 'activity', 'lovely', 'benefit', 'likeInfo', 'logoUrl', 'couponList', 'site_name', 'subscribe', 'newGoodsBananr', 'tengxun_map_key'));
  346. }
  347. /**
  348. * @param Request $request
  349. * @return mixed
  350. * @throws DataNotFoundException
  351. * @throws DbException
  352. * @throws ModelNotFoundException
  353. */
  354. public function cityArea(Request $request)
  355. {
  356. $province = SystemCity::where('level', 0)->where('parent_id', 0)->field('name,city_id')->select()->each(function ($item) {
  357. $item['city'] = SystemCity::where('level', 1)
  358. ->where('parent_id', $item['city_id'])
  359. ->field('name,city_id')
  360. ->select()->each(function ($sub_item) {
  361. $sub_item['area'] = SystemCity::where('level', 2)
  362. ->where('parent_id', $sub_item['city_id'])
  363. ->column('name');
  364. unset($sub_item['city_id']);
  365. })->toArray();
  366. unset($item['city_id']);
  367. });
  368. return app('json')->success('ok', $province->toArray());
  369. }
  370. /**
  371. * 获取分享配置
  372. * @return mixed
  373. */
  374. public function share()
  375. {
  376. $data['img'] = sys_config('wechat_share_img');
  377. if (strstr($data['img'], 'http') === false) $data['img'] = sys_config('site_url') . $data['img'];
  378. $data['img'] = str_replace('\\', '/', $data['img']);
  379. $data['title'] = sys_config('wechat_share_title');
  380. $data['synopsis'] = sys_config('wechat_share_synopsis');
  381. return app('json')->successful(compact('data'));
  382. }
  383. /**
  384. * 获取个人中心菜单
  385. * @param Request $request
  386. * @return mixed
  387. * @throws DataNotFoundException
  388. * @throws ModelNotFoundException
  389. * @throws \think\exception\DbException
  390. */
  391. public function menu_user(Request $request)
  392. {
  393. $menusInfo = sys_data('routine_my_menus') ?? [];
  394. $user = $request->user();
  395. $vipOpen = sys_config('vip_open');
  396. $vipOpen = is_string($vipOpen) ? (int)$vipOpen : $vipOpen;
  397. foreach ($menusInfo as $key => &$value) {
  398. $value['pic'] = set_file_url($value['pic']);
  399. if ($value['id'] == 137 && !(intval(sys_config('store_brokerage_statu')) == 2 || $user->is_promoter == 1))
  400. unset($menusInfo[$key]);
  401. if ($value['id'] == 174 && !StoreService::orderServiceStatus($user->uid))
  402. unset($menusInfo[$key]);
  403. if (((!StoreService::orderServiceStatus($user->uid)) && (!SystemStoreStaff::verifyStatus($user->uid))) && $value['wap_url'] === '/order/order_cancellation')
  404. unset($menusInfo[$key]);
  405. if (((!StoreService::orderServiceStatus($user->uid)) && (!SystemStoreStaff::verifyStatus($user->uid))) && $value['wap_url'] === '/admin/order_cancellation/index')
  406. unset($menusInfo[$key]);
  407. if ((!StoreService::orderServiceStatus($user->uid)) && $value['wap_url'] === '/admin/order/index')
  408. unset($menusInfo[$key]);
  409. if ($value['wap_url'] == '/user/vip' && !$vipOpen)
  410. unset($menusInfo[$key]);
  411. if ($value['wap_url'] == '/customer/index' && !StoreService::orderServiceStatus($user->uid))
  412. unset($menusInfo[$key]);
  413. }
  414. return app('json')->successful(['routine_my_menus' => $menusInfo]);
  415. }
  416. /**
  417. * 热门搜索关键字获取
  418. * @return mixed
  419. * @throws DataNotFoundException
  420. * @throws ModelNotFoundException
  421. * @throws \think\exception\DbException
  422. */
  423. public function search()
  424. {
  425. $routineHotSearch = sys_data('routine_hot_search') ?? [];
  426. $searchKeyword = [];
  427. if (count($routineHotSearch)) {
  428. foreach ($routineHotSearch as $key => &$item) {
  429. array_push($searchKeyword, $item['title']);
  430. }
  431. }
  432. return app('json')->successful($searchKeyword);
  433. }
  434. /**
  435. * 图片上传
  436. * @param Request $request
  437. * @return mixed
  438. * @throws \Psr\SimpleCache\InvalidArgumentException
  439. */
  440. public function upload_image(Request $request)
  441. {
  442. $data = UtilService::postMore([
  443. ['filename', 'file'],
  444. ], $request);
  445. if (!$data['filename']) return app('json')->fail('参数有误');
  446. if (Cache::has('start_uploads_' . $request->uid()) && Cache::get('start_uploads_' . $request->uid()) >= 100) return app('json')->fail('非法操作');
  447. $upload_type = sys_config('upload_type', 1);
  448. $upload = new Upload((int)$upload_type, [
  449. 'accessKey' => sys_config('accessKey'),
  450. 'secretKey' => sys_config('secretKey'),
  451. 'uploadUrl' => sys_config('uploadUrl'),
  452. 'storageName' => sys_config('storage_name'),
  453. 'storageRegion' => sys_config('storage_region'),
  454. ]);
  455. $info = $upload->to('store/comment')->validate()->move($data['filename']);
  456. if ($info === false) {
  457. return app('json')->fail($upload->getError());
  458. }
  459. $res = $upload->getUploadInfo();
  460. SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 1, $upload_type, $res['time'], 2);
  461. if (Cache::has('start_uploads_' . $request->uid()))
  462. $start_uploads = (int)Cache::get('start_uploads_' . $request->uid());
  463. else
  464. $start_uploads = 0;
  465. $start_uploads++;
  466. Cache::set('start_uploads_' . $request->uid(), $start_uploads, 86400);
  467. $res['dir'] = path_to_url($res['dir']);
  468. if (strpos($res['dir'], 'http') === false) $res['dir'] = $request->domain() . $res['dir'];
  469. return app('json')->successful('图片上传成功!', ['name' => $res['name'], 'url' => $res['dir']]);
  470. }
  471. /**
  472. * 物流公司
  473. * @return mixed
  474. */
  475. public function logistics()
  476. {
  477. $expressList = Express::lst();
  478. if (!$expressList) return app('json')->successful([]);
  479. return app('json')->successful($expressList->hidden(['code', 'id', 'sort', 'is_show'])->toArray());
  480. }
  481. /**
  482. * 短信购买异步通知
  483. *
  484. * @param Request $request
  485. * @return mixed
  486. */
  487. public function sms_pay_notify(Request $request)
  488. {
  489. list($order_id, $price, $status, $num, $pay_time, $attach) = UtilService::postMore([
  490. ['order_id', ''],
  491. ['price', 0.00],
  492. ['status', 400],
  493. ['num', 0],
  494. ['pay_time', time()],
  495. ['attach', 0],
  496. ], $request, true);
  497. if ($status == 200) {
  498. ChannelService::instance()->send('PAY_SMS_SUCCESS', ['price' => $price, 'number' => $num], [$attach]);
  499. return app('json')->successful();
  500. }
  501. return app('json')->fail();
  502. }
  503. /**
  504. * 记录用户分享
  505. * @param Request $request
  506. * @return mixed
  507. */
  508. public function user_share(Request $request)
  509. {
  510. return app('json')->successful(UserBill::setUserShare($request->uid()));
  511. }
  512. /**
  513. * 获取图片base64
  514. * @param Request $request
  515. * @return mixed
  516. */
  517. public function get_image_base64(Request $request)
  518. {
  519. list($imageUrl, $codeUrl) = UtilService::postMore([
  520. ['image', ''],
  521. ['code', ''],
  522. ], $request, true);
  523. try {
  524. $codeTmp = $code = $codeUrl ? image_to_base64($codeUrl) : false;
  525. if (!$codeTmp) {
  526. $putCodeUrl = put_image($codeUrl);
  527. $code = $putCodeUrl ? image_to_base64($_SERVER['HTTP_HOST'] . '/' . $putCodeUrl) : false;
  528. $code ?? unlink($_SERVER["DOCUMENT_ROOT"] . '/' . $putCodeUrl);
  529. }
  530. $imageTmp = $image = $imageUrl ? image_to_base64($imageUrl) : false;
  531. if (!$imageTmp) {
  532. $putImageUrl = put_image($imageUrl);
  533. $image = $putImageUrl ? image_to_base64($_SERVER['HTTP_HOST'] . '/' . $putImageUrl) : false;
  534. $image ?? unlink($_SERVER["DOCUMENT_ROOT"] . '/' . $putImageUrl);
  535. }
  536. return app('json')->successful(compact('code', 'image'));
  537. } catch (\Exception $e) {
  538. return app('json')->fail($e->getMessage());
  539. }
  540. }
  541. /**
  542. * 门店列表
  543. * @return mixed
  544. */
  545. public function store_list(Request $request)
  546. {
  547. list($latitude, $longitude, $page, $limit) = UtilService::getMore([
  548. ['latitude', ''],
  549. ['longitude', ''],
  550. ['page', 1],
  551. ['limit', 10]
  552. ], $request, true);
  553. $list = SystemStore::lst($latitude, $longitude, $page, $limit);
  554. if (!$list) $list = [];
  555. $data['list'] = $list;
  556. $data['tengxun_map_key'] = sys_config('tengxun_map_key');
  557. return app('json')->successful($data);
  558. }
  559. /**
  560. * 查找城市数据
  561. * @param Request $request
  562. * @return mixed
  563. */
  564. public function city_list(Request $request)
  565. {
  566. $list = CacheService::get('CITY_LIST', function () {
  567. $list = SystemCity::with('children')->field(['city_id', 'name', 'id', 'parent_id'])->where('parent_id', 0)->order('id asc')->select()->toArray();
  568. $data = [];
  569. foreach ($list as &$item) {
  570. $value = ['v' => $item['city_id'], 'n' => $item['name']];
  571. if ($item['children']) {
  572. foreach ($item['children'] as $key => &$child) {
  573. $value['c'][$key] = ['v' => $child['city_id'], 'n' => $child['name']];
  574. unset($child['id'], $child['area_code'], $child['merger_name'], $child['is_show'], $child['level'], $child['lng'], $child['lat'], $child['lat']);
  575. if (SystemCity::where('parent_id', $child['city_id'])->count()) {
  576. $child['children'] = SystemCity::where('parent_id', $child['city_id'])->field(['city_id', 'name', 'id', 'parent_id'])->select()->toArray();
  577. foreach ($child['children'] as $kk => $vv) {
  578. $value['c'][$key]['c'][$kk] = ['v' => $vv['city_id'], 'n' => $vv['name']];
  579. }
  580. }
  581. }
  582. }
  583. $data[] = $value;
  584. }
  585. return $data;
  586. }, 0);
  587. return app('json')->successful($list);
  588. }
  589. public function gp_fh()
  590. {
  591. $res = Achievement::do_Fhllirun();
  592. if ($res) {
  593. echo '发放成功';
  594. } else {
  595. echo '发放失败';
  596. }
  597. }
  598. }