Goods.php 4.7 KB

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