Goods.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace app\shop\controller;
  3. use app\common\controller\Frontend;
  4. use app\common\library\Image;
  5. use app\common\model\Config;
  6. use GuzzleHttp\json_decode;
  7. use think\cache\driver\Redis;
  8. class Goods extends Frontend
  9. {
  10. protected $noNeedLogin = [''];
  11. protected $noNeedRight = '*';
  12. protected $layout = '';
  13. public function _initialize()
  14. {
  15. parent::_initialize();
  16. }
  17. /**
  18. * 主页
  19. * @throws \think\db\exception\DataNotFoundException
  20. * @throws \think\db\exception\ModelNotFoundException
  21. * @throws \think\exception\DbException
  22. */
  23. public function index(){
  24. $cats = db('goods_cats')->where(['status'=>1])->order('sort asc,id asc')->select();
  25. foreach ($cats as $k=>$v)
  26. {
  27. $start=strtotime(date("Y-m-d {$v['start']}"));
  28. $end=strtotime(date("Y-m-d {$v['end']}"));
  29. /*未开始*/
  30. if(time()<$start)
  31. {
  32. $cats[$k]['jctime1']=$start-time();
  33. $cats[$k]['flag']=1;
  34. }elseif(time()>=$start && time()<$end)
  35. {
  36. $cats[$k]['jctime1']=$end-time();
  37. $cats[$k]['flag']=2;
  38. }else{
  39. $cats[$k]['flag']=0;
  40. $cats[$k]['jctime1']=0;
  41. }
  42. }
  43. $sinfo=db('studio')->where(['title'=>$this->auth->login_studio])->find();
  44. $awards = \app\common\model\Trade::getAwardTotal();
  45. //var_dump($awards);
  46. $counts = \app\common\model\Trade::getReleaseTotal($this->auth->id);
  47. $awards = [
  48. 'total'=> isset($awards['total'])? $awards['total'] : 0,
  49. 'total_usdt'=> isset($awards['total_usdt'])? $awards['total_usdt'] : 0,
  50. 'release_total_usdt'=> isset($counts['total'])? $counts['total'] : 0,
  51. 'surplus_usdt'=> isset($counts['surplus_usdt'])? $counts['surplus_usdt'] : 0,
  52. 'release_usdt'=> isset($counts['release_usdt'])? $counts['release_usdt'] : 0,
  53. ];
  54. $config = Config::getConfigByGroup('trade');
  55. $rates['release_rate'] = isset($config['release_rate'])? floatval($config['release_rate']['value']) : 0;
  56. $rates['award_rate'] = isset($config['award_rate'])? floatval($config['award_rate']['value']) : 0;
  57. $this->view->assign('config', $rates);
  58. $this->view->assign('awards', $awards);
  59. $this->view->assign('cats', $cats);
  60. $this->view->assign('logo', Image::makeLogo($sinfo['name']));
  61. return $this->fetch();
  62. }
  63. /**
  64. * 模式
  65. * @return mixed
  66. */
  67. function model(){
  68. $config = Config::getConfigByGroup('basic');
  69. $siteModel = isset($config['site_model'])? htmlspecialchars_decode($config['site_model']['value']) : '';
  70. $this->view->assign('site_model', $siteModel);
  71. return $this->fetch();
  72. }
  73. function goodslist()
  74. {
  75. $catid=input('catid');
  76. $login_studio=$this->auth->login_studio;
  77. $studio=db('studio')->where(['title'=>$login_studio])->find();
  78. if(time()>=strtotime(date("Y-m-d {$studio['start']}")) && time()<= strtotime(date("Y-m-d {$studio['end']}")) )
  79. {
  80. $status='营业中';
  81. }elseif(time()< strtotime(date("Y-m-d {$studio['start']}"))){
  82. $status='停业中';
  83. }elseif(time() > strtotime(date("Y-m-d {$studio['end']}"))){
  84. $status='停业中';
  85. }
  86. $isappoint=db('studio_user')->where(['sid'=>$studio['id'],'userid'=>$this->auth->id])->find();
  87. if($isappoint)
  88. {
  89. $flag=0;
  90. }else{
  91. $flag=1;
  92. }
  93. $startTimeText = isset($studio['start'])? $studio['start'] : 0;
  94. $endTime = isset($studio['end'])? $studio['end'] : 0;
  95. $startTime = $startTimeText? strtotime(date('Y-m-d').' '.$startTimeText) : 0;
  96. $endTime = $endTime? strtotime(date('Y-m-d').' '.$endTime) : 0;
  97. $expired = $startTime > time()? $startTime - time() : 0;
  98. if($endTime <= time()){
  99. $startTime = strtotime(date('Y-m-d',strtotime(date('Y-m-d'))+86400).' '.$startTimeText);
  100. $expired = $startTime > time()? $startTime - time() : 0;
  101. }
  102. $this->view->assign([
  103. 'title'=>get_table_column('goods_cats',$catid,'name'),
  104. 'expired'=> $expired,
  105. 'catid'=>$catid,
  106. 'studio'=>$studio,
  107. 'status'=>$status,
  108. 'flag'=>$flag,
  109. ]);
  110. return $this->fetch();
  111. }
  112. /* 商品详情 */
  113. function goodsdetailed()
  114. {
  115. $id=input('id');
  116. $info=db('goods')->where(['id'=>$id])->find();
  117. if(!empty($info['images']))
  118. {
  119. $images=$info['image'].','.$info['images'];
  120. $info['img']=explode(',', $images);
  121. }else{
  122. $info['img']=[$info['image']];
  123. }
  124. $this->view->assign([
  125. "info"=>$info,
  126. ]);
  127. return $this->fetch();
  128. }
  129. /* 商品详情 */
  130. function goodsdetailed1()
  131. {
  132. $id=input('id');
  133. $info=db('goods')->where(['id'=>$id])->find();
  134. if(!empty($info['images']))
  135. {
  136. $images=$info['image'].','.$info['images'];
  137. $info['img']=explode(',', $images);
  138. }else{
  139. $info['img']=[$info['image']];
  140. }
  141. $this->view->assign([
  142. "info"=>$info,
  143. ]);
  144. return $this->fetch();
  145. }
  146. /* 评论 */
  147. function appraise()
  148. {
  149. $goodsid=input('goodsid');
  150. $this->view->assign('goodsid',$goodsid);
  151. return $this->fetch();
  152. }
  153. /* 购物车 */
  154. function cart()
  155. {
  156. return $this->fetch();
  157. }
  158. }