<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Shop extends CI_Controller
{
private static $data = array();
public function __construct()
{
parent::__construct();
$this->load->model('Menu_model','menu');
$this->load->model('Appbanner_model','banner');
$this->load->model('Webcommon_model','common');
$this->load->model('User_model','user');
$this->load->model('Userinfo_model','userinfo');
$this->load->model('Goods_model','goods');
$this->load->model('Goodsbrand_model','goodsbrand');
$this->load->model('Goodsimage_model','goodsimage');
$this->load->model('Goodsactivity_model','goodsactivity');
$this->load->model('Goodsspec_model','goodsspec');
$this->load->model('Goodscate_model','cate');
$this->load->model('Goodscollection_model','collection') $this->load->model('Goodscomment_model','comment');
$this->load->model('Cart_model','cart');
$this->load->model('Vendercode_model','address');
$this->load->model('Province_model','province');
$this->load->model('Usercount_model','usercount');
$this->load->model('Order_model','order');
$this->load->model('Ordergoods_model','ordergoods');
}
public function Shop()
{
$bannerList = $this->banner->getGoodsBannerList();
$bannerArray = array();
foreach($bannerList as $key=>$value)
{
$bannerArray[$key]['bannerName'] = $value['bannerName'];
$bannerArray[$key]['imagePath'] = $this->config->item('hwclouds').$value['imagePath'];
$bannerArray[$key]['bannerUrl'] = $value['bannerUrl'];
}
$cateList = $this->cate->getGoodsCateList('',100);
$cateListArray = array();
foreach($cateList as $key=>$value)
{
$cateListArray[$key]['cateId'] = $value['cateId'];
$cateListArray[$key]['cateName'] = $value['cateName'];
$cateListArray[$key]['cateImg'] = empty($value['cateImg'])?'':$this->config->item('hwclouds').$value['cateImg'];
}
$brandInfo = $this->goodsbrand->getRecommendBrandList();
$goodsList = $this->goods->getWebRecommendGoodsList();
$activityInfo = $this->goodsactivity->getValidActivityList();
$goodsIds = array();
if(!empty($activityInfo))
{
foreach($activityInfo as $key=>$value)
{
$activityIds[$key] = $value['activityId'];
}
$goodsIdList = $this->goodsactivity->getActivityGoodsList( $activityIds );
if(!empty($goodsIdList))
{
foreach($goodsIdList as $key=>$value)
{
$goodsIds[$value['agId']] = $value['goodsId'];
}
}
}
$goodsInfo = array();
foreach($goodsList as $key=>$value)
{
$goodsInfo[$key]['goodsId'] = $value['goodsId'];
$imageInfo = $this->goodsimage->getGoodsImageOneInfo($value['goodsId']);
$goodsInfo[$key]['imagePath'] = $this->config->item('hwclouds').$imageInfo['imagePath'];
if(in_array($value['goodsId'], $goodsIds))
{ $a = array_search($value['goodsId'], $goodsIds);
$activityList = $this->goodsactivity->getActivityGoodsInfoRow($a);
$goodsInfo[$key]['goodsActivityJifen'] = $activityList['activityJifen'];
$goodsInfo[$key]['goodsJifen'] = $activityList['goodsJifen'];
$goodsInfo[$key]['goodsTitle'] = $activityList['goodsActivityName'];
}
else
{
$goodsInfo[$key]['goodsJifen'] = $value['goodsJifen'];
$goodsInfo[$key]['goodsTitle'] = $value['goodsTitle'];
}
}
echo $this->common->returnArray ( array ( 'bannerList' => $bannerArray ,'goodsList'=>$goodsInfo,'catelist'=>$cateListArray), '读取成功', 200 );exit;
}
public function ajaxShop()
{
$start = 0;
$limit = 10;
$start = $this->input->get_post('start');
if(empty($start))
{
echo $this->common->returnArray ( array ( 'goodsList' => '' ), '参数错误', 1 );exit;
}
$goodsList = $this->goods->getWebRecommendGoodsList( $limit ,$start);
if(empty($goodsList))
{
echo $this->common->returnArray ( array ( 'goodsList' => '' ), '暂无数据', 2 );exit;
}
$activityInfo = $this->goodsactivity->getValidActivityList( );
$goodsIds = array();
if(!empty($activityInfo))
{
foreach($activityInfo as $key=>$value)
{
$activityIds[$key] = $value['activityId'];
}
$goodsIdList = $this->goodsactivity->getActivityGoodsList( $activityIds );
if(!empty($goodsIdList))
{
foreach($goodsIdList as $key=>$value)
{
$goodsIds[$value['agId']] = $value['goodsId'];
}
}
}
$goodsInfo = array();
foreach($goodsList as $key=>$value)
{
$goodsInfo[$key]['goodsId'] = $value['goodsId'];
$imageInfo = $this->goodsimage->getGoodsImageOneInfo($value['goodsId']);
$goodsInfo[$key]['imagePath'] = $this->config->item('hwclouds').$imageInfo['imagePath'];
if(in_array($value['goodsId'], $goodsIds))
{ $a = array_search($value['goodsId'], $goodsIds);
$activityList = $this->goodsactivity->getActivityGoodsInfoRow($a);
$goodsInfo[$key]['goodsActivityJifen'] = $activityList['activityJifen'];
$goodsInfo[$key]['goodsJifen'] = $activityList['goodsJifen'];
$goodsInfo[$key]['goodsTitle'] = $activityList['goodsActivityName'];
}
else
{
$goodsInfo[$key]['goodsJifen'] = $value['goodsJifen'];
$goodsInfo[$key]['goodsTitle'] = $value['goodsTitle'];
}
}
echo $this->common->returnArray ( array ('goodsList'=>$goodsInfo), '读取成功', 200 );exit;
}
public function category()
{
$cateList = $this->cate->getGoodsCateList('',100);
$cateListArray = array();
foreach($cateList as $key=>$value)
{
$cateListArray[$key]['cateId'] = $value['cateId'];
$cateListArray[$key]['cateName'] = $value['cateName'];
$cateListArray[$key]['cateImg'] = empty($value['cateImg'])?'':$this->config->item('hwclouds').$value['cateImg'];
}
echo $this->common->returnArray ( array ('cateList'=>$cateListArray), '读取成功', 200 );exit;
}
public function goodsList()
{
$cateId = $this->input->get_post('cateId');
$keyword = $this->input->get_post('keyword');
if(empty($cateId))
{ if(empty($keyword)){
echo $this->common->returnArray ( array ('goodsList'=>''), '参数错误', 1 );exit;
}
}
$status = $this->input->get_post('status');
$start = $this->input->get_post('start');
$start = empty($start)?0:$start;
$limit = 10;
$goodsList = $this->goods->getCateGoodsList( $cateId ,$status, $limit, $start,$keyword ); $activityInfo = $this->goodsactivity->getValidActivityList();
$goodsIds = array();
if(!empty($activityInfo))
{
foreach($activityInfo as $key=>$value)
{
$activityIds[$key] = $value['activityId'];
}
$goodsIdList = $this->goodsactivity->getActivityGoodsList( $activityIds );
if(!empty($goodsIdList))
{
foreach($goodsIdList as $key=>$value)
{
$goodsIds[$value['agId']] = $value['goodsId'];
}
}
}
$goodsInfo = array();
$num = count($goodsList);
foreach($goodsList as $key=>$value)
{
$goodsInfo[$key]['goodsId'] = $value['goodsId'];
$imageInfo = $this->goodsimage->getGoodsImageOneInfo($value['goodsId']);
$goodsInfo[$key]['imagePath'] = $this->config->item('hwclouds').$imageInfo['imagePath'];
$goodsInfo[$key]['isFreight']= $value['isFreight'] ;
$goodsInfo[$key]['qt']= $value['qt'] ;
if(in_array($value['goodsId'], $goodsIds))
{
$a = array_search($value['goodsId'], $goodsIds);
$activityList = $this->goodsactivity->getActivityGoodsInfoRow($a);
$goodsInfo[$key]['goodsActivityJifen'] = $activityList['activityJifen'];
$goodsInfo[$key]['goodsJifen'] = $activityList['goodsJifen'];
$goodsInfo[$key]['ygoodsJifen']=$value['goodsJifen'];
$goodsInfo[$key]['goodsTitle'] = $activityList['goodsActivityName'];
}
else
{
$goodsInfo[$key]['goodsJifen'] = $value['goodsJifen'];
$goodsInfo[$key]['ygoodsJifen']=$value['goodsJifen'];
$goodsInfo[$key]['goodsTitle'] = $value['goodsTitle'];
}
}
echo $this->common->returnArray ( array ('goodsList'=>$goodsInfo), '读取成功', 200 );exit;
}
public function detail()
{
$token = $this->input->get_post('token');
$userId = $this->input->get_post('userId');
$goodsId = $this->input->get_post('goodsId');
if(empty($goodsId))
{
echo $this->common->returnArray ( array ('goodsList'=>''), '参数错误', 1 );exit;
}
$goodsInfo = $this->goods->getGoodsById( $goodsId );
if(empty($goodsInfo))
{
echo $this->common->returnArray ( array ('goodsList'=>''), '暂无数据', 2 );exit;
}
$this->goods->updateNum(array('viewNum'=>'viewNum+1'),$goodsId);
$brandArray = array();
if(!empty($goodsInfo['brandId']))
{
$brandInfo = $this->goodsbrand->getGoodsBrandRow( $goodsInfo['brandId'] );
if(!empty($brandInfo))
{
$brandArray['brandId'] = $brandInfo['brandId'];
$brandArray['brandName'] = $brandInfo['brandName'];
$brandArray['brief'] = $brandInfo['brief'];
$brandArray['imagePath'] = $this->config->item('hwclouds').$brandInfo['imagePath'];
}
}
$imageList = $this->goodsimage->getGoodsImageList($goodsId,0);
$imageListArray = array();
foreach($imageList as $key=>$value)
{
$imageListArray[$key]['imagePath'] = $this->config->item('hwclouds').$value['imagePath'];
}
$detailImageList = $this->goodsimage->getGoodsImageList($goodsId,1);
$detailImageListArray = array();
foreach($detailImageList as $key=>$value)
{
$detailImageListArray[$key]['imagePath'] = $this->config->item('hwclouds').$value['imagePath'];
}
$collectionInfo = $this->collection->getCollectionRow($goodsId,$userId);
$goodsInfo['shoucang'] = 0;
if(!empty($collectionInfo))
{
$goodsInfo['shoucang'] = 1;
}
$activityInfo = $this->goodsactivity->getValidActivity();
$goodsInfo['status'] = 0;
$goodsIds = array();
$activityStatus = 0;
if(!empty($activityInfo))
{
foreach($activityInfo as $key=>$value)
{
$activityIds[$key] = $value['activityId'];
}
$activityGoodsInfo = $this->goodsactivity->getDetailGoodsInfo( $activityIds ,$goodsId);
if(!empty($activityGoodsInfo))
{
$goodsInfo['goodsTitle'] = empty($activityGoodsInfo['goodsActivityName'])?$activityGoodsInfo['goodsTitle']:$activityGoodsInfo['goodsActivityName'];
$goodsInfo['status'] = 1;
$goodsInfo['activityJifen'] = $activityGoodsInfo['activityJifen'];
$activityStatus = 1;
}
}
$relateListArray = array();
$goodscount = 0;
if(!empty($goodsInfo['relateSkus']))
{
$goodsIds = $goodsInfo['relateSkus'];
$aa = explode('|',$goodsIds);
$activityGoodsId = array_filter($aa);
$goodscount = count($activityGoodsId);
$relateList = $this->goods->getRelateGoodsList($activityGoodsId,4);
foreach($relateList as $key=>$value)
{
$imageInfo = $this->goodsimage->getGoodsImageOneInfo($value['goodsId']);
$relateListArray[$key]['imagePath'] = $this->config->item('hwclouds').$imageInfo['imagePath'];
$activityGoodsInfo = $this->goodsactivity->getDetailGoodsInfo( $activityIds ,$value['goodsId']);
$relateListArray[$key]['goodsId'] = $value['goodsId'];
$relateListArray[$key]['goodsJifen'] = $value['goodsJifen'];
$relateListArray[$key]['goodsTitle'] = empty($activityGoodsInfo['goodsActivityName'])?$value['goodsTitle']:$activityGoodsInfo['goodsActivityName'];
$relateListArray[$key]['activityJifen'] = empty($activityGoodsInfo['activityJifen'])?0:$activityGoodsInfo['activityJifen'];
}
}
$goodsInfoArray['goodsId'] = $goodsInfo['goodsId'];
$goodsInfoArray['goodsTitle'] = $goodsInfo['goodsTitle'];
$goodsInfoArray['goodsPrice'] = $goodsInfo['goodsPrice'];
$goodsInfoArray['goodsJifen'] = $goodsInfo['goodsJifen'] $goodsInfoArray['activityJifen'] = empty($goodsInfo['activityJifen'])?'0':$goodsInfo['activityJifen'] $goodsInfoArray['shoucang'] = $goodsInfo['shoucang'];
$goodsInfoArray['activityStatus'] = $activityStatus;
$spceList = $this->goodsspec->getGoodsSpecList(array('goodsId'=>$goodsId));
$commentCount = $this->comment->getCountCommentNum( $goodsId );
$searchParam = array('goodsId'=>$goodsId,'deleteFlag'=>0);
$start = 0;
$limit = 5;
$commentList = $this->comment->getGoodsCommentList($searchParam,'*', $limit, $start);
$commentListArray = array();
foreach($commentList as $key=>$value)
{
$commentListArray[$key]['createTime'] = format_time($value['createTime']);
$commentListArray[$key]['content'] = preg_replace_callback('/@E(.{6}==)/', function($r) {return base64_decode($r[1]);}, $value['content']);
$commentListArray[$key]['userName'] = $value['userName'];
}
echo $this->common->returnArray ( array (
'imageList' => $imageListArray 'detailImageList' => $detailImageListArray 'brandInfo' => $brandArray 'relateList' => $relateListArray 'goodsInfo' => $goodsInfoArray 'spceList' => $spceList 'commentCount' => $commentCount 'commentList' => $commentListArra ), '读取成功', 200 );exit;
}
public function ajaxComment()
{
$goodsId = $this->input->get_post('goodsId');
$token = $this->input->get_post('token');
$userId = $this->input->get_post('userId');
$start = $this->input->get_post('start');
$start = !empty($start) ? $start : 0;
$limit = 20;
$commentcount = 0;
$commentCount = $this->comment->getCountCommentNum( $goodsId );
$searchParam = array('goodsId'=>$goodsId,'deleteFlag'=>0);
$commentList = $this->comment->getGoodsCommentList($searchParam,'*', $limit, $start); if(empty($commentList))
{
echo $this->common->returnArray ( array ('commentList'=>''), '暂无数据', 2 );exit;
}
$commentListArray = array();
foreach($commentList as $key=>$value)
{
$commentListArray[$key]['createTime'] = format_time($value['createTime']);
$commentListArray[$key]['content'] = preg_replace_callback('/@E(.{6}==)/', function($r) {return base64_decode($r[1]);}, $value['content']);
$commentListArray[$key]['userName'] = $value['userName'];
$commentListArray[$key]['headUrl'] = empty($value['headUrl'])?$this->config->item('base_url').'/public/web/images/use_tx_03.png':$this->config->item('hwclouds').$value['headUrl'];
if(!empty($value['imagePath'])){
$value['imagePath'] = explode(',', $value['imagePath']);
foreach ( $value['imagePath'] as $k=> $v){
$v = str_replace('"', '', $v);
$commentListArray[$key]['imagePath'][$k] = $this->config->item('hwclouds').$v;
}
}else{
$commentListArray[$key]['imagePath']= array();
}
}
$commentCount=empty($commentCount)?0:$commentCount;
echo $this->common->returnArray ( array ('commentList'=>$commentListArray,'commentCount'=>$commentCount), '读取成功', 200 );exit;
}
public function addComment()
{
$goodsId = $this->input->get_post('goodsId');
$token = $this->input->get_post('token');
$userId = $this->input->get_post('userId');
if(empty($token)||empty($userId))
{
echo $this->common->returnArray ( array ('list'=>''), '请登录', 3 );exit;
}
$this->common->getLoginStuate($userId, $token) if(empty($goodsId))
{
echo $this->common->returnArray ( array ('list'=>''), '参数错误', 1 );exit;
}
$content = $this->input->get_post('content');
$imagePath= $this->input->get_post('imagePath');
$direction = $this->input->get_post('direction');
$logistics = $this->input->get_post('logistics');
$service = $this->input->get_post('service');
$orderid = $this->input->get_post('orderId');
if(empty($content))
{
echo $this->common->returnArray ( array ( 'list' => '' ), '评论内容不能为空', 600010 );exit;
}
$userInfo = $this->userinfo->getUserInfoRow($userId,2);
if(empty($userInfo))
{
$userInfo = $this->userinfo->getUserInfoRow($userId,1);
if(empty($userInfo))
{
$userInfo = $this->userinfo->getUserInfoRow($userId,0);
}
}
$realName = $userInfo['nickName'];
$headUrl = $userInfo['headUrl'];
$content = preg_replace_callback('/[\xf0-\xf7].{3}/', function($r) { return '@E' . base64_encode($r[0]);}, $content);
$userIP = $this->input->ip_address();
$commentData = array(
'goodsId' => $goodsId,
'content' => empty($content)?'':$content,
'imagePath'=>$imagePath,
'direction'=>$direction,
'logistics'=>$logistics,
'service'=>$service,
'userName' => $realName,
'userId' => $userId,
'createTime' => time(),
'userIP' => $userIP,
'headUrl'=>$headUrl
);
$bool = $this->comment->insertData($commentData);
if($bool)
{
$this->order->updateOrder( $orderId ,array('isvaluated'=>1) );
echo $this->common->returnArray ( array ( 'list' => '' ), '评论成功', 200 );exit;
}
else
{
echo $this->common->returnArray ( array ( 'list' => '' ), '评论失败', 201 );exit;
}
}
public function changeSpec()
{
$token = $this->input->get_post('token');
$userId = $this->input->get_post('userId');
$goodsId = $this->input->get_post('goodsId');
$specId = $this->input->get_post('specId');
$specInfo = $this->goodsspec->getGoodsSpecById($specId);
echo $this->common->returnArray ( array ( 'specInfo' => $specInfo ), '读取成功', 200 );exit;
}
public function buyNow()
{
$token = $this->input->get_post('token');
$userId = $this->input->get_post('userId');
$goodsId = $this->input->get_post('goodsId');
$goodsNum = $this->input->get_post('goodsNum');
$specId = $this->input->get_post('specId');
if(empty($token)||empty($userId))
{
echo $this->common->returnArray ( array ('list'=>''), '请登录', 3 );exit;
}
$this->common->getLoginStuate($userId, $token) if(empty($goodsId))
{
echo $this->common->returnArray ( array ('list'=>''), '参数错误', 1 );exit;
}
if(empty($specId))
{
echo $this->common->returnArray ( array ('list'=>''), '请选择商品规格', 700010);exit;
}
$addressInfo = $this->address->getListByUserId( $userId ,1) if(empty($addressInfo))
{
echo $this->common->returnArray ( array ('list'=>''), '请添加收货地址', 800010 );exit;
}
$goodsInfoArray = array();
$imageInfo = $this->goodsimage->getGoodsImageOneInfo($goodsId);
$goodsInfoArray['imagePath'] = $this->config->item('hwclouds').$imageInfo['imagePath'];
$goodsInfo = $this->goods->getGoodsById( $goodsId );
$activityInfo = $this->goodsactivity->getValidActivity();
$specInfo = $this->goodsspec->getGoodsSpecById($specId);
$goodsInfoArray['goodsId'] = $goodsId;
$goodsInfoArray['goodsNum'] = $goodsNum;
$goodsInfoArray['specId'] = $specId;
$activityIds = array();
if(!empty($activityInfo))
{
foreach($activityInfo as $key=>$value)
{
$activityIds[$key] = $value['activityId'];
}
}
$activityGoodsInfo = array();
if(!empty($activityIds))
{
$activityGoodsInfo = $this->goodsactivity->getDetailGoodsInfo( $activityIds ,$goodsId);
}
$activityStatus = 0;
if(!empty($activityGoodsInfo))
{
$goodsInfoArray['goodsTitle'] = empty($activityGoodsInfo['goodsActivityName'])?$goodsInfo['goodsTitle']:$activityGoodsInfo['goodsActivityName'];
$goodsInfoArray['activityJifen'] = $specInfo['goodsActivityJifen'];
$goodsInfoArray['specName'] = $specInfo['specName'];
}
else
{
$goodsInfoArray['goodsTitle'] = $goodsInfo['goodsTitle'];
$goodsInfoArray['goodsJifen'] = $specInfo['goodsJifen'];
$goodsInfoArray['specName'] = $specInfo['specName'];
}
$sum = 0;
if(empty($goodsInfo['activityJifen']))
{
$sum = $specInfo['goodsJifen']*intval($goodsNum);
}
else
{
$sum = $specInfo['goodsActivityJifen']*intval($goodsNum);
}
echo $this->common->returnArray ( array ('addressInfo'=>$addressInfo,'goodsInfo'=>$goodsInfoArray,'subtotal'=>$sum), '读取成功', 200 );exit;
}
public function submitOrder()
{
$token = $this->input->get_post('token');
$userId = $this->input->get_post('userId');
$userAddrId = $this->input->get_post('userAddrId') $goodsNum = $this->input->get_post('goodsNum') $goodsJifen = $this->input->get_post('goodsJifen') $goodsId = $this->input->get_post('goodsId') $specId = $this->input->get_post('specId') $subtotal = $this->input->get_post('subtotal') $goodsInfo = $this->goods->getGoodsById( $goodsId );
$imageInfo = $this->goodsimage->getGoodsImageOneInfo($goodsId);
$imagePath = empty($imageInfo['imagePath'])?'':$imageInfo['imagePath'];
if(empty($token)||empty($userId))
{
echo $this->common->returnArray ( array ('list'=>''), '请登录', 3 );exit;
}
$this->common->getLoginStuate($userId, $token) if(empty($goodsId))
{
echo $this->common->returnArray ( array ('list'=>''), '参数错误', 1 );exit;
}
if(empty($specId))
{
echo $this->common->returnArray ( array ('list'=>''), '请选择商品规格', 700010 );exit;
}
$userInfo = $this->userinfo->getUserInfoRow($userId,2);
if(empty($userInfo))
{
$userInfo = $this->userinfo->getUserInfoRow($userId,1);
if(empty($userInfo))
{
$userInfo = $this->userinfo->getUserInfoRow($userId,0);
}
}
$realName = empty($userInfo['nickName'])?'':$userInfo['nickName'];
$user = $this->user->getUserRow( $userId );
if(empty($user['userName']))
{
$userName = $user['email'];
}
else if(empty($user['email']))
{
$userName = $user['phone'];
}
else
{
$userName = $user['userName'];
}
$remarks = $this->input->get_post('remarks');
$orderData = array(
'goodsNum' => $goodsNum,
'goodsTotalNum' => $subtotal,
'userId' => $userId,
'addressId' =>$userAddrId,
'userName' => $userName,
'realName' => $realName,
'orderPostageJifen' => 0,
'createTime' => time(),
'payTime' => time(),
'payStatus' => 0,
'orderStatus' => 0,
'remarks'=>$remarks
);
$bool = $this->order->addOrder($orderData) $specInfo = $this->goodsspec->getGoodsSpecById( $specId );
$orderGoods = array(
'goodsId' => $goodsId,
'orderId' => $bool,
'goodsName' => $goodsInfo['goodsTitle'],
'goodsImage' => $imagePath,
'goodsJifen' => $goodsJifen,
'specId' => $specId,
'specName' => empty($specInfo['specName'])?'':$specInfo['specName'],
'inventory' => $goodsNum
);
$this->ordergoods->addOrderGoods($orderGoods) echo $this->common->returnArray ( array ('orderId'=>$bool), '订单提交成功', 200 );exit;
}
public function pay()
{
$token = $this->input->get_post('token');
$userId = $this->input->get_post('userId');
$orderId = $this->input->get_post('orderId');
$payPassword = $this->input->get_post('payPassword');
if(empty($token)||empty($userId))
{
echo $this->common->returnArray ( array ('list'=>''), '请登录', 3 );exit;
}
$this->common->getLoginStuate($userId, $token) $orderInfo = $this->order->getUserOrderRow( $orderId );
$goodsJifen = $orderInfo['goodsTotalNum'];
$user = $this->user->getUserRow( $userId );
$payNum =0;
$payPasswords = $user['payPassword'];
if(empty($payPasswords))
{
echo $this->common->returnArray ( array ('list'=>''), '您未设置支付密码,暂不能支付', 900010);exit;
}
else if(md5($payPassword) !=$payPasswords)
{
$payNum++;
echo $this->common->returnArray ( array ('list'=>''), '支付密码输入错误', 900011);exit;
}
if($payNum>3)
{
echo $this->common->returnArray ( array ('list'=>''), '支付密码超过3次,无法支付', 900012);exit;
}
if(md5($payPassword) ==$payPasswords)
{
$userCount =$this->usercount->getUserCountRow( $userId );
$jifenNum = $userCount['jifenNum'] - $userCount['jifenConsumptionNum'];
if($goodsJifen > $jifenNum)
{
echo $this->common->returnArray ( array ('list'=>''), '积分余额不足,请充值', 900013);exit;
}
else
{
$this->order->updateOrder( $orderId ,array('payStatus'=>1,'orderStatus'=>2) );
$goodsList = $this->ordergoods->getGoodsById( $orderId );
foreach($goodsList as $key=>$value)
{
$this->goods->updateNum(array('inventory'=>'inventory-'.$value['inventory']),$value['goodsId']);
$this->goodsspec->updateInventory(array('specId'=>$value['specId']),array('inventory'=>'inventory-'.$value['inventory']));
}
$this->usercount->updateNum( array('jifenConsumptionNum'=>'jifenConsumptionNum+'.$goodsJifen) ,$userId );
echo $this->common->returnArray ( array ('list'=>''), '支付成功', 200 );exit;
}
}
}
public function paySuccess()
{
$token = $this->input->get_post('token');
$userId = $this->input->get_post('userId');
$orderId = $this->input->get_post('orderId');
if(empty($token)||empty($userId))
{
echo $this->common->returnArray ( array ('goodsList'=>''), '请登录',3 );exit;
}
$this->common->getLoginStuate($userId, $token) if(empty($orderId))
{
echo $this->common->returnArray ( array ('goodsList'=>''), '参数错误',1 );exit;
}
$orderInfo = $this->order->getUserOrderRow( $orderId );
if($orderInfo['orderStatus']==0)
{
echo $this->common->returnArray ( array ('goodsList'=>''), '未支付',900014 );exit;
}
$goodsJifen = $orderInfo['goodsTotalNum'];
$goodsList = $this->ordergoods->getGoodsById( $orderId );
$goodsListArray = array();
foreach($goodsList as $key=>$value)
{
$goodsInfo = $this->goods->getGoodsById( $value['goodsId'] );
$goodsListArray[$key]['goodsId'] = $value['goodsId'];
$goodsListArray[$key]['goodstitle'] = $value['goodsName'];
$goodsListArray[$key]['goodsJifen'] = $value['goodsJifen'];
}
echo $this->common->returnArray ( array ('goodsList'=>$goodsListArray) , '支付成功', 200 );exit;
}
public function addAddress()
{
$token = $this->input->get_post('token');
$userId = $this->input->get_post('userId');
if(empty($token)||empty($userId))
{
echo $this->common->returnArray ( array ('list'=>''), '请登录', 3 );exit;
}
$this->common->getLoginStuate($userId, $token) $userName = $this->input->get_post('userName');
$userPhone = $this->input->get_post('userPhone');
$provinceName = $this->input->get_post('provinceName');
$cityName = $this->input->get_post('cityName');
$areaName = $this->input->get_post('areaName');
$address = $this->input->get_post('address');
$zipcode = $this->input->get_post('zipcode');
$isDefault = $this->input->get_post('isDefault');
$addressData = array(
'userId' => $userId,
'provinceName' => $provinceName,
'cityName' => $cityName,
'areaName' => $areaName,
'address' => $address,
'isDefault' => empty($isDefault)?0:$isDefault,
'userName' => $userName,
'userPhone' => $userPhone,
'zipcode'=>$zipcode
);
if($isDefault==1)
{
$this->address->updateUserAddress( $userId ,array('isDefault'=>0));
}
$bool = $this->address->addAddress( $addressData );
$msg = $bool?'添加成功':'添加失败';
$code = $bool?'200':'201';
echo $this->common->returnArray ( array ('list'=>'') , $msg , $code );exit;
}
public function delAddress()
{
$token = $this->input->get_post('token');
$userId = $this->input->get_post('userId');
$userAddrId = $this->input->get_post('userAddrId');
if(empty($token)||empty($userId))
{
echo $this->common->returnArray ( array ('list'=>''), '请登录', 3 );exit;
}
$this->common->getLoginStuate($userId, $token) $addrInfo = $this->address->getAddressRow( $userAddrId );
if(empty($addrInfo))
{
echo $this->common->returnArray ( array ('list'=>''), '参数错误', 1 );exit;
}
$bool = $this->address->delAddress( $userAddrId );
$msg = $bool?'删除成功':'删除失败';
$code = $bool?'200':'201';
echo $this->common->returnArray ( array ('list'=>'') , $msg , $code );exit;
}
public function setDefaultAddress()
{
$token = $this->input->get_post('token');
$userId = $this->input->get_post('userId');
$userAddrId = $this->input->get_post('userAddrId');
if(empty($token)||empty($userId))
{
echo $this->common->returnArray ( array ('list'=>''), '请登录', 3 );exit;
}
$this->common->getLoginStuate($userId, $token) $addrInfo = $this->address->getAddressRow( $userAddrId );
if(empty($addrInfo))
{
echo $this->common->returnArray ( array ('list'=>''), '参数错误', 1 );exit;
}
$this->address->updateUserAddress( $userId ,array('isDefault'=>0));
$bool = $this->address->setAddress($userAddrId,array('isDefault'=>1));
$msg = $bool?'设置默认地址成功':'设置默认地址失败';
$code = $bool?'200':'201';
echo $this->common->returnArray ( array ('list'=>'') , $msg , $code );exit;
}
public function getProvinceList()
{
$provinceList = $this->province->getProvinceList('provinceCode,provinceName');
foreach( $provinceList as $key=>$value)
{
$array[$key]['name'] = $value['provinceName'];
$str = substr($value['provinceCode'],0,2);
$cityList = $this->province->getCity('cityCode,cityName',$str);
foreach($cityList as $k=>$v)
{
$array[$key]['city'][$k]['name'] =$v['cityName'];
$strcity = substr($v['cityCode'],0,4);
$areaList = $this->province->getArea('areaCode,areaName',$strcity);
foreach($areaList as $a=>$b)
{
$array[$key]['city'][$k]['area'][$a] =$b['areaName'];
}
}
}
echo $this->common->returnArray ( array ('provinceList'=>$array), '读取成功', 200 );exit;
}
public function getCityList()
{
$provinceCode = $this->input->get_post('provinceCode');
$str = substr($provinceCode,0,2);
$cityList = $this->province->getCity('cityCode,cityName',$str);
echo $this->common->returnArray ( array ('cityList'=> $cityList), '读取成功', 200 );exit;
}
public function getAreaList()
{
$cityCode = $this->input->get_post('cityCode');
$str = substr($cityCode,0,4);
$areaList = $this->province->getArea('areaCode,areaName',$str);
echo $this->common->returnArray ( array ('areaList'=> $areaList), '读取成功', 200 );exit;
}
public function getUserAddress()
{
$token = $this->input->get_post('token');
$userId = $this->input->get_post('userId');
if(empty($token)||empty($userId))
{
echo $this->common->returnArray ( array ('list'=>''), '请登录', 3 );exit;
}
$this->common->getLoginStuate($userId, $token) $addressList = $this->address->getUserAddressList( $userId );
if(empty($addressList))
{
echo $this->common->returnArray ( array ('list'=>''), '暂无收货地址', 1000010 );exit;
}
echo $this->common->returnArray ( array ('addressList'=>$addressList), '读取成功', 200 );exit;
}
public function editAddress()
{
$token = $this->input->get_post('token');
$userId = $this->input->get_post('userId');
$userAddrId = $this->input->get_post('userAddrId');
if(empty($token)||empty($userId))
{
echo $this->common->returnArray ( array ('list'=>''), '请登录', 3 );exit;
}
$this->common->getLoginStuate($userId, $token) if(empty($userAddrId))
{
echo $this->common->returnArray ( array ('list'=>''), '参数错误', 1 );exit;
}
$userName = $this->input->get_post('userName');
$userPhone = $this->input->get_post('userPhone');
$provinceName = $this->input->get_post('provinceName');
$cityName = $this->input->get_post('cityName');
$areaName = $this->input->get_post('areaName');
$address = $this->input->get_post('address');
$zipcode = $this->input->get_post('zipcode');
$isDefault = $this->input->get_post('isDefault');
if(!empty($isDefault)){
$getaddressarray = $this->address->getUserAddressList($userId);
if(!empty($getaddressarray)){
foreach ($getaddressarray as $value){
$uarrid = $value['userAddrId'];
unset($value['userAddrId']);
$value['isDefault']=0;
$bool = $this->address->setAddress($uarrid, $value);
}
}
}
if(empty($userName))
{
echo $this->common->returnArray ( array ('list'=>''), '请输入收件人姓名', 1000011);exit;
}
else if(mb_strlen($userName)>30)
{
echo $this->common->returnArray ( array ('list'=>''), '收件人姓名不能大于30个字符', 1000012);exit;
}
if(empty($userPhone))
{
echo $this->common->returnArray ( array ('list'=>''), '请输入收件人手机号', 1000013);exit;
}
if(empty($address))
{
echo $this->common->returnArray ( array ('list'=>''), '请输入详情地址', 1000014);exit;
}
else if(mb_strlen($address)>100)
{
echo $this->common->returnArray ( array ('list'=>''), '详情地址不能超过100个字符', 1000015);exit;
}
$addressData = array(
'userId' => $userId,
'provinceName' => $provinceName,
'cityName' => $cityName,
'areaName' => $areaName,
'address' => $address,
'isDefault' => empty($isDefault)?0:$isDefault,
'userName' => $userName,
'userPhone' => $userPhone,
'zipcode' =>$zipcode
);
$bool = $this->address->setAddress($userAddrId, $addressData );
$msg = $bool?'修改成功':'修改失败';
$code = $bool?'200':'201';
echo $this->common->returnArray ( array ('list'=>'') , $msg , $code );exit;
}
public function activity()
{
$activityList = $this->goodsactivity->getWebGoodsActivityList();
$time = time();
$activityListArray = array();
foreach($activityList as $key=>$value)
{
$activityListArray[$key]['activityId'] = $value['activityId'];
$activityListArray[$key]['activityName'] = $value['activityName'];
$activityListArray[$key]['startTime'] = date('Y-m-d H:i:s',$value['startTime']);
$activityListArray[$key]['endTime'] = date('Y-m-d H:i:s',$value['endTime']);
$activityListArray[$key]['linkUrl'] = $value['linkUrl'];
$activityListArray[$key]['status'] = 0;
if($value['startTime']>$time {
$activityListArray[$key]['styleclass'] = 'start1';
$activityListArray[$key]['status'] = 1;
}
else if(($value['startTime']<$time &&$value['endTime']>$time) {
$activityListArray[$key]['styleclass'] = 'start2';
$activityListArray[$key]['status'] = 2;
}
else if($value['endTime']<$time || $value['activityStatus']==2 {
$activityListArray[$key]['styleclass'] = 'start3';
}
$activityListArray[$key]['imagePath'] = $this->config->item('hwclouds').$value['activityImage'];
}
echo $this->common->returnArray ( array ( 'activityList' => $activityListArray ), '读取成功', 200 );exit;
}
public function activityGoodsList()
{
$token = $this->input->get_post('token');
$userId = $this->input->get_post('userId');
$activityId = $this->input->get_post('activityId');
$activityInfo = $this->goodsactivity->getGoodsActivityRow( $activityId );
if(empty($activityInfo['activityStatus']))
{
echo $this->common->returnArray ( array ( 'goodsList' => '' ), '活动未开始', 200 );exit;
}
else if($activityInfo['activityStatus']==2)
{
echo $this->common->returnArray ( array ( 'goodsList' => '' ), '活动已结束', 200 );exit;
}
else if($activityInfo['startTime']<time() && $activityInfo['endTime']<time())
{
echo $this->common->returnArray ( array ( 'goodsList' => '' ), '活动未开始', 200 );exit;
}
else if($activityInfo['endTime']<time())
{
echo $this->common->returnArray ( array ( 'goodsList' => '' ), '活动已结束', 200 );exit;
}
$goodsList = $this->goodsactivity->getActivityGoodsInfo( $activityId );
$goodsListArray = array();
foreach($goodsList as $key=>$value)
{
$imageInfo = $this->goodsimage->getGoodsImageOneInfo($value['goodsId']);
$goodsListArray[$key]['goodsId'] = $value['goodsId'];
$goodsListArray[$key]['goodsActivityName'] = $value['goodsActivityName'];
$goodsListArray[$key]['activityJifen'] = $value['activityJifen'];
$goodsListArray[$key]['goodsJifen'] = $value['goodsJifen'];
$goodsListArray[$key]['imagePath'] = $this->config->item('hwclouds').$imageInfo['imagePath'];
}
echo $this->common->returnArray ( array ( 'goodsList' => $goodsListArray ), '读取成功', 200 );exit;
}
public function collection()
{
$token = $this->input->get_post('token');
$userId = $this->input->get_post('userId');
$goodsId = $this->input->get_post('goodsId');
$status = $this->input->get_post('status');
if(empty($token)||empty($userId))
{
echo $this->common->returnArray ( array ('list'=>''), '请登录',3 );exit;
}
$this->common->getLoginStuate($userId, $token) if(empty($goodsId))
{
echo $this->common->returnArray ( array ('list'=>''), '参数错误', 1 );exit;
}
$collectionInfo = $this->collection->getCollectionRow($goodsId,$userId);
if(!empty($collectionInfo) || empty($status))
{
$this->collection->delete($collectionInfo['collectId']);
echo $this->common->returnArray ( array ( 'list' => '' ), '取消收藏成功', 200 );exit;
}
$collectionData = array(
'goodsId' => $goodsId,
'userId' => $userId,
'createTime' => time()
);
$bool = $this->collection->insertData( $collectionData );
echo $this->common->returnArray ( array ( 'list' => '' ), '收藏成功', 200 );exit;
}
public function goodsearch(){
$token = $this->input->get_post('token');
$keyword = $this->input->get_post('keyword');
if(empty($keyword))
{
echo $this->common->returnArray ( array ('goodsList'=>''), '搜索内容不能为空', 1 );exit;
}
$start = $this->input->get_post('start');
$start = empty($start)?0:$start;
$limit = 10;
$condition['goodsTitle'] = $keyword;
$goodsList = $this->goods->getActivityGoodsList( $condition, $limit, $start );
$activityInfo = $this->goodsactivity->getValidActivityList();
$goodsIds = array();
if(!empty($activityInfo))
{
foreach($activityInfo as $key=>$value)
{
$activityIds[$key] = $value['activityId'];
}
$goodsIdList = $this->goodsactivity->getActivityGoodsList( $activityIds );
if(!empty($goodsIdList))
{
foreach($goodsIdList as $key=>$value)
{
$goodsIds[$value['agId']] = $value['goodsId'];
}
}
}
$goodsInfo = array();
$num = count($goodsList);
foreach($goodsList as $key=>$value)
{
$goodsInfo[$key]['goodsId'] = $value['goodsId'];
$imageInfo = $this->goodsimage->getGoodsImageOneInfo($value['goodsId']);
$goodsInfo[$key]['imagePath'] = $this->config->item('hwclouds').$imageInfo['imagePath'];
if(in_array($value['goodsId'], $goodsIds))
{
$a = array_search($value['goodsId'], $goodsIds);
$activityList = $this->goodsactivity->getActivityGoodsInfoRow($a);
$goodsInfo[$key]['goodsActivityJifen'] = $activityList['activityJifen'];
$goodsInfo[$key]['goodsJifen'] = $activityList['goodsJifen'];
$goodsInfo[$key]['goodsTitle'] = $activityList['goodsActivityName'];
}
else
{
$goodsInfo[$key]['goodsJifen'] = $value['goodsJifen'];
$goodsInfo[$key]['goodsTitle'] = $value['goodsTitle'];
}
}
echo $this->common->returnArray ( array ('goodsList'=>$goodsInfo), '读取成功', 200 );exit;
}
}