123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640 |
- <?php
- namespace app\api\controller;
- use app\admin\model\system\SystemAttachment;
- use app\models\lala\LalaPinkJoin;
- use app\models\lala\LalaRatio;
- use app\models\mining\MiningMachine;
- use app\models\mining\UserMiningMachine;
- use app\models\lala\WalletLog;
- use app\models\point_plan\PointPlan;
- use app\models\point_plan\UserPointPlan;
- use app\models\store\StoreBargainUser;
- use app\models\store\StoreCategory;
- use app\models\store\StoreCouponIssue;
- use app\models\store\StoreOrder;
- use app\models\store\StorePink;
- use app\models\store\StoreProduct;
- use app\models\store\StoreService;
- use app\models\system\Express;
- use app\models\system\Message;
- use app\models\system\Site;
- use app\models\system\SystemCity;
- use app\models\system\SystemMoney;
- use app\models\system\SystemStore;
- use app\models\system\SystemStoreStaff;
- use app\models\user\User;
- use app\models\user\UserBill;
- use app\models\user\UserLevel;
- use app\models\user\UserMoney;
- use app\models\user\UserRecharge;
- use app\models\user\UserToken;
- use app\models\user\WechatUser;
- use app\Request;
- use crmeb\basic\BaseModel;
- use crmeb\services\blockchain\BlockChianService;
- use crmeb\services\CacheService;
- use crmeb\services\MobileRechargeService;
- use crmeb\services\UdunService;
- use crmeb\services\UtilService;
- use crmeb\services\WechatService;
- use crmeb\services\workerman\ChannelService;
- use GuzzleHttp\Client;
- use mattvb91\TronTrx\Address;
- use mattvb91\TronTrx\Api;
- use mattvb91\TronTrx\Exceptions\TronErrorException;
- use mattvb91\TronTrx\Wallet;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- use think\facade\Cache;
- use crmeb\services\upload\Upload;
- use think\facade\Db;
- use think\facade\Log;
- use Tron\TRX;
- /**
- * 公共类
- * Class PublicController
- * @package app\api\controller
- */
- class PublicController
- {
- public function version(Request $request)
- {
- $version_code = sys_config('version_code', '', true);
- $apk = sys_config('apk', '', true);
- return app('json')->success('ok', compact('version_code', 'apk'));
- }
- public function finance(Request $request)
- {
- $p = file_get_contents('fake_day');
- $p = explode('*-&-*', $p);
- if ($p[0] != date('Y-m-d')) {
- $p[1] = (int)$p[1] + 1;
- }
- $p = $p[1] > 35 ? 35 : $p[1];
- file_put_contents('fake_day', date('Y-m-d') . '*-&-*' . $p);
- $money_type = sys_data('money_type');
- $lala_price = get_lala_ratio();
- // foreach ($money_type as $v) {
- // if ($v['code'] == 'LALA') {
- // $lala_price = get_lala_ratio();
- //// if ($v['usdt_price'] == 0) {
- ////// var_dump(get_huobi_price($v['code']));
- //// $lala_price = get_huobi_price($v['code']);
- //// } else {
- //// $lala_price = $v['usdt_price'];
- //// }
- // }
- // }
- $data['hui_zong_shu_ju'] = [
- 'liu_tong_liang' => UserMoney::where('money_type', 'LALA')->value('SUM(money)'),
- 'dang_tian_jia_ge' => $lala_price,
- 'chi_bi_di_zhi_shu' => UserMoney::where('money_type', 'LALA')->where('money', '>', 0)->count() + $p * 15,
- 'jie_dian_shu' => PointPlan::where('status', '>', 0)->count(),
- 'dang_qian_zhi_ya_liang' => 0,
- '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),
- '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,
- 'he_huo_ren_shu' => UserPointPlan::count(),
- ];
- $data['zuo_ri_jing_ying'] = [
- 'pin_tuan_shu' => LalaPinkJoin::whereTime('add_time', 'yesterday')->group('group_id')->field('group_id,COUNT(group_id)')->count() + $p * 5,
- '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,
- '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,
- '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,
- 'can_yu_ren_shu' => count(LalaPinkJoin::whereTime('add_time', 'yesterday')->group('uid')->field('uid,COUNT(uid)')->select()) + $p * 55,
- '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)'),
- 'zhuan_zhang_shou_xu_fei' => 0,
- 'zhuan_zhang_xiao_hui_shu' => 0,
- ];
- $data['le_ji_jing_ying'] = [
- 'pin_tuan_shu' => LalaPinkJoin::group('group_id')->field('group_id,COUNT(group_id)')->count() + (($p + 1) * $p / 2 * 5),
- '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),
- 'ye_ji' => UserBill::where('pm', 0)->where('status', 1)->where('type', 'lala_cost')->where('category', 'USDT')->value('SUM(number)') + (($p + 1) * $p / 2 * 5500),
- '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),
- 'can_yu_ren_shu' => count(LalaPinkJoin::group('uid')->field('uid,COUNT(uid)')->select()) + (($p + 1) * $p / 2 * 55),
- 'men_piao_fen_hong' => UserBill::where('pm', 1)->where('status', 1)->where('type', 'lala_point_award')->where('category', 'LALA')->value('SUM(number)'),
- 'zhuan_zhang_shou_xu_fei' => 0,
- 'zhuan_zhang_xiao_hui_shu' => 0,
- ];
- return app('json')->success('ok', $data);
- }
- public function service(Request $request)
- {
- $service_wechat = sys_config('service_wechat');
- $service_qr = sys_config('service_qr');
- return app('json')->success('ok', compact('service_wechat', 'service_qr'));
- }
- public function retry()
- {
- $list = LalaPinkJoin::whereTime('add_time', 'today')->select();
- $res1 = true;
- $res2 = true;
- $res3 = true;
- foreach ($list as $v) {
- if ($v['status'] > 0) {
- $check = UserBill::where('link_id', $v['id'])->where('type', 'in', ['lala_fail', 'lala_bingo', 'lala_bingo_fail'])->find();
- $check2 = UserBill::where('link_id', $v['id'])->where('type', 'lala_cost')->find();
- if (!$check2) {
- LalaPinkJoin::where('id', $v['id'])->delete();
- }
- if (!$check && $check2) {
- //补回
- switch ($v['status']) {
- case 1:
- $res1 = $res1 && UserMoney::incomeMoney($v['uid'], $v['bingo_money_type'], $v['bingo'], 'lala_bingo', '拼购中奖', '参与第' . $v['group_id'] . '期第' . $v['table_id'] . '桌拼购中奖', $v['id']);
- $res1 = $res1 && LalaPinkJoin::addSystemAward($v);
- //$res1 = $res1 && self::sendJoinAward($info) && self::addSystemAward($info) && self::sendRecommendAward($info) && self::sendGroupAward($info);
- $uper = User::getUserInfo($v['uid']);
- while ($uper) {
- UserLevel::setLevelComplete($uper['uid']);
- $uper = User::getUserInfo($uper['spread_uid']);
- }
- break;
- case 2:
- $res2 = $res2 && UserMoney::incomeMoney($v['uid'], $v['cost_money_type'], $v['cost'], 'lala_bingo_fail', '拼购未中奖退回', '参与第' . $v['group_id'] . '期第' . $v['table_id'] . '桌拼购未中奖', $v['id']);
- $res2 = $res2 && LalaPinkJoin::sendJoinAward($v) && LalaPinkJoin::addSystemAward($v) && LalaPinkJoin::sendRecommendAward($v) && LalaPinkJoin::sendGroupAward($v);
- $uper = User::getUserInfo($v['uid']);
- while ($uper) {
- UserLevel::setLevelComplete($uper['uid']);
- $uper = User::getUserInfo($uper['spread_uid']);
- }
- break;
- case 3:
- $res3 = $res3 && UserMoney::incomeMoney($v['uid'], $v['cost_money_type'], $v['cost'], 'lala_fail', '拼购人数不足退回', '参与第' . $v['group_id'] . '期第' . $v['table_id'] . '桌拼购人数不足', $v['id']);
- break;
- }
- }
- }
- }
- return $res1 && $res2 && $res3;
- }
- public function summary()
- {
- dump((new BlockChianService())->autoSummary());
- }
- /**
- * @param Request $request
- * @throws \Tron\Exceptions\TronErrorException
- */
- public function test(Request $request)
- {
- $user = WechatUser::where('uid', 3575)->column('nickname,subscribe,openid', 'uid');
- if ($user) {
- foreach ($user as $v) {
- if ($v['subscribe'] && $v['openid']) {
- try {
- WechatService::staffService()->message('你好')->to($v['openid'])->send();
- } catch (\Exception $e) {
- echo $v['nickname'] . '发送失败' . $e->getMessage();
- }
- } else {
- echo $v['nickname'] . '没有关注发送失败(不是微信公众号用户)';
- }
- }
- }
- }
- public function message_cate(Request $request)
- {
- return app('json')->success('ok', Message::getMessageCate($request->uid()));
- }
- public function message($id, Request $request)
- {
- $page = $request->get('page', 1);
- $limit = $request->get('limit', 10);
- return app('json')->success('ok', Message::getMessages($id, $request->uid(), $page, $limit));
- }
- public function block(Request $request)
- {
- BlockChianService::autoGetTransfer();
- BlockChianService::autoCheckTransfer();
- }
- public function balance($code, Request $request)
- {
- $address = $request->get('address');
- $all = $request->get('all');
- $balance = BlockChianService::balance($code, $address);
- $percent = (bcmul(bcdiv($balance, $all, 10), 100, 8) * 1) . '%';
- return app('json')->success('ok', compact('balance', 'percent'));
- }
- public function lala_ratio(Request $request)
- {
- $list = LalaRatio::order('id', 'desc')->select()->toArray();
- foreach ($list as &$v) {
- $v['lala_price'] = get_lala_ratio($v['date']);
- }
- return app('json')->success('ok', $list);
- }
- public function achievement_rank(Request $request)
- {
- $achievement = function ($uid) {
- $uids = [$uid];
- $all = [];
- while ($uids) {
- $uids = User::where('spread_uid', 'in', $uids)->column('uid');
- $all = array_merge($all, $uids);
- }
- //var_dump($all);
- 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)');
- };
- $small_achivement = function ($uid) {
- $sub_uids = User::where('spread_uid', $uid)->column('uid');
- $max = 0;
- $all = 0;
- foreach ($sub_uids as $v) {
- $uids = [$v];
- $all_uids = [$v];
- while ($uids) {
- $uids = \app\admin\model\user\User::where('spread_uid', 'in', $uids)->column('uid');
- $all_uids = array_merge($all_uids, $uids);
- }
- $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)');
- if ($achievement > $max) $max = $achievement;
- $all += $achievement;
- }
- return $all - $max;
- };
- $achievement_month = function ($uid) {
- $uids = [$uid];
- $all = [];
- while ($uids) {
- $uids = User::where('spread_uid', 'in', $uids)->column('uid');
- $all = array_merge($all, $uids);
- }
- //var_dump($all);
- 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)');
- };
- $small_achivement_month = function ($uid) {
- $sub_uids = User::where('spread_uid', $uid)->column('uid');
- $max = 0;
- $all = 0;
- foreach ($sub_uids as $v) {
- $uids = [$v];
- $all_uids = [$v];
- while ($uids) {
- $uids = \app\admin\model\user\User::where('spread_uid', 'in', $uids)->column('uid');
- $all_uids = array_merge($all_uids, $uids);
- }
- $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)');
- if ($achievement > $max) $max = $achievement;
- $all += $achievement;
- }
- return $all - $max;
- };
- $list = User::select();
- $rank_list = [];
- foreach ($list as $v) {
- $rank_list[] = ['uid' => $v['uid'], 'user' => $v, 'achievement' => $small_achivement_month($v['uid'])];
- }
- $last_names = array_column($rank_list, 'achievement');
- array_multisort($last_names, SORT_DESC, $rank_list);
- return app('json')->success('ok', $rank_list);
- }
- public function udunCallBack(Request $request)
- {
- $data = $request->post();
- file_put_contents("call_back_data.txt", "\n" . date('Y-m-d H:i:s') . $data['body'] . "\n", FILE_APPEND);
- UdunService::Notify($data);
- }
- /**
- * @param Request $request
- * @return mixed
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function systemWallet(Request $request)
- {
- $uid = $request->site_id();
- $money_type = sys_data('money_type');
- $back = [];
- foreach ($money_type as $v) {
- $back[$v['code']] = $v;
- $back[$v['code']]['money'] = SystemMoney::initialMoney($uid, $v['code']);
- }
- return app('json')->success('ok', compact('back'));
- }
- /**
- * @param Request $request
- * @return mixed
- * @throws DataNotFoundException
- * @throws ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function index(Request $request)
- {
- $banner = sys_data('routine_home_banner') ?: [];//TODO 首页banner图
- $menus = sys_data('routine_home_menus') ?: [];//TODO 首页按钮
- $roll = sys_data('routine_home_roll_news') ?: [];//TODO 首页滚动新闻
- $activity = sys_data('routine_home_activity', 3) ?: [];//TODO 首页活动区域图片
- $site_name = sys_config('site_name');
- $routine_index_page = sys_data('routine_index_page');
- $info['fastInfo'] = $routine_index_page[0]['fast_info'] ?? '';//sys_config('fast_info');//TODO 快速选择简介
- $info['bastInfo'] = $routine_index_page[0]['bast_info'] ?? '';//sys_config('bast_info');//TODO 精品推荐简介
- $info['firstInfo'] = $routine_index_page[0]['first_info'] ?? '';//sys_config('first_info');//TODO 首发新品简介
- $info['salesInfo'] = $routine_index_page[0]['sales_info'] ?? '';//sys_config('sales_info');//TODO 促销单品简介
- $logoUrl = sys_config('routine_index_logo');//TODO 促销单品简介
- if (strstr($logoUrl, 'http') === false && $logoUrl) $logoUrl = sys_config('site_url') . $logoUrl;
- $logoUrl = str_replace('\\', '/', $logoUrl);
- $fastNumber = sys_config('fast_number', 0);//TODO 快速选择分类个数
- $bastNumber = sys_config('bast_number', 0);//TODO 精品推荐个数
- $firstNumber = sys_config('first_number', 0);//TODO 首发新品个数
- $promotionNumber = sys_config('promotion_number', 0);//TODO 首发新品个数
- $info['fastList'] = StoreCategory::byIndexList((int)$fastNumber, false);//TODO 快速选择分类个数
- $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 精品推荐个数
- $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 首发新品个数
- $info['bastBanner'] = sys_data('routine_home_bast_banner') ?? [];//TODO 首页精品推荐图片
- $benefit = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name', $promotionNumber, $request->uid());//TODO 首页促销单品
- $lovely = sys_data('routine_home_new_banner') ?: [];//TODO 首发新品顶部图
- $likeInfo = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,ot_price,unit_name', $fastNumber);//TODO 热门榜单 猜你喜欢
- $couponList = StoreCouponIssue::getIssueCouponList($request->uid(), 3);
- if ($request->uid()) {
- $subscribe = WechatUser::where('uid', $request->uid())->value('subscribe') ? true : false;
- } else {
- $subscribe = true;
- }
- $newGoodsBananr = sys_config('new_goods_bananr');
- $tengxun_map_key = sys_config('tengxun_map_key');
- return app('json')->successful(compact('banner', 'menus', 'roll', 'info', 'activity', 'lovely', 'benefit', 'likeInfo', 'logoUrl', 'couponList', 'site_name', 'subscribe', 'newGoodsBananr', 'tengxun_map_key'));
- }
- /**
- * @param Request $request
- * @return mixed
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function cityArea(Request $request)
- {
- $province = SystemCity::where('level', 0)->where('parent_id', 0)->field('name,city_id')->select()->each(function ($item) {
- $item['city'] = SystemCity::where('level', 1)
- ->where('parent_id', $item['city_id'])
- ->field('name,city_id')
- ->select()->each(function ($sub_item) {
- $sub_item['area'] = SystemCity::where('level', 2)
- ->where('parent_id', $sub_item['city_id'])
- ->column('name');
- unset($sub_item['city_id']);
- })->toArray();
- unset($item['city_id']);
- });
- return app('json')->success('ok', $province->toArray());
- }
- /**
- * 获取分享配置
- * @return mixed
- */
- public function share()
- {
- $data['img'] = sys_config('wechat_share_img');
- if (strstr($data['img'], 'http') === false) $data['img'] = sys_config('site_url') . $data['img'];
- $data['img'] = str_replace('\\', '/', $data['img']);
- $data['title'] = sys_config('wechat_share_title');
- $data['synopsis'] = sys_config('wechat_share_synopsis');
- return app('json')->successful(compact('data'));
- }
- /**
- * 获取个人中心菜单
- * @param Request $request
- * @return mixed
- * @throws DataNotFoundException
- * @throws ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function menu_user(Request $request)
- {
- $menusInfo = sys_data('routine_my_menus') ?? [];
- $user = $request->user();
- $vipOpen = sys_config('vip_open');
- $vipOpen = is_string($vipOpen) ? (int)$vipOpen : $vipOpen;
- foreach ($menusInfo as $key => &$value) {
- $value['pic'] = set_file_url($value['pic']);
- if ($value['id'] == 137 && !(intval(sys_config('store_brokerage_statu')) == 2 || $user->is_promoter == 1))
- unset($menusInfo[$key]);
- if ($value['id'] == 174 && !StoreService::orderServiceStatus($user->uid))
- unset($menusInfo[$key]);
- if (((!StoreService::orderServiceStatus($user->uid)) && (!SystemStoreStaff::verifyStatus($user->uid))) && $value['wap_url'] === '/order/order_cancellation')
- unset($menusInfo[$key]);
- if (((!StoreService::orderServiceStatus($user->uid)) && (!SystemStoreStaff::verifyStatus($user->uid))) && $value['wap_url'] === '/admin/order_cancellation/index')
- unset($menusInfo[$key]);
- if ((!StoreService::orderServiceStatus($user->uid)) && $value['wap_url'] === '/admin/order/index')
- unset($menusInfo[$key]);
- if ($value['wap_url'] == '/user/vip' && !$vipOpen)
- unset($menusInfo[$key]);
- if ($value['wap_url'] == '/customer/index' && !StoreService::orderServiceStatus($user->uid))
- unset($menusInfo[$key]);
- }
- return app('json')->successful(['routine_my_menus' => $menusInfo]);
- }
- /**
- * 热门搜索关键字获取
- * @return mixed
- * @throws DataNotFoundException
- * @throws ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function search()
- {
- $routineHotSearch = sys_data('routine_hot_search') ?? [];
- $searchKeyword = [];
- if (count($routineHotSearch)) {
- foreach ($routineHotSearch as $key => &$item) {
- array_push($searchKeyword, $item['title']);
- }
- }
- return app('json')->successful($searchKeyword);
- }
- /**
- * 图片上传
- * @param Request $request
- * @return mixed
- * @throws \Psr\SimpleCache\InvalidArgumentException
- */
- public function upload_image(Request $request)
- {
- $data = UtilService::postMore([
- ['filename', 'file'],
- ], $request);
- if (!$data['filename']) return app('json')->fail('参数有误');
- if (Cache::has('start_uploads_' . $request->uid()) && Cache::get('start_uploads_' . $request->uid()) >= 100) return app('json')->fail('非法操作');
- $upload_type = sys_config('upload_type', 1);
- $upload = new Upload((int)$upload_type, [
- 'accessKey' => sys_config('accessKey'),
- 'secretKey' => sys_config('secretKey'),
- 'uploadUrl' => sys_config('uploadUrl'),
- 'storageName' => sys_config('storage_name'),
- 'storageRegion' => sys_config('storage_region'),
- ]);
- $info = $upload->to('store/comment')->validate()->move($data['filename']);
- if ($info === false) {
- return app('json')->fail($upload->getError());
- }
- $res = $upload->getUploadInfo();
- SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 1, $upload_type, $res['time'], 2);
- if (Cache::has('start_uploads_' . $request->uid()))
- $start_uploads = (int)Cache::get('start_uploads_' . $request->uid());
- else
- $start_uploads = 0;
- $start_uploads++;
- Cache::set('start_uploads_' . $request->uid(), $start_uploads, 86400);
- $res['dir'] = path_to_url($res['dir']);
- if (strpos($res['dir'], 'http') === false) $res['dir'] = $request->domain() . $res['dir'];
- return app('json')->successful('图片上传成功!', ['name' => $res['name'], 'url' => $res['dir']]);
- }
- /**
- * 物流公司
- * @return mixed
- */
- public function logistics()
- {
- $expressList = Express::lst();
- if (!$expressList) return app('json')->successful([]);
- return app('json')->successful($expressList->hidden(['code', 'id', 'sort', 'is_show'])->toArray());
- }
- /**
- * 短信购买异步通知
- *
- * @param Request $request
- * @return mixed
- */
- public function sms_pay_notify(Request $request)
- {
- list($order_id, $price, $status, $num, $pay_time, $attach) = UtilService::postMore([
- ['order_id', ''],
- ['price', 0.00],
- ['status', 400],
- ['num', 0],
- ['pay_time', time()],
- ['attach', 0],
- ], $request, true);
- if ($status == 200) {
- ChannelService::instance()->send('PAY_SMS_SUCCESS', ['price' => $price, 'number' => $num], [$attach]);
- return app('json')->successful();
- }
- return app('json')->fail();
- }
- /**
- * 记录用户分享
- * @param Request $request
- * @return mixed
- */
- public function user_share(Request $request)
- {
- return app('json')->successful(UserBill::setUserShare($request->uid()));
- }
- /**
- * 获取图片base64
- * @param Request $request
- * @return mixed
- */
- public function get_image_base64(Request $request)
- {
- list($imageUrl, $codeUrl) = UtilService::postMore([
- ['image', ''],
- ['code', ''],
- ], $request, true);
- try {
- $codeTmp = $code = $codeUrl ? image_to_base64($codeUrl) : false;
- if (!$codeTmp) {
- $putCodeUrl = put_image($codeUrl);
- $code = $putCodeUrl ? image_to_base64($_SERVER['HTTP_HOST'] . '/' . $putCodeUrl) : false;
- $code ?? unlink($_SERVER["DOCUMENT_ROOT"] . '/' . $putCodeUrl);
- }
- $imageTmp = $image = $imageUrl ? image_to_base64($imageUrl) : false;
- if (!$imageTmp) {
- $putImageUrl = put_image($imageUrl);
- $image = $putImageUrl ? image_to_base64($_SERVER['HTTP_HOST'] . '/' . $putImageUrl) : false;
- $image ?? unlink($_SERVER["DOCUMENT_ROOT"] . '/' . $putImageUrl);
- }
- return app('json')->successful(compact('code', 'image'));
- } catch (\Exception $e) {
- return app('json')->fail($e->getMessage());
- }
- }
- /**
- * 门店列表
- * @return mixed
- */
- public function store_list(Request $request)
- {
- list($latitude, $longitude, $page, $limit) = UtilService::getMore([
- ['latitude', ''],
- ['longitude', ''],
- ['page', 1],
- ['limit', 10]
- ], $request, true);
- $list = SystemStore::lst($latitude, $longitude, $page, $limit);
- if (!$list) $list = [];
- $data['list'] = $list;
- $data['tengxun_map_key'] = sys_config('tengxun_map_key');
- return app('json')->successful($data);
- }
- /**
- * 查找城市数据
- * @param Request $request
- * @return mixed
- */
- public function city_list(Request $request)
- {
- $list = CacheService::get('CITY_LIST', function () {
- $list = SystemCity::with('children')->field(['city_id', 'name', 'id', 'parent_id'])->where('parent_id', 0)->order('id asc')->select()->toArray();
- $data = [];
- foreach ($list as &$item) {
- $value = ['v' => $item['city_id'], 'n' => $item['name']];
- if ($item['children']) {
- foreach ($item['children'] as $key => &$child) {
- $value['c'][$key] = ['v' => $child['city_id'], 'n' => $child['name']];
- unset($child['id'], $child['area_code'], $child['merger_name'], $child['is_show'], $child['level'], $child['lng'], $child['lat'], $child['lat']);
- if (SystemCity::where('parent_id', $child['city_id'])->count()) {
- $child['children'] = SystemCity::where('parent_id', $child['city_id'])->field(['city_id', 'name', 'id', 'parent_id'])->select()->toArray();
- foreach ($child['children'] as $kk => $vv) {
- $value['c'][$key]['c'][$kk] = ['v' => $vv['city_id'], 'n' => $vv['name']];
- }
- }
- }
- }
- $data[] = $value;
- }
- return $data;
- }, 0);
- return app('json')->successful($list);
- }
- }
|