vr-shopxo-source/Application/Api/Controller/BuyController.class.php

107 lines
3.0 KiB
PHP
Raw Normal View History

2018-08-04 17:54:43 +00:00
<?php
namespace Api\Controller;
2018-11-14 06:34:32 +00:00
use Service\ResourcesService;
2018-11-21 17:02:38 +00:00
use Service\BuyService;
use Service\UserService;
2018-11-14 06:34:32 +00:00
2018-08-04 17:54:43 +00:00
/**
* 购买确认
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-03-02T22:48:35+0800
*/
class BuyController extends CommonController
{
/**
* [_initialize 前置操作-继承公共前置方法]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-03-02T22:48:35+0800
*/
public function _initialize()
{
// 调用父类前置方法
parent::_initialize();
// 是否ajax请求
if(!IS_AJAX)
{
$this->error(L('common_unauthorized_access'));
}
// 登录校验
$this->Is_Login();
}
/**
* 购买确认
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-07-20
* @desc description
*/
public function Index()
{
2018-11-21 17:02:38 +00:00
// 获取商品列表
2018-11-23 09:59:58 +00:00
$params = $this->data_post;
2018-11-21 17:02:38 +00:00
$params['user'] = $this->user;
$ret = BuyService::BuyTypeGoodsList($params);
2018-08-04 17:54:43 +00:00
2018-11-21 17:02:38 +00:00
// 商品校验
if(isset($ret['code']) && $ret['code'] == 0)
{
2018-11-26 09:29:06 +00:00
// 用户默认地址
$address = UserService::UserDefaultAddress(['user'=>$this->user]);
2018-11-21 17:02:38 +00:00
// 商品/基础信息
$base = [
'total_price' => empty($ret['data']) ? 0 : array_sum(array_column($ret['data'], 'total_price')),
'total_stock' => empty($ret['data']) ? 0 : array_sum(array_column($ret['data'], 'stock')),
2018-11-26 09:29:06 +00:00
'address' => empty($address['data']) ? null : $address['data'],
2018-11-21 17:02:38 +00:00
];
2018-08-04 17:54:43 +00:00
2018-11-22 09:50:11 +00:00
// 支付方式
2018-11-21 17:02:38 +00:00
$payment_list = ResourcesService::BuyPaymentList(['is_enable'=>1, 'is_open_user'=>1]);
2018-11-22 09:50:11 +00:00
// 扩展展示数据
$extension_list = [
// ['name'=>'感恩节9折', 'tips'=>'-¥23元'],
// ['name'=>'运费', 'tips'=>'+¥10元'],
];
// 数据返回组装
2018-11-21 17:02:38 +00:00
$result = [
2018-11-26 07:29:21 +00:00
'goods_list' => $ret['data'],
'payment_list' => $payment_list,
'base' => $base,
'extension_list' => $extension_list,
'common_order_is_booking' => (int) MyC('common_order_is_booking', 0),
2018-11-21 17:02:38 +00:00
];
$this->ajaxReturn(L('common_operation_success'), 0, $result);
} else {
$this->ajaxReturn(isset($ret['msg']) ? $ret['msg'] : L('common_param_error'), -100);
}
2018-08-04 17:54:43 +00:00
}
/**
2018-11-22 09:50:11 +00:00
* 订单添加
2018-08-04 17:54:43 +00:00
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
2018-11-22 09:50:11 +00:00
* @date 2018-09-25
2018-08-04 17:54:43 +00:00
* @desc description
*/
2018-11-22 09:50:11 +00:00
public function Add()
2018-08-04 17:54:43 +00:00
{
2018-11-23 09:59:58 +00:00
$params = $this->data_post;
2018-11-22 09:50:11 +00:00
$params['user'] = $this->user;
$ret = BuyService::OrderAdd($params);
$this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
2018-08-04 17:54:43 +00:00
}
}
?>