PublicController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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\User;
  26. use app\models\user\UserBill;
  27. use app\models\user\UserLevel;
  28. use app\models\user\UserMoney;
  29. use app\models\user\UserRecharge;
  30. use app\models\user\UserToken;
  31. use app\models\user\WechatUser;
  32. use app\Request;
  33. use crmeb\basic\BaseModel;
  34. use crmeb\services\blockchain\BlockChianService;
  35. use crmeb\services\CacheService;
  36. use crmeb\services\MobileRechargeService;
  37. use crmeb\services\UdunService;
  38. use crmeb\services\UtilService;
  39. use crmeb\services\WechatService;
  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. $user = WechatUser::where('uid', 3575)->column('nickname,subscribe,openid', 'uid');
  182. if ($user) {
  183. foreach ($user as $v) {
  184. if ($v['subscribe'] && $v['openid']) {
  185. try {
  186. WechatService::staffService()->message('你好')->to($v['openid'])->send();
  187. } catch (\Exception $e) {
  188. echo $v['nickname'] . '发送失败' . $e->getMessage();
  189. }
  190. } else {
  191. echo $v['nickname'] . '没有关注发送失败(不是微信公众号用户)';
  192. }
  193. }
  194. }
  195. }
  196. public function message_cate(Request $request)
  197. {
  198. return app('json')->success('ok', Message::getMessageCate($request->uid()));
  199. }
  200. public function message($id, Request $request)
  201. {
  202. $page = $request->get('page', 1);
  203. $limit = $request->get('limit', 10);
  204. return app('json')->success('ok', Message::getMessages($id, $request->uid(), $page, $limit));
  205. }
  206. public function block(Request $request)
  207. {
  208. BlockChianService::autoGetTransfer();
  209. BlockChianService::autoCheckTransfer();
  210. }
  211. public function balance($code, Request $request)
  212. {
  213. $address = $request->get('address');
  214. $all = $request->get('all');
  215. $balance = BlockChianService::balance($code, $address);
  216. $percent = (bcmul(bcdiv($balance, $all, 10), 100, 8) * 1) . '%';
  217. return app('json')->success('ok', compact('balance', 'percent'));
  218. }
  219. public function lala_ratio(Request $request)
  220. {
  221. $list = LalaRatio::order('id', 'desc')->select()->toArray();
  222. foreach ($list as &$v) {
  223. $v['lala_price'] = get_lala_ratio($v['date']);
  224. }
  225. return app('json')->success('ok', $list);
  226. }
  227. public function achievement_rank(Request $request)
  228. {
  229. $achievement = function ($uid) {
  230. $uids = [$uid];
  231. $all = [];
  232. while ($uids) {
  233. $uids = User::where('spread_uid', 'in', $uids)->column('uid');
  234. $all = array_merge($all, $uids);
  235. }
  236. //var_dump($all);
  237. 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)');
  238. };
  239. $small_achivement = function ($uid) {
  240. $sub_uids = User::where('spread_uid', $uid)->column('uid');
  241. $max = 0;
  242. $all = 0;
  243. foreach ($sub_uids as $v) {
  244. $uids = [$v];
  245. $all_uids = [$v];
  246. while ($uids) {
  247. $uids = \app\admin\model\user\User::where('spread_uid', 'in', $uids)->column('uid');
  248. $all_uids = array_merge($all_uids, $uids);
  249. }
  250. $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)');
  251. if ($achievement > $max) $max = $achievement;
  252. $all += $achievement;
  253. }
  254. return $all - $max;
  255. };
  256. $achievement_month = function ($uid) {
  257. $uids = [$uid];
  258. $all = [];
  259. while ($uids) {
  260. $uids = User::where('spread_uid', 'in', $uids)->column('uid');
  261. $all = array_merge($all, $uids);
  262. }
  263. //var_dump($all);
  264. 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)');
  265. };
  266. $small_achivement_month = function ($uid) {
  267. $sub_uids = User::where('spread_uid', $uid)->column('uid');
  268. $max = 0;
  269. $all = 0;
  270. foreach ($sub_uids as $v) {
  271. $uids = [$v];
  272. $all_uids = [$v];
  273. while ($uids) {
  274. $uids = \app\admin\model\user\User::where('spread_uid', 'in', $uids)->column('uid');
  275. $all_uids = array_merge($all_uids, $uids);
  276. }
  277. $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)');
  278. if ($achievement > $max) $max = $achievement;
  279. $all += $achievement;
  280. }
  281. return $all - $max;
  282. };
  283. $list = User::select();
  284. $rank_list = [];
  285. foreach ($list as $v) {
  286. $rank_list[] = ['uid' => $v['uid'], 'user' => $v, 'achievement' => $small_achivement_month($v['uid'])];
  287. }
  288. $last_names = array_column($rank_list, 'achievement');
  289. array_multisort($last_names, SORT_DESC, $rank_list);
  290. return app('json')->success('ok', $rank_list);
  291. }
  292. public function udunCallBack(Request $request)
  293. {
  294. $data = $request->post();
  295. file_put_contents("call_back_data.txt", "\n" . date('Y-m-d H:i:s') . $data['body'] . "\n", FILE_APPEND);
  296. UdunService::Notify($data);
  297. }
  298. /**
  299. * @param Request $request
  300. * @return mixed
  301. * @throws DataNotFoundException
  302. * @throws DbException
  303. * @throws ModelNotFoundException
  304. */
  305. public function systemWallet(Request $request)
  306. {
  307. $uid = $request->site_id();
  308. $money_type = sys_data('money_type');
  309. $back = [];
  310. foreach ($money_type as $v) {
  311. $back[$v['code']] = $v;
  312. $back[$v['code']]['money'] = SystemMoney::initialMoney($uid, $v['code']);
  313. }
  314. return app('json')->success('ok', compact('back'));
  315. }
  316. /**
  317. * @param Request $request
  318. * @return mixed
  319. * @throws DataNotFoundException
  320. * @throws ModelNotFoundException
  321. * @throws \think\exception\DbException
  322. */
  323. public function index(Request $request)
  324. {
  325. $banner = sys_data('routine_home_banner') ?: [];//TODO 首页banner图
  326. $menus = sys_data('routine_home_menus') ?: [];//TODO 首页按钮
  327. $roll = sys_data('routine_home_roll_news') ?: [];//TODO 首页滚动新闻
  328. $activity = sys_data('routine_home_activity', 3) ?: [];//TODO 首页活动区域图片
  329. $site_name = sys_config('site_name');
  330. $routine_index_page = sys_data('routine_index_page');
  331. $info['fastInfo'] = $routine_index_page[0]['fast_info'] ?? '';//sys_config('fast_info');//TODO 快速选择简介
  332. $info['bastInfo'] = $routine_index_page[0]['bast_info'] ?? '';//sys_config('bast_info');//TODO 精品推荐简介
  333. $info['firstInfo'] = $routine_index_page[0]['first_info'] ?? '';//sys_config('first_info');//TODO 首发新品简介
  334. $info['salesInfo'] = $routine_index_page[0]['sales_info'] ?? '';//sys_config('sales_info');//TODO 促销单品简介
  335. $logoUrl = sys_config('routine_index_logo');//TODO 促销单品简介
  336. if (strstr($logoUrl, 'http') === false && $logoUrl) $logoUrl = sys_config('site_url') . $logoUrl;
  337. $logoUrl = str_replace('\\', '/', $logoUrl);
  338. $fastNumber = sys_config('fast_number', 0);//TODO 快速选择分类个数
  339. $bastNumber = sys_config('bast_number', 0);//TODO 精品推荐个数
  340. $firstNumber = sys_config('first_number', 0);//TODO 首发新品个数
  341. $promotionNumber = sys_config('promotion_number', 0);//TODO 首发新品个数
  342. $info['fastList'] = StoreCategory::byIndexList((int)$fastNumber, false);//TODO 快速选择分类个数
  343. $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 精品推荐个数
  344. $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 首发新品个数
  345. $info['bastBanner'] = sys_data('routine_home_bast_banner') ?? [];//TODO 首页精品推荐图片
  346. $benefit = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name', $promotionNumber, $request->uid());//TODO 首页促销单品
  347. $lovely = sys_data('routine_home_new_banner') ?: [];//TODO 首发新品顶部图
  348. $likeInfo = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,ot_price,unit_name', $fastNumber);//TODO 热门榜单 猜你喜欢
  349. $couponList = StoreCouponIssue::getIssueCouponList($request->uid(), 3);
  350. if ($request->uid()) {
  351. $subscribe = WechatUser::where('uid', $request->uid())->value('subscribe') ? true : false;
  352. } else {
  353. $subscribe = true;
  354. }
  355. $newGoodsBananr = sys_config('new_goods_bananr');
  356. $tengxun_map_key = sys_config('tengxun_map_key');
  357. return app('json')->successful(compact('banner', 'menus', 'roll', 'info', 'activity', 'lovely', 'benefit', 'likeInfo', 'logoUrl', 'couponList', 'site_name', 'subscribe', 'newGoodsBananr', 'tengxun_map_key'));
  358. }
  359. /**
  360. * @param Request $request
  361. * @return mixed
  362. * @throws DataNotFoundException
  363. * @throws DbException
  364. * @throws ModelNotFoundException
  365. */
  366. public function cityArea(Request $request)
  367. {
  368. $province = SystemCity::where('level', 0)->where('parent_id', 0)->field('name,city_id')->select()->each(function ($item) {
  369. $item['city'] = SystemCity::where('level', 1)
  370. ->where('parent_id', $item['city_id'])
  371. ->field('name,city_id')
  372. ->select()->each(function ($sub_item) {
  373. $sub_item['area'] = SystemCity::where('level', 2)
  374. ->where('parent_id', $sub_item['city_id'])
  375. ->column('name');
  376. unset($sub_item['city_id']);
  377. })->toArray();
  378. unset($item['city_id']);
  379. });
  380. return app('json')->success('ok', $province->toArray());
  381. }
  382. /**
  383. * 获取分享配置
  384. * @return mixed
  385. */
  386. public function share()
  387. {
  388. $data['img'] = sys_config('wechat_share_img');
  389. if (strstr($data['img'], 'http') === false) $data['img'] = sys_config('site_url') . $data['img'];
  390. $data['img'] = str_replace('\\', '/', $data['img']);
  391. $data['title'] = sys_config('wechat_share_title');
  392. $data['synopsis'] = sys_config('wechat_share_synopsis');
  393. return app('json')->successful(compact('data'));
  394. }
  395. /**
  396. * 获取个人中心菜单
  397. * @param Request $request
  398. * @return mixed
  399. * @throws DataNotFoundException
  400. * @throws ModelNotFoundException
  401. * @throws \think\exception\DbException
  402. */
  403. public function menu_user(Request $request)
  404. {
  405. $menusInfo = sys_data('routine_my_menus') ?? [];
  406. $user = $request->user();
  407. $vipOpen = sys_config('vip_open');
  408. $vipOpen = is_string($vipOpen) ? (int)$vipOpen : $vipOpen;
  409. foreach ($menusInfo as $key => &$value) {
  410. $value['pic'] = set_file_url($value['pic']);
  411. if ($value['id'] == 137 && !(intval(sys_config('store_brokerage_statu')) == 2 || $user->is_promoter == 1))
  412. unset($menusInfo[$key]);
  413. if ($value['id'] == 174 && !StoreService::orderServiceStatus($user->uid))
  414. unset($menusInfo[$key]);
  415. if (((!StoreService::orderServiceStatus($user->uid)) && (!SystemStoreStaff::verifyStatus($user->uid))) && $value['wap_url'] === '/order/order_cancellation')
  416. unset($menusInfo[$key]);
  417. if (((!StoreService::orderServiceStatus($user->uid)) && (!SystemStoreStaff::verifyStatus($user->uid))) && $value['wap_url'] === '/admin/order_cancellation/index')
  418. unset($menusInfo[$key]);
  419. if ((!StoreService::orderServiceStatus($user->uid)) && $value['wap_url'] === '/admin/order/index')
  420. unset($menusInfo[$key]);
  421. if ($value['wap_url'] == '/user/vip' && !$vipOpen)
  422. unset($menusInfo[$key]);
  423. if ($value['wap_url'] == '/customer/index' && !StoreService::orderServiceStatus($user->uid))
  424. unset($menusInfo[$key]);
  425. }
  426. return app('json')->successful(['routine_my_menus' => $menusInfo]);
  427. }
  428. /**
  429. * 热门搜索关键字获取
  430. * @return mixed
  431. * @throws DataNotFoundException
  432. * @throws ModelNotFoundException
  433. * @throws \think\exception\DbException
  434. */
  435. public function search()
  436. {
  437. $routineHotSearch = sys_data('routine_hot_search') ?? [];
  438. $searchKeyword = [];
  439. if (count($routineHotSearch)) {
  440. foreach ($routineHotSearch as $key => &$item) {
  441. array_push($searchKeyword, $item['title']);
  442. }
  443. }
  444. return app('json')->successful($searchKeyword);
  445. }
  446. /**
  447. * 图片上传
  448. * @param Request $request
  449. * @return mixed
  450. * @throws \Psr\SimpleCache\InvalidArgumentException
  451. */
  452. public function upload_image(Request $request)
  453. {
  454. $data = UtilService::postMore([
  455. ['filename', 'file'],
  456. ], $request);
  457. if (!$data['filename']) return app('json')->fail('参数有误');
  458. if (Cache::has('start_uploads_' . $request->uid()) && Cache::get('start_uploads_' . $request->uid()) >= 100) return app('json')->fail('非法操作');
  459. $upload_type = sys_config('upload_type', 1);
  460. $upload = new Upload((int)$upload_type, [
  461. 'accessKey' => sys_config('accessKey'),
  462. 'secretKey' => sys_config('secretKey'),
  463. 'uploadUrl' => sys_config('uploadUrl'),
  464. 'storageName' => sys_config('storage_name'),
  465. 'storageRegion' => sys_config('storage_region'),
  466. ]);
  467. $info = $upload->to('store/comment')->validate()->move($data['filename']);
  468. if ($info === false) {
  469. return app('json')->fail($upload->getError());
  470. }
  471. $res = $upload->getUploadInfo();
  472. SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 1, $upload_type, $res['time'], 2);
  473. if (Cache::has('start_uploads_' . $request->uid()))
  474. $start_uploads = (int)Cache::get('start_uploads_' . $request->uid());
  475. else
  476. $start_uploads = 0;
  477. $start_uploads++;
  478. Cache::set('start_uploads_' . $request->uid(), $start_uploads, 86400);
  479. $res['dir'] = path_to_url($res['dir']);
  480. if (strpos($res['dir'], 'http') === false) $res['dir'] = $request->domain() . $res['dir'];
  481. return app('json')->successful('图片上传成功!', ['name' => $res['name'], 'url' => $res['dir']]);
  482. }
  483. /**
  484. * 物流公司
  485. * @return mixed
  486. */
  487. public function logistics()
  488. {
  489. $expressList = Express::lst();
  490. if (!$expressList) return app('json')->successful([]);
  491. return app('json')->successful($expressList->hidden(['code', 'id', 'sort', 'is_show'])->toArray());
  492. }
  493. /**
  494. * 短信购买异步通知
  495. *
  496. * @param Request $request
  497. * @return mixed
  498. */
  499. public function sms_pay_notify(Request $request)
  500. {
  501. list($order_id, $price, $status, $num, $pay_time, $attach) = UtilService::postMore([
  502. ['order_id', ''],
  503. ['price', 0.00],
  504. ['status', 400],
  505. ['num', 0],
  506. ['pay_time', time()],
  507. ['attach', 0],
  508. ], $request, true);
  509. if ($status == 200) {
  510. ChannelService::instance()->send('PAY_SMS_SUCCESS', ['price' => $price, 'number' => $num], [$attach]);
  511. return app('json')->successful();
  512. }
  513. return app('json')->fail();
  514. }
  515. /**
  516. * 记录用户分享
  517. * @param Request $request
  518. * @return mixed
  519. */
  520. public function user_share(Request $request)
  521. {
  522. return app('json')->successful(UserBill::setUserShare($request->uid()));
  523. }
  524. /**
  525. * 获取图片base64
  526. * @param Request $request
  527. * @return mixed
  528. */
  529. public function get_image_base64(Request $request)
  530. {
  531. list($imageUrl, $codeUrl) = UtilService::postMore([
  532. ['image', ''],
  533. ['code', ''],
  534. ], $request, true);
  535. try {
  536. $codeTmp = $code = $codeUrl ? image_to_base64($codeUrl) : false;
  537. if (!$codeTmp) {
  538. $putCodeUrl = put_image($codeUrl);
  539. $code = $putCodeUrl ? image_to_base64($_SERVER['HTTP_HOST'] . '/' . $putCodeUrl) : false;
  540. $code ?? unlink($_SERVER["DOCUMENT_ROOT"] . '/' . $putCodeUrl);
  541. }
  542. $imageTmp = $image = $imageUrl ? image_to_base64($imageUrl) : false;
  543. if (!$imageTmp) {
  544. $putImageUrl = put_image($imageUrl);
  545. $image = $putImageUrl ? image_to_base64($_SERVER['HTTP_HOST'] . '/' . $putImageUrl) : false;
  546. $image ?? unlink($_SERVER["DOCUMENT_ROOT"] . '/' . $putImageUrl);
  547. }
  548. return app('json')->successful(compact('code', 'image'));
  549. } catch (\Exception $e) {
  550. return app('json')->fail($e->getMessage());
  551. }
  552. }
  553. /**
  554. * 门店列表
  555. * @return mixed
  556. */
  557. public function store_list(Request $request)
  558. {
  559. list($latitude, $longitude, $page, $limit) = UtilService::getMore([
  560. ['latitude', ''],
  561. ['longitude', ''],
  562. ['page', 1],
  563. ['limit', 10]
  564. ], $request, true);
  565. $list = SystemStore::lst($latitude, $longitude, $page, $limit);
  566. if (!$list) $list = [];
  567. $data['list'] = $list;
  568. $data['tengxun_map_key'] = sys_config('tengxun_map_key');
  569. return app('json')->successful($data);
  570. }
  571. /**
  572. * 查找城市数据
  573. * @param Request $request
  574. * @return mixed
  575. */
  576. public function city_list(Request $request)
  577. {
  578. $list = CacheService::get('CITY_LIST', function () {
  579. $list = SystemCity::with('children')->field(['city_id', 'name', 'id', 'parent_id'])->where('parent_id', 0)->order('id asc')->select()->toArray();
  580. $data = [];
  581. foreach ($list as &$item) {
  582. $value = ['v' => $item['city_id'], 'n' => $item['name']];
  583. if ($item['children']) {
  584. foreach ($item['children'] as $key => &$child) {
  585. $value['c'][$key] = ['v' => $child['city_id'], 'n' => $child['name']];
  586. unset($child['id'], $child['area_code'], $child['merger_name'], $child['is_show'], $child['level'], $child['lng'], $child['lat'], $child['lat']);
  587. if (SystemCity::where('parent_id', $child['city_id'])->count()) {
  588. $child['children'] = SystemCity::where('parent_id', $child['city_id'])->field(['city_id', 'name', 'id', 'parent_id'])->select()->toArray();
  589. foreach ($child['children'] as $kk => $vv) {
  590. $value['c'][$key]['c'][$kk] = ['v' => $vv['city_id'], 'n' => $vv['name']];
  591. }
  592. }
  593. }
  594. }
  595. $data[] = $value;
  596. }
  597. return $data;
  598. }, 0);
  599. return app('json')->successful($list);
  600. }
  601. }