Index.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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\StoreSeckill;
  9. use app\wap\model\store\StoreCategory;
  10. use app\wap\model\store\StoreOrder;
  11. use app\wap\model\store\StorePink;
  12. use app\wap\model\store\StoreProduct;
  13. use app\wap\model\user\User;
  14. use app\wap\model\user\UserNotice;
  15. use app\wap\model\user\WechatUser;
  16. use basic\WapBasic;
  17. use service\GroupDataService;
  18. use service\QrcodeService;
  19. use service\SystemConfigService;
  20. use service\WechatService;
  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. $round=round($value['sales']/$value['stock'],2)*100;
  48. if($round<100){
  49. $storeSeckill[$key]['round']=$round;
  50. }else{
  51. $storeSeckill[$key]['round']=100;
  52. }
  53. }
  54. $this->assign([
  55. 'banner'=>GroupDataService::getData('store_home_banner')?:[],
  56. 'menus'=>GroupDataService::getData('store_home_menus')?:[],
  57. 'roll_news'=>GroupDataService::getData('store_home_roll_news')?:[],
  58. 'category'=>StoreCategory::pidByCategory(0,'id,cate_name'),
  59. 'pinkImage'=>SystemConfigService::get('store_home_pink'),
  60. 'notice'=>$notice,
  61. 'storeSeckill'=>$storeSeckill,
  62. 'storePink'=>$storePink,
  63. ]);
  64. return $this->fetch();
  65. }
  66. public function about()
  67. {
  68. return $this->fetch();
  69. }
  70. public function spread($uni = '')
  71. {
  72. if(!$uni || $uni == 'now') $this->redirect(Url::build('spread',['uni'=>$this->oauth()]));
  73. $wechatUser = WechatUser::getWechatInfo($uni);
  74. $statu = (int)SystemConfigService::get('store_brokerage_statu');
  75. if($statu == 1){
  76. if(!User::be(['uid'=>$this->userInfo['uid'],'is_promoter'=>1]))
  77. return $this->failed('没有权限访问!');
  78. }
  79. $qrInfo = QrcodeService::getTemporaryQrcode('spread',$wechatUser['uid']);
  80. $this->assign([
  81. 'qrInfo'=>$qrInfo,
  82. 'wechatUser'=>$wechatUser
  83. ]);
  84. return $this->fetch();
  85. }
  86. }