123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544 |
- <?php
- namespace app\index\controller;
- use app\common\model\BuyCarModel;
- use app\common\model\NoticeModel;
- use app\common\model\ProductConfigModel;
- use app\common\model\ProductModel;
- use app\common\model\OrderModel;
- use app\common\model\ProductTypeModel;
- use app\common\model\StoreModel;
- use app\common\model\UserModel;
- use app\common\service\helperService;
- use app\common\service\interfaceService;
- use app\common\service\ServiceBaseInfo;
- use app\common\service\serviceWechat;
- use think\Config;
- use think\Cookie;
- use think\Session;
- use think\Validate;
- class Index extends Base{
- /**
- * 首页
- * @return mixed
- */
- public function erweicode(){
- $userModel = new UserModel();
- $userInfo = $userModel->getOne(['user_no'=>Session::get('user_no')]);
- $code = interfaceService::returnErWeiCode("{$userInfo['mobile']}");
- $this->assign('code',$code);
- $this->assign('userInfo',$userInfo);
- return $this->fetch('Index/erweicode');
- }
- public function center(){
- $userModel = new UserModel();
- $userInfo = $userModel->getOne(['user_no'=>Session::get('user_no')]);
- $data['no_pay'] = 0;
- $data['no_send'] = 0;
- $data['no_shou'] = 0;
- $data['service'] = 0;
- $res = $this->ordernums();
- foreach($res as $k=>$v){
- if($v['order_status'] == 10){
- $data['no_pay'] = $v['nums'];
- }
- if($v['order_status'] == 20){
- $data['no_send'] = $v['nums'];
- }
- if($v['order_status'] == 30){
- $data['no_shou'] = $v['nums'];
- }
- if($v['order_status'] == 40){
- $data['service'] = $v['nums'];
- }
- }
- $orderModel = new OrderModel();
- $data['service'] = $orderModel->getCounts(['user_no'=>Session::get('user_no'),'is_sales'=>1,'os.is_shows'=>1]);
- $this->assign('userInfo',$userInfo);
- $this->assign('nums',$data);
- return $this->fetch('Index/center');
- }
- public function commodityShow(){
- $params = $this->request->param();
- $show = isset($params['show'])?$params['show']:'1';
- Session::set('show',$show);
- }
- public function commodity(){
- $params = $this->request->param();
- $rule = [
- ['action|排序规则','number'],
- // ['product_name|','number'],
- ];
- $validate = new Validate($rule);
- if(!$validate->check($params)){
- $this->error($validate->getError(),'','','3');
- }
- $type_id = isset($params['id'])?$params['id']:'';
- $action = isset($params['action'])?$params['action']:'1';
- $where = [
- 'product.status'=>'1',
- 'product.type_id'=>$type_id,
- ];
- if(isset($params['product_name']) && !empty($params['product_name'])){
- $where['product_name'] = ['like',"%{$params['product_name']}%"];
- }
- if(Session::has('doctor_no')){
- $doctor_no=Session::get('doctor_no');
- $actio=1;
- }else{
- $doctor_no=0;
- $actio=2;
- }
- $where = array_filter($where);
- $productModel = new ProductModel();
- $productInfo = $productModel->getProductAndPromoList($where,$doctor_no,'',$actio);
- if($productInfo){
- // print_r($productInfo);exit;
- $productConfirmModel = new ProductConfigModel();
- foreach ($productInfo as &$product){
- $product['sorts'] = 1;
- if($product['promo_price']){
- $product['sorts'] = 2;
- }
- $check = $productConfirmModel->getOne(['product_no'=>$product['product_no'],'status'=>1]);
- if($check){
- $product['sorts'] = 3;
- }
- if($product['promo_price'] && $check){
- $product['sorts'] = 4;
- }
- }
- if($action == 1){//默认
- foreach($productInfo as $val){
- $key_arrays[]=$val['sort'];
- }
- // //1.正常2.促销3.限购4.促销+限购
- array_multisort($key_arrays,SORT_DESC,SORT_NUMERIC,$productInfo);
- }
- if ($action == 3){ //从小到大
- foreach($productInfo as $val){
- $key_arrays[]=$val['sales_price'];
- }
- array_multisort($key_arrays,SORT_ASC,SORT_NUMERIC,$productInfo);
- }
- if ($action == 4){//从大到小
- foreach($productInfo as $val){
- $key_arrays[]=$val['sales_price'];
- }
- array_multisort($key_arrays,SORT_DESC,SORT_NUMERIC,$productInfo);
- }
- // print_r($productInfo);exit;
- if($action==2){
- foreach ($productInfo as $key=>$product){
- if(empty($product['promo_price'])){
- unset($productInfo[$key]);
- }
- }
- }
- }
- if(!empty($productInfo)){
- // print_r($productInfo);exit;
- foreach ($productInfo as $key=>&$product){
- $product['images'] = json_decode($product['images'],true);
- if(empty($product['type_name'])){
- unset($productInfo[$key]);
- }
- }
- }
- //print_r($productInfo);exit;
- $productType = new ProductTypeModel();
- $productTypeInfo = $productType->getMulti(['status'=>1]);
- //得到处方药
- $drugC = $productType->getMulti(['parent_id'=>2,'status'=>1]);
- //得到非处方药
- $drugF = $productType->getMulti(['parent_id'=>1,'status'=>1]);
- // print_r($drugF);exit;
- // echo $action;exit;
- if(Session::has('show')){
- $show = Session::get('show');
- }else{
- $show = 2;
- }
- $this->assign('show',$show);
- $this->assign('drugC',$drugC);
- $this->assign('drugF',$drugF);
- $this->assign('productTypeInfo',$productTypeInfo);
- $this->assign('action',$action);
- $this->assign('productInfo',$productInfo);
- return $this->fetch('Index/commodity');
- }
- public function person_info(){
- $params = $this->request->param();
- $rule = [
- ['check_user_pay|门店id','number'],
- ];
- $validate = new Validate($rule);
- if(!$validate->check($params)){
- $this->error($validate->getError(),null,'',3);
- }
- $check_user_pay = isset($params['check_user_pay'])?$params['check_user_pay']:'1';
- $this->assign('check_user_pay',$check_user_pay);
- return $this->fetch('Index/person_info');
- }
- public function edit_person_info(){
- $userNo = Session::get('user_no');
- $userModel = new UserModel();
- $userInfo = $userModel->getOne(['user_no'=>$userNo,'status'=>1]);
- if($userInfo['province_code']){
- $userInfo['province'] = ServiceBaseInfo::getAddress(['level'=>1,'code'=>$userInfo['province_code']]);
- $userInfo['province'] = current($userInfo['province']);
- $userInfo['city'] = ServiceBaseInfo::getAddress(['level'=>2,'code'=>$userInfo['city_code']]);
- $userInfo['city'] = current($userInfo['city']);
- $userInfo['area'] = ServiceBaseInfo::getAddress(['level'=>3,'code'=>$userInfo['area_code']]);
- $userInfo['area'] = current($userInfo['area']);
- }
- $this->assign('userInfo',$userInfo);
- return $this->fetch('Index/edit_person_info');
- }
- public function saveUser(){
- $params = $this->request->param();
- // print_r($params);exit;
- $rule = [
- // ['user_name|用户名','require'],
- ['sex|性别','require|number'],
- ['birthday|生日','require'],
- ['pro|省份code','require|number'],
- ['cit|城市code','require|number'],
- ['are|县区code','require|number'],
- ];
- $validate = new Validate($rule);
- if(!$validate->check($params)){
- $this->error($validate->getError(),null,'',3);
- }
- $userModel = new UserModel();
- $data = [
- 'real_name'=>$params['real_name'],
- 'gender'=>$params['sex'],
- 'birthday'=>strtotime($params['birthday']),
- 'province_code'=>$params['pro'],
- 'city_code'=>$params['cit'],
- 'area_code'=>$params['are']
- ];
- // print_r($data);exit;
- $return = $userModel->saveData($data,['user_no'=>Session::get('user_no')]);
- if($return === false){
- $this->error('操作有误,请重试');
- }
- $this->redirect('/index/index/card');
- }
- public function card(){
- $userNo = Session::get('user_no');
- $userModel = new UserModel();
- $userInfo = $userModel->getOne(['user_no'=>$userNo,'status'=>1]);
- if($userInfo['mobile']){
- $str1 = substr($userInfo['mobile'],0,3);
- $str2 = substr($userInfo['mobile'],3,4);
- $str3 = substr($userInfo['mobile'],7,4);
- }else{
- $str1='';
- $str2='';
- $str3='';
- }
- $this->assign('str1',$str1);
- $this->assign('str2',$str2);
- $this->assign('str3',$str3);
- $this->assign('userInfo',$userInfo);
- return $this->fetch('Index/card');
- }
- public function join_member(){
- return $this->fetch('Index/join_member');
- }
- public function score(){
- $userModel = new UserModel();
- $userInfo = $userModel->getOne(['user_no'=>Session::get('user_no')]);
- $orderModel = new OrderModel();
- $orderInfo = $orderModel->getMulti(['user_no'=>Session::get('user_no'),'order_status'=>['in',['20','30','31']]]);
- $this->assign('userInfo',$userInfo);
- $this->assign('orderInfo',$orderInfo);
- return $this->fetch('Index/score');
- }
- public function address(){
- return $this->fetch('Index/address');
- }
- public function addressList(){
- return $this->fetch('Index/addressList');
- }
- public function cart(){
- return $this->fetch('Index/cart');
- }
- public function footer(){
- return $this->fetch('Index/footer');
- }
- //待发货
- public function order_apply(){
- return $this->fetch('Index/order_apply');
- }
- //待付款
- public function order_noPay(){
- return $this->fetch('Index/order_noPay');
- }
- //查看售后
- public function order_view(){
- return $this->fetch('Index/order_view');
- }
- //待收货
- public function order_get(){
- return $this->fetch('Index/order_get');
- }
-
- public function after_sales(){
- return $this->fetch('Index/after_sales');
- }
- public function customer_service(){
- return $this->fetch('Index/customer_service');
- }
- /**
- *用户数量
- */
- public function ordernums(){
- $orderModel = new OrderModel();
- $where = ['user_no'=>session('user_no'),'order_status'=>['in',[10,20,30,40]]];
- $res = $orderModel->getUserOrderNums($where);
- return $res;
- }
- public function index(){
- $params = $this->request->param();
- $rule = [
- ['store_id|门店id','number'],
- ];
- $validate = new Validate($rule);
- if(!$validate->check($params)){
- $this->error($validate->getError(),null,'',3);
- }
- //获取门店信息
- $storeModel = new StoreModel();
- $where = ['status'=>1];
- //如果没有指定门店的话查询默认门店
- isset($params['store_id'])?$where['store_id'] = $params['store_id']:'';
- $storeInfo = $storeModel->getOne($where,true,'store_id asc');
- //跑马灯消息(获取最新的5条)
- $noticeModel = new NoticeModel();
- $noticeList = $noticeModel->getMulti(['status'=>1],'id desc',5);
- //获取门店下的商品信息
- $productModel = new ProductModel();
- $where=[
- 'product.status'=>1,
- 'is_hot'=>1,
- ];
- if(isset($params['product_name']) && !empty($params['product_name'])){
- $where['product.product_name'] = ['like',"%{$params['product_name']}%"];
- }
- if(Session::has('doctor_no')){
- $doctor_no=Session::get('doctor_no');
- $action=1;
- }else{
- $doctor_no=0;
- $action=2;
- }
- $productList = $productModel->getProductAndPromoList($where,$doctor_no,'sort desc',$action);
- // print_r($productList);exit;
- // if($productList){
- foreach ($productList as $key=>&$product){
- if($product['images']){
- $product['images'] = current(json_decode($product['images'],true));
- }
- if(empty($product['type_name'])){
- unset($productList[$key]);
- }
- }
- // }
- $this->assign('product_name',isset($params['product_name'])?$params['product_name']:'');
- $this->assign('storeInfo',$storeInfo);
- $this->assign('noticeList',$noticeList);
- $this->assign('productList',$productList);
- return $this->fetch('Index/index');
- }
- public function message(){
- return $this->fetch('Index/message');
- }
- public function order_management(){
- return $this->fetch('Index/order_management');
- }
- public function ordernews(){
- return $this->fetch('Index/ordernews');
- }
- public function ordernews2(){
- return $this->fetch('Index/ordernews2');
- }
- public function outlet(){
- $store = new StoreModel();
- $lng = Cookie::get('lng');
- $lat = Cookie::get('lat');
- $lng = !empty($lng)?$lng:'121.41141';
- $lat = !empty($lat)?$lat:'31.27167';
- $allStore = $store->getVicinityStoreList(['status'=>1],$lng,$lat);
- if($allStore){
- foreach ($allStore as &$store){
- $store['distance'] = $store['distance']>1000?round($store['distance']/1000,2)."km":round($store['distance'],2).'m';
- }
- }
- // print_r($allStore);exit;
- $this->assign('allStore',$allStore);
- return $this->fetch('Index/outlet');
- }
- public function paySuccess(){
- return $this->fetch('Index/paySuccess');
- }
- public function pro_detail(){
- $params = $this->request->param();
- $rule = [
- ['product_no|产品编号','number|max:20'],
- ];
- $validate = new Validate($rule);
- if(!$validate->check($params)){
- $this->error($validate->getError(),null,'',3);
- }
- if(Session::has('doctor_no')){
- $doctor_no=Session::get('doctor_no');
- }else{
- $doctor_no=0;
- }
- $ProductModel = new ProductModel();
- $Product = $ProductModel->getProductAndPromoOne(['product.product_no'=>"{$params['product_no']}"],$doctor_no);
- $buyCarModel = new BuyCarModel();
- $sum = $buyCarModel->getSum(['user_no'=>Session::get('user_no')],'number');
- $Product['images'] = json_decode($Product['images'],true);
- $doctor_no = 0;
- if(Session::has('doctor_no'))
- {
- $doctor_no = Session::get('doctor_no');
- }
- $this->assign('doctor_no',$doctor_no);
- $this->assign('product',$Product);
- $this->assign('car_sum',$sum);
- return $this->fetch('Index/pro_detail');
- }
- /**
- * 添加购物
- */
- public function addCar(){
- $params = $this->request->param();
- $rule = [
- ['product_no|产品编号','number|max:20'],
- ['num|产品数量','number|max:16'],
- ['doctor_no|医生编号','number|max:16'],
- ];
- $validate = new Validate($rule);
- if(!$validate->check($params)){
- $this->error($validate->getError(),null,'',3);
- }
- //判断当前产品
- $buyCarModel = new BuyCarModel();
- $buyCar = $buyCarModel->getOne(['product_no'=>"{$params['product_no']}",'user_no'=>Session::get('user_no')]);
- //print_r($buyCar);exit;
- if(!empty($buyCar)){
- $num = $buyCar['number'];
- if($buyCar['doctor_no']!=0){
- $data = ['number'=>($num+$params['num'])];
- }else{
- $data = ['number'=>($num+$params['num']),'doctor_no'=>$params['doctor_no']];
- }
- $buyCarModel->saveData($data,[
- 'product_no'=>"{$params['product_no']}",
- 'user_no'=>Session::get('user_no'),
- 'number'=>"$num",
- ]);
- }else{
- $buyCarModel->saveData([
- 'product_no'=>"{$params['product_no']}",
- 'user_no'=>Session::get('user_no'),
- 'number'=>$params['num'],
- 'doctor_no'=>$params['doctor_no']
- ]);
- }
- $carSum = $buyCarModel->getSum(['user_no'=>Session::get('user_no')],'number');
- helperService::returnJson([
- 'code'=>200,
- 'msg'=>'加入购物车成功',
- 'data'=>['car_sum'=>$carSum]
- ]);
- }
- /**
- * 获取微信接口
- */
- public function map(){
- $serviceWechat = new serviceWechat();
- $res = $serviceWechat->getConfigJs([]);
- // print_r($res);exit;
- $res = json_decode($res,true);
- if(!isset($res['code']) || $res['code'] != 200){
- die('获取jsapi数据失败,请重新尝试!');
- }
- $jsapi_ticket = $res['data'];
- $timestamp = time();
- $nonceStr = rand(10000,80000);
- $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
- $sign = "jsapi_ticket=$jsapi_ticket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
- $signature = sha1($sign);
- $this->assign('request_header',$this->request->header());
- $this->assign('signature',$signature);
- $this->assign('timestamp',$timestamp);
- $this->assign('nonceStr',$nonceStr);
- $this->assign('appId',Config::get('APPID'));
- $params = $this->request->param();
- $store_id = isset($params['store_id'])?$params['store_id']:0;
- $storeModel = new StoreModel();
- $store = $storeModel->getOne(['store_id'=>"$store_id"]);
- if(empty($store)){
- $this->error('门店不存在');
- }
- // print_r($_SERVER);exit;
- $this->assign('latitude',$store['lat']);
- $this->assign('longitude',$store['lng']);
- $this->assign('name',$store['store_name']);
- $this->assign('address',$store['address']);
- $this->assign('xxx',$_SERVER['HTTP_REFERER']);
- return $this->fetch("/Index/map");
- }
- public function new_file(){
- return $this->fetch('Index/new_file');
- }
- public function dangjian(){
- return $this->fetch('Index/dangjian');
- }
- }
|