200 lines
5.8 KiB
PHP
Executable File
200 lines
5.8 KiB
PHP
Executable File
<?php
|
||
namespace wstmart\app\controller;
|
||
use wstmart\common\model\Carts as M;
|
||
use wstmart\common\model\UserAddress;
|
||
use wstmart\common\model\Payments;
|
||
/**
|
||
* ============================================================================
|
||
* 购物车控制器
|
||
*/
|
||
class Carts extends Base{
|
||
|
||
// 前置方法执行列表
|
||
protected $beforeActionList = [
|
||
'checkAuth'
|
||
];
|
||
/**
|
||
* 批量修改购物车状态
|
||
*/
|
||
public function batchChangeCartGoods(){
|
||
$m = new M();
|
||
$rs = $m->batchChangeCartGoods();
|
||
exit(json_encode($rs));
|
||
}
|
||
/**
|
||
* 查看购物车列表
|
||
*/
|
||
public function index(){
|
||
$m = new M();
|
||
$carts = $m->getCarts(false);
|
||
exit(jsonReturn("",1,$carts));
|
||
}
|
||
/**
|
||
* 加入购物车
|
||
*/
|
||
public function addCart(){
|
||
$m = new M();
|
||
$rs = $m->addCart();
|
||
$rs['cartNum'] = WSTCartNum();
|
||
exit(json_encode($rs));
|
||
}
|
||
/**
|
||
* 修改购物车商品状态
|
||
*/
|
||
public function changeCartGoods(){
|
||
$m = new M();
|
||
$rs = $m->changeCartGoods();
|
||
exit(json_encode($rs));
|
||
}
|
||
/**
|
||
* 删除购物车里的商品
|
||
*/
|
||
public function delCart(){
|
||
$m = new M();
|
||
$rs= $m->delCart();
|
||
exit(json_encode($rs));
|
||
}
|
||
/**
|
||
* 计算运费、惠宝和总商品价格
|
||
*/
|
||
public function getCartMoney(){
|
||
$m = new M();
|
||
$data = $m->getCartMoney();
|
||
exit(json_encode($rs));
|
||
}
|
||
/**
|
||
* 计算运费、惠宝和总商品价格
|
||
*/
|
||
public function getMoney(){
|
||
$type = (int)input('type');
|
||
if($type == 1){
|
||
$rs = model('carts')->getMoney();//立即下单获取价格
|
||
}else{
|
||
$m = new M();
|
||
$rs =$m->getCartMoney();//购物车获取价格
|
||
}
|
||
exit(json_encode($rs));
|
||
}
|
||
/**
|
||
* 计算运费、惠宝和总商品价格/虚拟商品
|
||
*/
|
||
public function getQuickCartMoney(){
|
||
$m = new M();
|
||
$data = $m->getQuickCartMoney();
|
||
return $data;
|
||
}
|
||
/**
|
||
* 立即购买保存下参数
|
||
* @return [type] [description]
|
||
*/
|
||
public function buy(){
|
||
$rs = model('Carts')->buy();
|
||
exit(json_encode($rs));
|
||
}
|
||
/**
|
||
* 跳去购物车结算页面
|
||
*/
|
||
public function settlement(){
|
||
|
||
$m = new M();
|
||
//获取一个用户地址
|
||
$addressId = (int)input('addressId');
|
||
$ua = new UserAddress();
|
||
if($addressId>0){
|
||
$userAddress = $ua->getById($addressId);
|
||
}else{
|
||
$userAddress = $ua->getDefaultAddress();
|
||
}
|
||
//$this->assign('userAddress',$userAddress);
|
||
//获取支付方式
|
||
$pa = new Payments();
|
||
$payments = $pa->getByGroup('4',-1,true);//具体支付场景1pc,2wap,3微信,4app
|
||
|
||
//dump($payments);
|
||
//获取已选的购物车商品
|
||
//$carts = $m->getCarts(true, 0, $userAddress);// 添加运费显示 mark hsf 20171116
|
||
$userId = (int)session('WST_USER.userId');
|
||
$areaId2 = isset($userAddress['areaId2']) ? $userAddress['areaId2'] : 0;
|
||
|
||
$type = (int)input('type');
|
||
if($type == 1){
|
||
$carts = model('carts')->buyNow($areaId2);//立即下单结算方式
|
||
}else{
|
||
$carts = $m->getCarts(true, 0, $areaId2);
|
||
}
|
||
if(empty($carts['carts'])){
|
||
exit(jsonReturn('未找到相关商品',-1));
|
||
}
|
||
// //$carts = $m->getCarts(true, 0, $userAddress);购物车结算方式
|
||
hook("appControllerCartsSettlement",["carts"=>$carts,"payments"=>&$payments]);
|
||
// //ect整合相关优惠还有判断不能和在线支付商品一块
|
||
// hook("ectIntegration",["carts"=>&$carts,'isSettlement'=>true,'uId'=>(int)session('WST_USER.userId')]);
|
||
//
|
||
// //获取用户惠宝
|
||
$user = model('users')->getFieldsById($userId,'userScore,loginName,userMoney,userECT');
|
||
// //计算可用惠宝和金额
|
||
// $goodsTotalMoney = round((($carts['goodsTotalMoney'] - $carts['promotionMoney'] - $carts['allShippingMoney']) * HuiScale()),2);//$carts['goodsTotalMoney']; 惠宝最多可抵用20% mark 20170907
|
||
// $goodsTotalScore = WSTScoreToMoney($goodsTotalMoney,true);
|
||
// $useOrderScore =0;
|
||
// $useOrderMoney = 0;
|
||
// // if(!isset($carts['ect_pay']) || !$carts['ect_pay']){
|
||
// if($user['userScore']>$goodsTotalScore){//个人所有积分大于订单可抵用的积分
|
||
// $useOrderScore = $goodsTotalScore;//可抵下的积分
|
||
// $useOrderMoney = $goodsTotalMoney;//可抵下的金额
|
||
// }else{
|
||
// $useOrderScore = $user['userScore'];//可抵下的积分为自已所有的积分
|
||
// $useOrderMoney = WSTScoreToMoney($useOrderScore);//转换成金额
|
||
// }
|
||
// // }
|
||
$data = $carts;
|
||
$data['loginName'] = $user['loginName'];
|
||
$data['userMoney'] = $user['userMoney'];
|
||
$data['userECT'] = $user['userECT'];
|
||
$data['userAddress'] = $userAddress;
|
||
$data['payments'] = $payments;
|
||
$data['useOrderScore'] = 0;// $useOrderScore;//可抵积分
|
||
$data['useOrderMoney'] = 0;//$useOrderMoney;//可抵积分换算成金额
|
||
exit(jsonReturn('',1,$data));
|
||
}
|
||
/**
|
||
* 跳去虚拟商品购物车结算页面
|
||
*/
|
||
public function quickSettlement(){
|
||
$m = new M();
|
||
//获取支付方式
|
||
$pa = new Payments();
|
||
$payments = $pa->getByGroup('2');
|
||
$this->assign('payments',$payments);
|
||
//获取用户惠宝
|
||
$user = model('users')->getFieldsById((int)session('WST_USER.userId'),'userScore');
|
||
//获取已选的购物车商品
|
||
$carts = $m->getQuickCarts();
|
||
//计算可用惠宝和金额
|
||
$goodsTotalMoney = $carts['goodsTotalMoney'];
|
||
$goodsTotalScore = WSTScoreToMoney($goodsTotalMoney,true);
|
||
$useOrderScore =0;
|
||
$useOrderMoney = 0;
|
||
if($user['userScore']>$goodsTotalScore){
|
||
$useOrderScore = $goodsTotalScore;
|
||
$useOrderMoney = $goodsTotalMoney;
|
||
}else{
|
||
$useOrderScore = $user['userScore'];
|
||
$useOrderMoney = WSTScoreToMoney($useOrderScore);
|
||
}
|
||
$this->assign('userOrderScore',$useOrderScore);
|
||
$this->assign('userOrderMoney',$useOrderMoney);
|
||
|
||
$this->assign('carts',$carts);
|
||
return $this->fetch('settlement_quick');
|
||
}
|
||
|
||
/**
|
||
* APP购物车推荐商品
|
||
*/
|
||
public function recommendGoods(){
|
||
$m = new M();
|
||
$recommendGoods = $m->recommendGoods();
|
||
exit(json_encode($recommendGoods));
|
||
}
|
||
}
|