|
修改app/home/controller/DetailController.php文件
- <?php
- namespace app\home\controller;
- use app\BaseController;
- use think\facade\View;
- use think\facade\Db;
- use think\facade\cache;
- use YttGet\YttGetItem;
- use YttGet\YttGetH5api;
- class DetailController extends BaseController {
- public function _initialize() {
- parent::_initialize();
- }
- public function index(){
- $iid = request()->param('iid','','trim');
- $ytt_geth = new YttGetItem();
- $item = array();
- if(C('ytt_site_cache')){
- if (NULL === $item = cache('item'.$iid)) {
- $item = $ytt_geth->gets_info($iid);
- cache('item'.$iid,$item);
- }
- }else{
- $item = $ytt_geth->gets_info($iid);
- }
- if(empty($item['num_iid'])){
- $this->_404('https://item.taobao.com/item.htm?id='.$iid);
- exit;
- }
- if(!empty($item['coupon_price'])){
- $item['coupon_price'] = format_price($item['coupon_price']);
- }
- if(!empty($item['price'])){
- $item['price'] = format_price($item['price']);
- }
- $imglist = array();
- $pic_list = array();
- if(!empty($item['imglist'])){
- $imglist = explode(',',$item['imglist']);
- foreach($imglist as $key => $vol){
- $pic_list[$key]['pic'] = $vol;
- }
- }
- $orlike = array();
- if(C('ytt_site_cache')){
- if (NULL === $orlike = cache('orlike'.$iid)) {
- $orlike = $ytt_geth->gets_same($iid);
- cache('orlike'.$iid,$orlike);
- }
- }else{
- $orlike = $ytt_geth->gets_same($iid);
- }
-
-
- $newlist=array();
- if(!empty($orlike)){
- $or_list = array_rand($orlike,5);
- foreach($or_list as $val){
- $newlist[]=$orlike[$val];
- }
- $newlist = array_values($newlist);
- foreach($orlike as $key=>$val){
- $orlike[$key] = $val;
- $orlike[$key]['pic'] = attach(get_thumb($val['pic_url'], '_b'),'item');
- $orlike[$key]['price'] = format_price($val['price']);
- $orlike[$key]['num_iid'] = $val['num_iid'];
- $orlike[$key]['coupon_price'] = format_price($val['coupon_price']);
- $orlike[$key]['quan'] = format_price($val['quan']);
- }
- }
- if(!empty($item['volume'])){
- $volumec = ',已售'.$item['volume'].'件,数量有限,抢完为止。';
- }else{
- $volumec = ',数量有限,抢完为止。';
- }
- if(!empty($item['quan'])){
- $desc = '原价'.$item['price'].'元,现有优惠券'.$item['quan'].'元,领券后只要'.$item['coupon_price'].'元'.$volumec;
- }else{
- $desc = '现售价'.$item['coupon_price'].'元'.$volumec;
- if($item['price']>$item['coupon_price']){
- $desc = '原价'.$item['price'].'元,现售价'.$item['coupon_price'].'元'.$volumec;
- }
- }
- $descs = $desc;
- $item['start_time'] = date('Y.m.d',$item['coupon_start_time']);
- $item['end_time'] = date('Y.m.d',$item['coupon_end_time']);
- $item['intro'] = $item['intro'].$desc;
- $this->_config_seo(C('ytt_seo_config.item'), array(
- 'title' => $item['title'],
- 'intro' => $item['intro'],
- 'shopname' => $item['shop_title'],
- 'catname' => $item['one_cname'],
- 'desc' => $descs,
- 'tags' => $item['tags'],
- ));
- View::assign('pic_list', $pic_list);
- View::assign('orlike', $orlike);
- View::assign('newlist', $newlist);
- View::assign('item', $item);
- View::assign('iid', $iid);
- return view();
- }
-
-
- }
复制代码
|
|