Goods.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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_usdt'])? $counts['total_usdt'] : 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. $loginStu = db('studio')->where(['title' => $this->auth->login_studio])->find();
  58. $stuid = isset($loginStu['id'])? $loginStu['id'] : 0;
  59. $counts = [
  60. 'status1'=> db('trade')->where(['relevant_userid'=>$this->auth->id,'status'=>1,'stuid'=>$stuid])->count('id'),
  61. 'status2'=> db('trade')->where(['relevant_userid'=>$this->auth->id,'status'=>2,'stuid'=>$stuid])->count('id'),
  62. 'status3'=> db('trade')->where(['relevant_userid'=>$this->auth->id,'status'=>3,'issell'=>[['egt',0],['elt',2]],'stuid'=>$stuid])->count('id'),
  63. ];
  64. $config = Config::getConfigByGroup('basic');
  65. $this->view->assign('config', $rates);
  66. $this->view->assign('awards', $awards);
  67. $this->view->assign('cats', $cats);
  68. $this->view->assign('counts', $counts);
  69. $this->view->assign('logo', Image::makeLogo($sinfo['name']));
  70. $this->view->assign('product_img', isset($config['product_img']['value'])? $config['product_img']['value'] : '');
  71. return $this->fetch();
  72. }
  73. /**
  74. * 模式
  75. * @return mixed
  76. */
  77. function model(){
  78. $config = Config::getConfigByGroup('basic');
  79. $siteModel = isset($config['site_model'])? htmlspecialchars_decode($config['site_model']['value']) : '';
  80. $this->view->assign('site_model', $siteModel);
  81. return $this->fetch();
  82. }
  83. function goodslist()
  84. {
  85. $catid=input('catid');
  86. $login_studio=$this->auth->login_studio;
  87. $studio=db('studio')->where(['title'=>$login_studio])->find();
  88. if(time()>=strtotime(date("Y-m-d {$studio['start']}")) && time()<= strtotime(date("Y-m-d {$studio['end']}")) )
  89. {
  90. $status='营业中';
  91. }elseif(time()< strtotime(date("Y-m-d {$studio['start']}"))){
  92. $status='停业中';
  93. }elseif(time() > strtotime(date("Y-m-d {$studio['end']}"))){
  94. $status='停业中';
  95. }
  96. if(empty($user['bank_number']) && empty($user['wxprc']) &&empty($user['alipayprc']) && empty($user['usdt_address']) && empty($user['thb_bank_number']) && empty($user['idr_bank_number']))
  97. {
  98. $this->view->assign('no_auth', true);
  99. }else{
  100. $this->view->assign('no_auth', false);
  101. }
  102. $isappoint=db('studio_user')->where(['sid'=>$studio['id'],'userid'=>$this->auth->id])->find();
  103. if($isappoint)
  104. {
  105. $flag=0;
  106. }else{
  107. $flag=1;
  108. }
  109. $startTimeText = isset($studio['start'])? $studio['start'] : 0;
  110. $endTime = isset($studio['end'])? $studio['end'] : 0;
  111. $startTime = $startTimeText? strtotime(date('Y-m-d').' '.$startTimeText) : 0;
  112. $endTime = $endTime? strtotime(date('Y-m-d').' '.$endTime) : 0;
  113. $expired = $startTime > time()? $startTime - time() : 0;
  114. if($endTime <= time()){
  115. $startTime = strtotime(date('Y-m-d',strtotime(date('Y-m-d'))+86400).' '.$startTimeText);
  116. $expired = $startTime > time()? $startTime - time() : 0;
  117. }
  118. $this->view->assign([
  119. 'title'=>get_table_column('goods_cats',$catid,'name'),
  120. 'expired'=> $expired,
  121. 'catid'=>$catid,
  122. 'studio'=>$studio,
  123. 'status'=>$status,
  124. 'flag'=>$flag,
  125. ]);
  126. return $this->fetch();
  127. }
  128. /* 商品详情 */
  129. function goodsdetailed()
  130. {
  131. $id=input('id');
  132. $info=db('goods')->where(['id'=>$id])->find();
  133. if(!empty($info['images']))
  134. {
  135. $images=$info['image'].','.$info['images'];
  136. $info['img']=explode(',', $images);
  137. }else{
  138. $info['img']=[$info['image']];
  139. }
  140. $this->view->assign([
  141. "info"=>$info,
  142. ]);
  143. return $this->fetch();
  144. }
  145. /* 商品详情 */
  146. function goodsdetailed1()
  147. {
  148. $id=input('id');
  149. $info=db('goods')->where(['id'=>$id])->find();
  150. if(!empty($info['images']))
  151. {
  152. $images=$info['image'].','.$info['images'];
  153. $info['img']=explode(',', $images);
  154. }else{
  155. $info['img']=[$info['image']];
  156. }
  157. $this->view->assign([
  158. "info"=>$info,
  159. ]);
  160. return $this->fetch();
  161. }
  162. /* 评论 */
  163. function appraise()
  164. {
  165. $goodsid=input('goodsid');
  166. $this->view->assign('goodsid',$goodsid);
  167. return $this->fetch();
  168. }
  169. /* 购物车 */
  170. function cart()
  171. {
  172. return $this->fetch();
  173. }
  174. }