Goods.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. return $this->fetch();
  69. }
  70. function goodslist()
  71. {
  72. $catid=input('catid');
  73. $login_studio=$this->auth->login_studio;
  74. $studio=db('studio')->where(['title'=>$login_studio])->find();
  75. if(time()>=strtotime(date("Y-m-d {$studio['start']}")) && time()<= strtotime(date("Y-m-d {$studio['end']}")) )
  76. {
  77. $status='营业中';
  78. }elseif(time()< strtotime(date("Y-m-d {$studio['start']}"))){
  79. $status='停业中';
  80. }elseif(time() > strtotime(date("Y-m-d {$studio['end']}"))){
  81. $status='停业中';
  82. }
  83. $isappoint=db('studio_user')->where(['sid'=>$studio['id'],'userid'=>$this->auth->id])->find();
  84. if($isappoint)
  85. {
  86. $flag=0;
  87. }else{
  88. $flag=1;
  89. }
  90. $startTimeText = isset($studio['start'])? $studio['start'] : 0;
  91. $endTime = isset($studio['end'])? $studio['end'] : 0;
  92. $startTime = $startTimeText? strtotime(date('Y-m-d').' '.$startTimeText) : 0;
  93. $endTime = $endTime? strtotime(date('Y-m-d').' '.$endTime) : 0;
  94. $expired = $startTime > time()? $startTime - time() : 0;
  95. if($endTime <= time()){
  96. $startTime = strtotime(date('Y-m-d',strtotime(date('Y-m-d'))+86400).' '.$startTimeText);
  97. $expired = $startTime > time()? $startTime - time() : 0;
  98. }
  99. $this->view->assign([
  100. 'title'=>get_table_column('goods_cats',$catid,'name'),
  101. 'expired'=> $expired,
  102. 'catid'=>$catid,
  103. 'studio'=>$studio,
  104. 'status'=>$status,
  105. 'flag'=>$flag,
  106. ]);
  107. return $this->fetch();
  108. }
  109. /* 商品详情 */
  110. function goodsdetailed()
  111. {
  112. $id=input('id');
  113. $info=db('goods')->where(['id'=>$id])->find();
  114. if(!empty($info['images']))
  115. {
  116. $images=$info['image'].','.$info['images'];
  117. $info['img']=explode(',', $images);
  118. }else{
  119. $info['img']=[$info['image']];
  120. }
  121. $this->view->assign([
  122. "info"=>$info,
  123. ]);
  124. return $this->fetch();
  125. }
  126. /* 商品详情 */
  127. function goodsdetailed1()
  128. {
  129. $id=input('id');
  130. $info=db('goods')->where(['id'=>$id])->find();
  131. if(!empty($info['images']))
  132. {
  133. $images=$info['image'].','.$info['images'];
  134. $info['img']=explode(',', $images);
  135. }else{
  136. $info['img']=[$info['image']];
  137. }
  138. $this->view->assign([
  139. "info"=>$info,
  140. ]);
  141. return $this->fetch();
  142. }
  143. /* 评论 */
  144. function appraise()
  145. {
  146. $goodsid=input('goodsid');
  147. $this->view->assign('goodsid',$goodsid);
  148. return $this->fetch();
  149. }
  150. /* 购物车 */
  151. function cart()
  152. {
  153. return $this->fetch();
  154. }
  155. }