Index.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\model\BuyCarModel;
  4. use app\common\model\NoticeModel;
  5. use app\common\model\ProductConfigModel;
  6. use app\common\model\ProductModel;
  7. use app\common\model\OrderModel;
  8. use app\common\model\ProductTypeModel;
  9. use app\common\model\StoreModel;
  10. use app\common\model\UserModel;
  11. use app\common\service\helperService;
  12. use app\common\service\interfaceService;
  13. use app\common\service\ServiceBaseInfo;
  14. use app\common\service\serviceWechat;
  15. use think\Config;
  16. use think\Cookie;
  17. use think\Session;
  18. use think\Validate;
  19. class Index extends Base{
  20. /**
  21. * 首页
  22. * @return mixed
  23. */
  24. public function erweicode(){
  25. $userModel = new UserModel();
  26. $userInfo = $userModel->getOne(['user_no'=>Session::get('user_no')]);
  27. $code = interfaceService::returnErWeiCode("{$userInfo['mobile']}");
  28. $this->assign('code',$code);
  29. $this->assign('userInfo',$userInfo);
  30. return $this->fetch('Index/erweicode');
  31. }
  32. public function center(){
  33. $userModel = new UserModel();
  34. $userInfo = $userModel->getOne(['user_no'=>Session::get('user_no')]);
  35. $data['no_pay'] = 0;
  36. $data['no_send'] = 0;
  37. $data['no_shou'] = 0;
  38. $data['service'] = 0;
  39. $res = $this->ordernums();
  40. foreach($res as $k=>$v){
  41. if($v['order_status'] == 10){
  42. $data['no_pay'] = $v['nums'];
  43. }
  44. if($v['order_status'] == 20){
  45. $data['no_send'] = $v['nums'];
  46. }
  47. if($v['order_status'] == 30){
  48. $data['no_shou'] = $v['nums'];
  49. }
  50. if($v['order_status'] == 40){
  51. $data['service'] = $v['nums'];
  52. }
  53. }
  54. $orderModel = new OrderModel();
  55. $data['service'] = $orderModel->getCounts(['user_no'=>Session::get('user_no'),'is_sales'=>1,'os.is_shows'=>1]);
  56. $this->assign('userInfo',$userInfo);
  57. $this->assign('nums',$data);
  58. return $this->fetch('Index/center');
  59. }
  60. public function commodityShow(){
  61. $params = $this->request->param();
  62. $show = isset($params['show'])?$params['show']:'1';
  63. Session::set('show',$show);
  64. }
  65. public function commodity(){
  66. $params = $this->request->param();
  67. $rule = [
  68. ['action|排序规则','number'],
  69. // ['product_name|','number'],
  70. ];
  71. $validate = new Validate($rule);
  72. if(!$validate->check($params)){
  73. $this->error($validate->getError(),'','','3');
  74. }
  75. $type_id = isset($params['id'])?$params['id']:'';
  76. $action = isset($params['action'])?$params['action']:'1';
  77. $where = [
  78. 'product.status'=>'1',
  79. 'product.type_id'=>$type_id,
  80. ];
  81. if(isset($params['product_name']) && !empty($params['product_name'])){
  82. $where['product_name'] = ['like',"%{$params['product_name']}%"];
  83. }
  84. if(Session::has('doctor_no')){
  85. $doctor_no=Session::get('doctor_no');
  86. $actio=1;
  87. }else{
  88. $doctor_no=0;
  89. $actio=2;
  90. }
  91. $where = array_filter($where);
  92. $productModel = new ProductModel();
  93. $productInfo = $productModel->getProductAndPromoList($where,$doctor_no,'',$actio);
  94. if($productInfo){
  95. // print_r($productInfo);exit;
  96. $productConfirmModel = new ProductConfigModel();
  97. foreach ($productInfo as &$product){
  98. $product['sorts'] = 1;
  99. if($product['promo_price']){
  100. $product['sorts'] = 2;
  101. }
  102. $check = $productConfirmModel->getOne(['product_no'=>$product['product_no'],'status'=>1]);
  103. if($check){
  104. $product['sorts'] = 3;
  105. }
  106. if($product['promo_price'] && $check){
  107. $product['sorts'] = 4;
  108. }
  109. }
  110. if($action == 1){//默认
  111. foreach($productInfo as $val){
  112. $key_arrays[]=$val['sort'];
  113. }
  114. // //1.正常2.促销3.限购4.促销+限购
  115. array_multisort($key_arrays,SORT_DESC,SORT_NUMERIC,$productInfo);
  116. }
  117. if ($action == 3){ //从小到大
  118. foreach($productInfo as $val){
  119. $key_arrays[]=$val['sales_price'];
  120. }
  121. array_multisort($key_arrays,SORT_ASC,SORT_NUMERIC,$productInfo);
  122. }
  123. if ($action == 4){//从大到小
  124. foreach($productInfo as $val){
  125. $key_arrays[]=$val['sales_price'];
  126. }
  127. array_multisort($key_arrays,SORT_DESC,SORT_NUMERIC,$productInfo);
  128. }
  129. // print_r($productInfo);exit;
  130. if($action==2){
  131. foreach ($productInfo as $key=>$product){
  132. if(empty($product['promo_price'])){
  133. unset($productInfo[$key]);
  134. }
  135. }
  136. }
  137. }
  138. if(!empty($productInfo)){
  139. // print_r($productInfo);exit;
  140. foreach ($productInfo as $key=>&$product){
  141. $product['images'] = json_decode($product['images'],true);
  142. if(empty($product['type_name'])){
  143. unset($productInfo[$key]);
  144. }
  145. }
  146. }
  147. //print_r($productInfo);exit;
  148. $productType = new ProductTypeModel();
  149. $productTypeInfo = $productType->getMulti(['status'=>1]);
  150. //得到处方药
  151. $drugC = $productType->getMulti(['parent_id'=>2,'status'=>1]);
  152. //得到非处方药
  153. $drugF = $productType->getMulti(['parent_id'=>1,'status'=>1]);
  154. // print_r($drugF);exit;
  155. // echo $action;exit;
  156. if(Session::has('show')){
  157. $show = Session::get('show');
  158. }else{
  159. $show = 2;
  160. }
  161. $this->assign('show',$show);
  162. $this->assign('drugC',$drugC);
  163. $this->assign('drugF',$drugF);
  164. $this->assign('productTypeInfo',$productTypeInfo);
  165. $this->assign('action',$action);
  166. $this->assign('productInfo',$productInfo);
  167. return $this->fetch('Index/commodity');
  168. }
  169. public function person_info(){
  170. $params = $this->request->param();
  171. $rule = [
  172. ['check_user_pay|门店id','number'],
  173. ];
  174. $validate = new Validate($rule);
  175. if(!$validate->check($params)){
  176. $this->error($validate->getError(),null,'',3);
  177. }
  178. $check_user_pay = isset($params['check_user_pay'])?$params['check_user_pay']:'1';
  179. $this->assign('check_user_pay',$check_user_pay);
  180. return $this->fetch('Index/person_info');
  181. }
  182. public function edit_person_info(){
  183. $userNo = Session::get('user_no');
  184. $userModel = new UserModel();
  185. $userInfo = $userModel->getOne(['user_no'=>$userNo,'status'=>1]);
  186. if($userInfo['province_code']){
  187. $userInfo['province'] = ServiceBaseInfo::getAddress(['level'=>1,'code'=>$userInfo['province_code']]);
  188. $userInfo['province'] = current($userInfo['province']);
  189. $userInfo['city'] = ServiceBaseInfo::getAddress(['level'=>2,'code'=>$userInfo['city_code']]);
  190. $userInfo['city'] = current($userInfo['city']);
  191. $userInfo['area'] = ServiceBaseInfo::getAddress(['level'=>3,'code'=>$userInfo['area_code']]);
  192. $userInfo['area'] = current($userInfo['area']);
  193. }
  194. $this->assign('userInfo',$userInfo);
  195. return $this->fetch('Index/edit_person_info');
  196. }
  197. public function saveUser(){
  198. $params = $this->request->param();
  199. // print_r($params);exit;
  200. $rule = [
  201. // ['user_name|用户名','require'],
  202. ['sex|性别','require|number'],
  203. ['birthday|生日','require'],
  204. ['pro|省份code','require|number'],
  205. ['cit|城市code','require|number'],
  206. ['are|县区code','require|number'],
  207. ];
  208. $validate = new Validate($rule);
  209. if(!$validate->check($params)){
  210. $this->error($validate->getError(),null,'',3);
  211. }
  212. $userModel = new UserModel();
  213. $data = [
  214. 'real_name'=>$params['real_name'],
  215. 'gender'=>$params['sex'],
  216. 'birthday'=>strtotime($params['birthday']),
  217. 'province_code'=>$params['pro'],
  218. 'city_code'=>$params['cit'],
  219. 'area_code'=>$params['are']
  220. ];
  221. // print_r($data);exit;
  222. $return = $userModel->saveData($data,['user_no'=>Session::get('user_no')]);
  223. if($return === false){
  224. $this->error('操作有误,请重试');
  225. }
  226. $this->redirect('/index/index/card');
  227. }
  228. public function card(){
  229. $userNo = Session::get('user_no');
  230. $userModel = new UserModel();
  231. $userInfo = $userModel->getOne(['user_no'=>$userNo,'status'=>1]);
  232. if($userInfo['mobile']){
  233. $str1 = substr($userInfo['mobile'],0,3);
  234. $str2 = substr($userInfo['mobile'],3,4);
  235. $str3 = substr($userInfo['mobile'],7,4);
  236. }else{
  237. $str1='';
  238. $str2='';
  239. $str3='';
  240. }
  241. $this->assign('str1',$str1);
  242. $this->assign('str2',$str2);
  243. $this->assign('str3',$str3);
  244. $this->assign('userInfo',$userInfo);
  245. return $this->fetch('Index/card');
  246. }
  247. public function join_member(){
  248. return $this->fetch('Index/join_member');
  249. }
  250. public function score(){
  251. $userModel = new UserModel();
  252. $userInfo = $userModel->getOne(['user_no'=>Session::get('user_no')]);
  253. $orderModel = new OrderModel();
  254. $orderInfo = $orderModel->getMulti(['user_no'=>Session::get('user_no'),'order_status'=>['in',['20','30','31']]]);
  255. $this->assign('userInfo',$userInfo);
  256. $this->assign('orderInfo',$orderInfo);
  257. return $this->fetch('Index/score');
  258. }
  259. public function address(){
  260. return $this->fetch('Index/address');
  261. }
  262. public function addressList(){
  263. return $this->fetch('Index/addressList');
  264. }
  265. public function cart(){
  266. return $this->fetch('Index/cart');
  267. }
  268. public function footer(){
  269. return $this->fetch('Index/footer');
  270. }
  271. //待发货
  272. public function order_apply(){
  273. return $this->fetch('Index/order_apply');
  274. }
  275. //待付款
  276. public function order_noPay(){
  277. return $this->fetch('Index/order_noPay');
  278. }
  279. //查看售后
  280. public function order_view(){
  281. return $this->fetch('Index/order_view');
  282. }
  283. //待收货
  284. public function order_get(){
  285. return $this->fetch('Index/order_get');
  286. }
  287. public function after_sales(){
  288. return $this->fetch('Index/after_sales');
  289. }
  290. public function customer_service(){
  291. return $this->fetch('Index/customer_service');
  292. }
  293. /**
  294. *用户数量
  295. */
  296. public function ordernums(){
  297. $orderModel = new OrderModel();
  298. $where = ['user_no'=>session('user_no'),'order_status'=>['in',[10,20,30,40]]];
  299. $res = $orderModel->getUserOrderNums($where);
  300. return $res;
  301. }
  302. public function index(){
  303. $params = $this->request->param();
  304. $rule = [
  305. ['store_id|门店id','number'],
  306. ];
  307. $validate = new Validate($rule);
  308. if(!$validate->check($params)){
  309. $this->error($validate->getError(),null,'',3);
  310. }
  311. //获取门店信息
  312. $storeModel = new StoreModel();
  313. $where = ['status'=>1];
  314. //如果没有指定门店的话查询默认门店
  315. isset($params['store_id'])?$where['store_id'] = $params['store_id']:'';
  316. $storeInfo = $storeModel->getOne($where,true,'store_id asc');
  317. //跑马灯消息(获取最新的5条)
  318. $noticeModel = new NoticeModel();
  319. $noticeList = $noticeModel->getMulti(['status'=>1],'id desc',5);
  320. //获取门店下的商品信息
  321. $productModel = new ProductModel();
  322. $where=[
  323. 'product.status'=>1,
  324. 'is_hot'=>1,
  325. ];
  326. if(isset($params['product_name']) && !empty($params['product_name'])){
  327. $where['product.product_name'] = ['like',"%{$params['product_name']}%"];
  328. }
  329. if(Session::has('doctor_no')){
  330. $doctor_no=Session::get('doctor_no');
  331. $action=1;
  332. }else{
  333. $doctor_no=0;
  334. $action=2;
  335. }
  336. $productList = $productModel->getProductAndPromoList($where,$doctor_no,'sort desc',$action);
  337. // print_r($productList);exit;
  338. // if($productList){
  339. foreach ($productList as $key=>&$product){
  340. if($product['images']){
  341. $product['images'] = current(json_decode($product['images'],true));
  342. }
  343. if(empty($product['type_name'])){
  344. unset($productList[$key]);
  345. }
  346. }
  347. // }
  348. $this->assign('product_name',isset($params['product_name'])?$params['product_name']:'');
  349. $this->assign('storeInfo',$storeInfo);
  350. $this->assign('noticeList',$noticeList);
  351. $this->assign('productList',$productList);
  352. return $this->fetch('Index/index');
  353. }
  354. public function message(){
  355. return $this->fetch('Index/message');
  356. }
  357. public function order_management(){
  358. return $this->fetch('Index/order_management');
  359. }
  360. public function ordernews(){
  361. return $this->fetch('Index/ordernews');
  362. }
  363. public function ordernews2(){
  364. return $this->fetch('Index/ordernews2');
  365. }
  366. public function outlet(){
  367. $store = new StoreModel();
  368. $lng = Cookie::get('lng');
  369. $lat = Cookie::get('lat');
  370. $lng = !empty($lng)?$lng:'121.41141';
  371. $lat = !empty($lat)?$lat:'31.27167';
  372. $allStore = $store->getVicinityStoreList(['status'=>1],$lng,$lat);
  373. if($allStore){
  374. foreach ($allStore as &$store){
  375. $store['distance'] = $store['distance']>1000?round($store['distance']/1000,2)."km":round($store['distance'],2).'m';
  376. }
  377. }
  378. // print_r($allStore);exit;
  379. $this->assign('allStore',$allStore);
  380. return $this->fetch('Index/outlet');
  381. }
  382. public function paySuccess(){
  383. return $this->fetch('Index/paySuccess');
  384. }
  385. public function pro_detail(){
  386. $params = $this->request->param();
  387. $rule = [
  388. ['product_no|产品编号','number|max:20'],
  389. ];
  390. $validate = new Validate($rule);
  391. if(!$validate->check($params)){
  392. $this->error($validate->getError(),null,'',3);
  393. }
  394. if(Session::has('doctor_no')){
  395. $doctor_no=Session::get('doctor_no');
  396. }else{
  397. $doctor_no=0;
  398. }
  399. $ProductModel = new ProductModel();
  400. $Product = $ProductModel->getProductAndPromoOne(['product.product_no'=>"{$params['product_no']}"],$doctor_no);
  401. $buyCarModel = new BuyCarModel();
  402. $sum = $buyCarModel->getSum(['user_no'=>Session::get('user_no')],'number');
  403. $Product['images'] = json_decode($Product['images'],true);
  404. $doctor_no = 0;
  405. if(Session::has('doctor_no'))
  406. {
  407. $doctor_no = Session::get('doctor_no');
  408. }
  409. $this->assign('doctor_no',$doctor_no);
  410. $this->assign('product',$Product);
  411. $this->assign('car_sum',$sum);
  412. return $this->fetch('Index/pro_detail');
  413. }
  414. /**
  415. * 添加购物
  416. */
  417. public function addCar(){
  418. $params = $this->request->param();
  419. $rule = [
  420. ['product_no|产品编号','number|max:20'],
  421. ['num|产品数量','number|max:16'],
  422. ['doctor_no|医生编号','number|max:16'],
  423. ];
  424. $validate = new Validate($rule);
  425. if(!$validate->check($params)){
  426. $this->error($validate->getError(),null,'',3);
  427. }
  428. //判断当前产品
  429. $buyCarModel = new BuyCarModel();
  430. $buyCar = $buyCarModel->getOne(['product_no'=>"{$params['product_no']}",'user_no'=>Session::get('user_no')]);
  431. //print_r($buyCar);exit;
  432. if(!empty($buyCar)){
  433. $num = $buyCar['number'];
  434. if($buyCar['doctor_no']!=0){
  435. $data = ['number'=>($num+$params['num'])];
  436. }else{
  437. $data = ['number'=>($num+$params['num']),'doctor_no'=>$params['doctor_no']];
  438. }
  439. $buyCarModel->saveData($data,[
  440. 'product_no'=>"{$params['product_no']}",
  441. 'user_no'=>Session::get('user_no'),
  442. 'number'=>"$num",
  443. ]);
  444. }else{
  445. $buyCarModel->saveData([
  446. 'product_no'=>"{$params['product_no']}",
  447. 'user_no'=>Session::get('user_no'),
  448. 'number'=>$params['num'],
  449. 'doctor_no'=>$params['doctor_no']
  450. ]);
  451. }
  452. $carSum = $buyCarModel->getSum(['user_no'=>Session::get('user_no')],'number');
  453. helperService::returnJson([
  454. 'code'=>200,
  455. 'msg'=>'加入购物车成功',
  456. 'data'=>['car_sum'=>$carSum]
  457. ]);
  458. }
  459. /**
  460. * 获取微信接口
  461. */
  462. public function map(){
  463. $serviceWechat = new serviceWechat();
  464. $res = $serviceWechat->getConfigJs([]);
  465. // print_r($res);exit;
  466. $res = json_decode($res,true);
  467. if(!isset($res['code']) || $res['code'] != 200){
  468. die('获取jsapi数据失败,请重新尝试!');
  469. }
  470. $jsapi_ticket = $res['data'];
  471. $timestamp = time();
  472. $nonceStr = rand(10000,80000);
  473. $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  474. $sign = "jsapi_ticket=$jsapi_ticket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
  475. $signature = sha1($sign);
  476. $this->assign('request_header',$this->request->header());
  477. $this->assign('signature',$signature);
  478. $this->assign('timestamp',$timestamp);
  479. $this->assign('nonceStr',$nonceStr);
  480. $this->assign('appId',Config::get('APPID'));
  481. $params = $this->request->param();
  482. $store_id = isset($params['store_id'])?$params['store_id']:0;
  483. $storeModel = new StoreModel();
  484. $store = $storeModel->getOne(['store_id'=>"$store_id"]);
  485. if(empty($store)){
  486. $this->error('门店不存在');
  487. }
  488. // print_r($_SERVER);exit;
  489. $this->assign('latitude',$store['lat']);
  490. $this->assign('longitude',$store['lng']);
  491. $this->assign('name',$store['store_name']);
  492. $this->assign('address',$store['address']);
  493. $this->assign('xxx',$_SERVER['HTTP_REFERER']);
  494. return $this->fetch("/Index/map");
  495. }
  496. public function new_file(){
  497. return $this->fetch('Index/new_file');
  498. }
  499. public function dangjian(){
  500. return $this->fetch('Index/dangjian');
  501. }
  502. }