Index.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 service\GroupDataService;
  19. use service\QrcodeService;
  20. use service\SystemConfigService;
  21. use service\WechatService;
  22. use think\Db;
  23. use think\Url;
  24. class Index extends AuthController
  25. //class Index extends WapBasic
  26. {
  27. public function index()
  28. {
  29. try{
  30. $uid = User::getActiveUid();
  31. $notice = UserNotice::getNotice($uid);
  32. }catch (\Exception $e){
  33. $notice = 0;
  34. }
  35. $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();
  36. if($storePink){
  37. foreach ($storePink as $k=>$v){
  38. $remain = $v['add_time']%86400;
  39. $hour = floor($remain/3600);
  40. $storePink[$k]['nickname'] = $v['nickname'].$hour.'小时之前拼单';
  41. }
  42. }
  43. $seckillnum=(int)GroupDataService::getData('store_seckill');
  44. $storeSeckill=StoreSeckill::where('is_del',0)->where('status',1)
  45. ->where('start_time','<',time())->where('stop_time','>',time())
  46. ->limit($seckillnum)->order('sort desc')->select()->toArray();
  47. foreach($storeSeckill as $key=>$value){
  48. if($value['stock']>0)
  49. $round = round($value['sales']/$value['stock'],2)*100;
  50. else $round = 100;
  51. if($round<100){
  52. $storeSeckill[$key]['round']=$round;
  53. }else{
  54. $storeSeckill[$key]['round']=100;
  55. }
  56. }
  57. $this->assign([
  58. 'banner'=>GroupDataService::getData('store_home_banner')?:[],
  59. 'menus'=>GroupDataService::getData('store_home_menus')?:[],
  60. 'roll_news'=>GroupDataService::getData('store_home_roll_news')?:[],
  61. 'category'=>StoreCategory::pidByCategory(0,'id,cate_name'),
  62. 'pinkImage'=>SystemConfigService::get('store_home_pink'),
  63. 'notice'=>$notice,
  64. 'storeSeckill'=>$storeSeckill,
  65. 'storePink'=>$storePink,
  66. ]);
  67. return $this->fetch();
  68. }
  69. public function about()
  70. {
  71. return $this->fetch();
  72. }
  73. public function spread($uni = '')
  74. {
  75. if(!$uni || $uni == 'now') $this->redirect(Url::build('spread',['uni'=>$this->oauth()]));
  76. $wechatUser = WechatUser::getWechatInfo($uni);
  77. $statu = (int)SystemConfigService::get('store_brokerage_statu');
  78. if($statu == 1){
  79. if(!User::be(['uid'=>$this->userInfo['uid'],'is_promoter'=>1]))
  80. return $this->failed('没有权限访问!');
  81. }
  82. $qrInfo = QrcodeService::getTemporaryQrcode('spread',$wechatUser['uid']);
  83. $this->assign([
  84. 'qrInfo'=>$qrInfo,
  85. 'wechatUser'=>$wechatUser
  86. ]);
  87. return $this->fetch();
  88. }
  89. }