Index.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/12/11
  6. */
  7. namespace app\wap\controller;
  8. use app\wap\model\store\StoreCombination;
  9. use app\wap\model\store\StoreSeckill;
  10. use app\wap\model\store\StoreCategory;
  11. use app\wap\model\store\StoreOrder;
  12. use app\wap\model\store\StorePink;
  13. use app\wap\model\store\StoreProduct;
  14. use app\wap\model\user\User;
  15. use app\wap\model\user\UserNotice;
  16. use app\wap\model\user\WechatUser;
  17. use basic\WapBasic;
  18. use app\core\util\GroupDataService;
  19. use app\core\util\QrcodeService;
  20. use app\core\util\SystemConfigService;
  21. use think\Db;
  22. use think\Url;
  23. class Index extends AuthController
  24. //class Index extends WapBasic
  25. {
  26. public function index()
  27. {
  28. try{
  29. $uid = User::getActiveUid();
  30. $notice = UserNotice::getNotice($uid);
  31. }catch (\Exception $e){
  32. $notice = 0;
  33. }
  34. $storePink = StorePink::where('p.add_time','GT',time()-86300)->alias('p')->where('p.status',1)->join('User u','u.uid=p.uid')->field('u.nickname,u.avatar as src,p.add_time')->order('p.add_time desc')->limit(20)->select();
  35. if($storePink){
  36. foreach ($storePink as $k=>$v){
  37. $remain = $v['add_time']%86400;
  38. $hour = floor($remain/3600);
  39. $storePink[$k]['nickname'] = $v['nickname'].$hour.'小时之前拼单';
  40. }
  41. }
  42. $seckillnum=(int)GroupDataService::getData('store_seckill');
  43. $storeSeckill=StoreSeckill::where('is_del',0)->where('status',1)
  44. ->where('start_time','<',time())->where('stop_time','>',time())
  45. ->limit($seckillnum)->order('sort desc')->select()->toArray();
  46. foreach($storeSeckill as $key=>$value){
  47. if($value['stock']>0)
  48. $round = round($value['sales']/$value['stock'],2)*100;
  49. else $round = 100;
  50. if($round<100){
  51. $storeSeckill[$key]['round']=$round;
  52. }else{
  53. $storeSeckill[$key]['round']=100;
  54. }
  55. }
  56. $this->assign([
  57. 'banner'=>GroupDataService::getData('store_home_banner')?:[],
  58. 'menus'=>GroupDataService::getData('store_home_menus')?:[],
  59. 'roll_news'=>GroupDataService::getData('store_home_roll_news')?:[],
  60. 'category'=>StoreCategory::pidByCategory(0,'id,cate_name'),
  61. 'pinkImage'=>SystemConfigService::get('store_home_pink'),
  62. 'notice'=>$notice,
  63. 'storeSeckill'=>$storeSeckill,
  64. 'storePink'=>$storePink,
  65. ]);
  66. return $this->fetch();
  67. }
  68. public function about()
  69. {
  70. return $this->fetch();
  71. }
  72. public function spread($uni = '')
  73. {
  74. if(!$uni || $uni == 'now') $this->redirect(Url::build('spread',['uni'=>$this->oauth()]));
  75. $wechatUser = WechatUser::getWechatInfo($uni);
  76. $statu = (int)SystemConfigService::get('store_brokerage_statu');
  77. if($statu == 1){
  78. if(!User::be(['uid'=>$this->userInfo['uid'],'is_promoter'=>1]))
  79. return $this->failed('没有权限访问!');
  80. }
  81. $qrInfo = QrcodeService::getTemporaryQrcode('spread',$wechatUser['uid']);
  82. $this->assign([
  83. 'qrInfo'=>$qrInfo,
  84. 'wechatUser'=>$wechatUser
  85. ]);
  86. return $this->fetch();
  87. }
  88. }