uid(), false);//TODO 精品推荐个数 $info['suitList'] = StoreProduct::getSuitProduct('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['storeList'] = StoreProduct::getStoreProduct('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['integralList'] = StoreProduct::getIntegralProduct('id,image,store_name,cate_id,price,ot_price,IFNULL(sales,0) + IFNULL(ficti,0) as sales,unit_name,max_use_integral', (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);//TODO 首页促销单品 $lovely = sys_data('routine_home_new_banner') ?: [];//TODO 首发新品顶部图 $likeInfo = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,ot_price,unit_name', 3);//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('filing_info', 'banner', 'menus', 'roll', 'info', 'activity', 'lovely', 'benefit', 'likeInfo', 'logoUrl', 'couponList', 'site_name', 'subscribe', 'newGoodsBananr', 'tengxun_map_key', 'explosive_money')); } /** * 获取分享配置 * @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 \think\db\exception\DataNotFoundException * @throws \think\db\exception\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 \think\db\exception\DataNotFoundException * @throws \think\db\exception\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); } /** * 门店列表 * @return mixed */ public function store_info($id, Request $request) { return app('json')->successful('ok', ['info' => SystemStore::get($id)]); } /** * 查找城市数据 * @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); } /** * 获取拼团数据 * @return mixed */ public function pink() { $data['pink_count'] = StorePink::where(['status' => 2, 'is_refund' => 0])->count(); $data['avatars'] = User::whereIn('uid', function ($query) { $query->name('store_pink')->where(['status' => 2, 'is_refund' => 0])->field(['uid'])->select(); })->limit(3)->order('uid desc')->column('avatar'); return app('json')->successful($data); } /** * 获取门店信息 * @param Request $request */ public function storeinfo(Request $request) { $id = input('id', 0); if (!SystemStore::be(['id' => $id])) return app('json')->fail('参数有误'); $info = SystemStore::find($id)->toArray(); $info['store_user'] = []; if ($info['uid'] > 0) $info['store_user'] = User::where('uid', $info['uid'])->field('nickname,avatar,uid')->find(); return app('json')->successful($info); } public function baidutoken() { // cache("baidu_token",0); if (!cache("baidu_token")) { $url = "https://openapi.baidu.com/oauth/2.0/token"; $data['grant_type'] = 'client_credentials'; $data['client_id'] = 'j7WG6EsXZyuVlbgTRGBFqTTf'; $data['client_secret'] = 'G2Ax5oI0Uq1MCk52GcEY0aAVTWTvbkvQ'; $rs = json_decode(file_get_contents($url . "?" . http_build_query($data)), true); cache("baidu_token", $rs, 2591999); } return app('json')->successful(cache("baidu_token")); } public function day() { $day = @file_get_contents("day.txt"); if (date("Y-m-d", $day) < date("Y-m-d", time())) { Db::query("call create_partition_cart()"); Db::query("call create_partition_order()"); Db::query("call create_partition_bill()"); } if (date("m-d", $day) < date("m-d", time()) && date("d", time()) == "1") { Db::query("call create_partition_user()"); Db::query("call create_partition_wechat_user()"); } echo "ok"; } public function gacha_set(Request $request) { $pay_way = sys_config('pay_way', 1, true); $pay_num = sys_config('pay_num', 1, true); $award = sys_data('gacha_set'); $sum_ratio = 0; foreach ($award as $k => $v) { $sum_ratio = $sum_ratio + $v['award_ratio']; unset($award[$k]['limit_time']); } return app('json')->success('ok', compact('pay_way', 'pay_num', 'award', 'sum_ratio')); } public function gacha(Request $request) { $pay_way = sys_config('pay_way', 1, true); $pay_num = sys_config('pay_num', 1, true); if ($pay_way == 1) { $pay_way = 'integral'; } else if ($pay_way == 2) { $pay_way = 'now_money'; } else { return app('json')->fail('抽奖尚未开启'); } $user = User::get($request->uid()); $award = sys_data('gacha_set'); $sum_ratio = 0; $times = Gacha::where('uid', $user['uid'])->count(); $real_award = []; foreach ($award as $v) { if ($times >= $v['limit_time']) { $sum_ratio = $sum_ratio + $v['award_ratio']; $real_award[] = $v; } } if ($sum_ratio < 1) { return app('json')->fail('抽奖尚未开启'); } if ($user[$pay_way] < $pay_num) return app('json')->fail('余额不足'); User::beginTrans(); try { $res = User::bcDec($user['uid'], $pay_way, $pay_num, 'uid'); $bill_res = UserBill::expend('抽奖支付', $user['uid'], $pay_way, 'gacha_pay', $pay_num, 0, bcsub($user[$pay_way], $pay_num, 2), '参与抽奖支付'); if (!($res && $bill_res)) return app('json')->fail('支付失败'); $award_gacha = rand(1, $sum_ratio); foreach ($real_award as $v) { if ($award_gacha <= $v['award_ratio']) { $gacha = $v; break; } $award_gacha -= $v['award_ratio']; } $gacha_res = Gacha::create([ 'award' => $gacha['awatd'], 'uid' => $user['uid'], 'award_type' => $gacha['award_type'], 'add_time' => time(), 'limit_time' => time() + ($gacha['award_time'] * 24 * 3600), 'unicode' => Gacha::createCode($user['uid']) ]); UserBill::where('id', $bill_res['id'])->update(['link_id' => $gacha_res['id']]); User::commitTrans(); return app('json')->success('ok', $gacha_res); } catch (\Exception $e) { User::rollbackTrans(); return app('json')->fail($e->getMessage()); } } public function gacha_log(Request $request) { $page = $request->get('page', 1); $limit = $request->get('limit', 10); $status = $request->get('status', ''); $where['uid'] = $request->uid(); if ($status != '') { $where['status'] = $status; } $list = Gacha::where($where)->page($page, $limit)->select(); $count = Gacha::where($where)->count(); return app('json')->success('ok', compact('list', 'count')); } public function get_award($id, Request $request) { $info = Gacha::get($id); if ($info['uid'] != $request->uid()) return app('json')->fail('奖励不存在'); if ($info['status'] != 0) return app('json')->fail('奖品已兑换'); if ($info['limit_time'] < time()) return app('json')->fail('奖品兑换期已过'); if ($info['award_type'] == 2) return app('json')->fail('实物奖品请往线下兑换点兑奖'); User::beginTrans(); try { User::bcInc($request->uid(), 'integral', $info['award'], 'uid'); UserBill::expend('抽奖奖品', $request->uid(), 'integral', 'gacha_get', $info['award'], $info['id'], User::where('uid', $request->uid())->value('integral'), '抽奖奖品兑换'); Gacha::where('id', $id)->update(['status' => 1]); User::commitTrans(); return app('json')->success('兑换成功'); } catch (\Exception $e) { User::rollbackTrans(); return app('json')->fail($e->getMessage()); } } }