<?php
namespace App\Http\Controllers\Api;
use App\Handlers\WechatConfigHandler;
use App\Models\About;
use App\Models\Cms\Article;
use App\Models\Cms\Chapter;
use App\Models\Cms\CollectArticle;
use App\Models\Config;
use App\Models\Customer;
use App\Models\Feedback;
use App\Models\JoinUs;
use App\Models\Shop\Address;
use App\Models\Shop\Brand;
use App\Models\Shop\Cart;
use App\Models\Shop\Category;
use App\Models\Shop\CollectProduct;
use App\Models\Shop\Coupon;
use App\Models\Shop\CustomerCoupon;
use App\Models\Shop\Order;
use App\Models\Shop\Product;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use App\Handlers\WXBizDataCrypt;
use Illuminate\Support\Facades\DB;
class IndexController extends Controller
{
protected $wechat;
public function __construct(WechatConfigHandler $wechat)
{
$this->wechat = $wechat;
}
public function auth(Request $request)
{
//声明CODE,获取小程序传过来的CODE
$code = $request->code;
//配置appid
$appid = env('WECHAT_OFFICIAL_ACCOUNT_APPID', '');
//配置appscret
$secret = env('WECHAT_OFFICIAL_ACCOUNT_SECRET', '');
//api接口
$api = "https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$secret}&js_code={$code}&grant_type=authorization_code";
$str = json_decode($this->httpGet($api), true);
$openid = $str['openid'];
/* $sessionKey = $str['session_key'];
session('sessionKey', $sessionKey); */
$customer = Customer::where('openid', $openid)->first();
if ($customer) {
$customer->update([
'openid' => $openid,
'headimgurl' => $request->headimgurl,
'nickname' => $request->nickname,
'tel' => $request->tel,
'sex' => $request->sex,
]);
} else {
Customer::create([
'openid' => $openid,
'headimgurl' => $request->headimgurl,
'nickname' => $request->nickname,
'tel' => $request->tel,
'sex' => $request->sex,
]);
}
return $this->success_data('授权成功', $str);
}
/**
* 更新获取用户绑定手机号
* @param Request $request
* @return number[]|unknown[]|string[]
*/
public function updateCustomerPhone(Request $request){
$appid = env('WECHAT_OFFICIAL_ACCOUNT_APPID', '');
$openid = $request->openid ? $request->openid : 'osJCDuBE6RgIJV8lv1dDq8K4B5eU';
if (!$openid) {
return $this->error_data('用户不存在');
}
$customer = Customer::where('openid', $openid)->first();
$encryptedData = $request->encryptedData;
$iv = $request->iv;
$sessionKey = $request->sessionKey;
$pc = new WXBizDataCrypt($appid, $sessionKey);
$errCode = $pc->decryptData($encryptedData, $iv, $data );
if ($errCode == 0) {
$infoArr = json_decode($data,true);
$tel = $infoArr['phoneNumber'];
$customer->update([
'tel' => $tel
]);
return $this->success_data('授权成功',$customer);
} else {
return $this->error_data($errCode);
}
}
//获取GET请求
function httpGet($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_URL, $url);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}
public function configs()
{
$configs = Config::first();
return $this->success_data('系统信息', $configs);
}
public function index(Request $request)
{
//品类
$categories = Category::where('parent_id', '>', 0)->where('is_top', 1)->orderby('sort_order', 'asc')->limit(3)->get();
if (!empty($categories)) {
foreach ($categories as &$category) {
$category['image']=$category['top_image'];
}
}
//轮播
$banner = Config::first()->banner;
$image = Config::first()->image;
//品牌
$brand = Brand::first();
$openid = $request->openid ? $request->openid : 'osJCDuBE6RgIJV8lv1dDq8K4B5eU';
if (!$openid) {
return $this->error_data('用户不存在');
}
$customer = Customer::where('openid', $openid)->first();
$grade = $customer ? $customer->grade : 1;
$price = 'price_' . $grade;
$show = 'show_' . $grade;
//热销
$hot = Product::where('is_show', true)->where('is_hot', true)->where($show, 1)->orderby('sort_order', 'asc')->get()->map(function ($model) use ($price) {
$model['price'] = $model[$price];
return $model;
});
//推荐
$recommend = Product::where('is_show', true)->where('is_recommend', true)->where($show, 1)->orderby('sort_order', 'asc')->get()->map(function ($model) use ($price) {
$model['price'] = $model[$price];
return $model;
});
return $this->success_data('首页', ['categories' => $categories, 'banner' => $banner, 'image' => $image, 'brand' => $brand, 'hot' => $hot, 'recommend' => $recommend, 'customer' => $customer]);
}
public function categories()
{
$categories = Category::with(['children' => function ($query) {
$query->orderby('sort_order')->get();
}])->where('parent_id', 0)->orderby('sort_order')->get();
$banner = Config::find(1)->value('shop_banner');
return $this->success_data('商品分类', ['banner'=>$banner, 'categories' => $categories]);
}
public function brand()
{
$brand = Brand::first();
return $this->success_data('品牌详情', $brand);
}
public function products(Request $request)
{
$openid = $request->openid ? $request->openid : 'osJCDuBE6RgIJV8lv1dDq8K4B5eU';
if (!$openid) {
return $this->error_data('用户不存在');
}
$customer = Customer::where('openid', $openid)->first();
$grade = $customer ? $customer->grade : 1;
$price = 'price_' . $grade;
$show = 'show_' . $grade;
//多条件查找
$where = function ($query) use ($request) {
$query->where('is_show', true);
if ($request->has('category_id') and $request->category_id != '') {
$query->where('category_id', $request->category_id);
}
if ($request->has('is_new') and $request->is_new != '') {
$query->where('is_new', true);
}
if ($request->has('is_hot') and $request->is_hot != '') {
$query->where('is_hot', true);
}
if ($request->has('is_recommend') and $request->is_recommend != '') {
$query->where('is_recommend', true);
}
};
$products = Product::where($where)->where($show, 1)->orderby('sort_order', 'asc')->paginate($request->total);
if ($request->has('sale_num') and $request->sale_num != '') {
$products = Product::where($where)->where($show, 1)->orderby('sale_num', 'desc')->paginate($request->total);
}
if ($request->has('price_desc') and $request->price_desc != '') {
$products = Product::where($where)->where($show, 1)->orderby($price, 'desc')->paginate($request->total);
}
if ($request->has('price_asc') and $request->price_asc != '') {
$products = Product::where($where)->where($show, 1)->orderby($price, 'asc
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于PHP开发的灯具直播商城系统源码.zip 基于PHP开发的灯具直播商城系统源码.zip 基于PHP开发的灯具直播商城系统源码.zip 【备注】 主要针对计算机相关专业的正在做毕设的学生和需要项目实战的PHP学习者。 也可作为课程设计、期末大作业。包含:项目源码、数据库脚本、项目说明等,该项目可以直接作为毕设使用。 也可以用来学习参考借鉴!
资源推荐
资源详情
资源评论
收起资源包目录
基于PHP开发的灯具直播商城系统源码.zip (923个子文件)
1597056913png 95KB
1597056941tmp 95KB
1597056966png 13KB
artisan 2KB
.buildpath 169B
web.config 914B
app.css 153KB
bootstrap.min.css 122KB
AdminLTE.min.css 89KB
ueditor.css 43KB
_all-skins.min.css 41KB
ueditor.min.css 34KB
sweetalert2.css 34KB
font-awesome.min.css 30KB
_all.css 21KB
video-js.css 21KB
bootstrap-editable.css 21KB
image.css 18KB
_all.css 15KB
select2.min.css 15KB
video.css 15KB
attachment.css 14KB
_all.css 14KB
_all.css 13KB
video-js.min.css 11KB
fileinput.min.css 8KB
bootstrap-datetimepicker.min.css 8KB
shCoreDefault.css 7KB
toastr.min.css 6KB
bootstrap-switch.min.css 6KB
fontawesome-iconpicker.min.css 6KB
slider.css 4KB
skin-black-light.min.css 4KB
skin-blue-light.min.css 4KB
skin-yellow-light.min.css 4KB
skin-purple-light.min.css 4KB
scrawl.css 4KB
skin-green-light.min.css 4KB
skin-red-light.min.css 4KB
skin-black.min.css 3KB
bootstrap-colorpicker.min.css 3KB
ion.rangeSlider.css 3KB
skin-blue.min.css 3KB
index.css 3KB
skin-purple.min.css 3KB
skin-yellow.min.css 3KB
skin-green.min.css 3KB
skin-red.min.css 3KB
codemirror.css 3KB
charts.css 3KB
fonts.css 2KB
background.css 2KB
purple.css 2KB
yellow.css 2KB
orange.css 2KB
green.css 2KB
grey.css 2KB
blue.css 2KB
aero.css 2KB
pink.css 2KB
red.css 2KB
base.css 2KB
line.css 2KB
ion.rangeSlider.skinFlat.css 2KB
order.css 2KB
emotion.css 2KB
bootstrap-duallistbox.min.css 2KB
ion.rangeSlider.skinNice.css 2KB
dialogbase.css 2KB
music.css 2KB
purple.css 2KB
yellow.css 2KB
orange.css 2KB
purple.css 2KB
yellow.css 2KB
orange.css 2KB
green.css 2KB
green.css 2KB
pink.css 2KB
grey.css 2KB
blue.css 2KB
aero.css 2KB
laravel-admin.css 2KB
pink.css 2KB
grey.css 2KB
blue.css 2KB
aero.css 2KB
red.css 2KB
red.css 2KB
all.css 2KB
minimal.css 2KB
polaris.css 2KB
square.css 2KB
nestable.css 2KB
nprogress.css 1KB
orange.css 1KB
purple.css 1KB
yellow.css 1KB
green.css 1KB
blue.css 1KB
共 923 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
Make程序设计
- 粉丝: 5623
- 资源: 3567
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功