Buy.php 3.3 KB
Newer Older
D
v1.2.0  
devil_gong 已提交
1 2 3 4
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
D
devil_gong 已提交
5
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
D
v1.2.0  
devil_gong 已提交
6 7 8 9 10 11 12
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\api\controller;

D
Devil 已提交
13
use app\service\BaseService;
14 15 16 17
use app\service\GoodsService;
use app\service\UserService;
use app\service\PaymentService;
use app\service\BuyService;
D
devil 已提交
18
use app\service\PluginsService;
D
v1.2.0  
devil_gong 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

/**
 * 购买
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-01T21:51:08+0800
 */
class Buy extends Common
{
    /**
     * 构造方法
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-11-30
     * @desc    description
     */
    public function __construct()
    {
        parent::__construct();

        // 是否登录
G
gongfuxiang 已提交
42
        $this->IsLogin();
D
v1.2.0  
devil_gong 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56
    }
    
    /**
     * [Index 首页]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2017-02-22T16:50:32+0800
     */
    public function Index()
    {
        // 获取商品列表
        $params = $this->data_post;
        $params['user'] = $this->user;
D
devil 已提交
57
        $buy_ret = BuyService::BuyTypeGoodsList($params);
D
v1.2.0  
devil_gong 已提交
58 59

        // 商品校验
D
devil 已提交
60
        if(isset($buy_ret['code']) && $buy_ret['code'] == 0)
D
v1.2.0  
devil_gong 已提交
61
        {
D
devil 已提交
62 63 64 65
            // 基础信息
            $buy_base = $buy_ret['data']['base'];
            $buy_goods = $buy_ret['data']['goods'];

D
v1.2.0  
devil_gong 已提交
66 67 68 69 70
            // 支付方式
            $payment_list = PaymentService::BuyPaymentList(['is_enable'=>1, 'is_open_user'=>1]);

            // 数据返回组装
            $result = [
D
Devil 已提交
71 72 73 74
                'goods_list'        => $buy_goods,
                'payment_list'      => $payment_list,
                'base'              => $buy_base,
                'common_site_type'  => (int) $buy_base['common_site_type'],
D
v1.2.0  
devil_gong 已提交
75
            ];
D
devil 已提交
76 77

            // 优惠劵
D
devil 已提交
78
            $ret = PluginsService::PluginsControlCall('coupon', 'coupon', 'buy', 'api', ['order_goods'=>$buy_goods, 'params'=>$params]);
D
devil 已提交
79 80 81 82 83
            if($ret['code'] == 0 && isset($ret['data']['code']) && $ret['data']['code'] == 0)
            {
                $result['plugins_coupon_data'] = $ret['data']['data'];
            }

D
Devil 已提交
84 85 86 87 88 89 90
            // 积分
            $ret = PluginsService::PluginsControlCall('points', 'index', 'buy', 'api', ['order_goods'=>$buy_goods, 'params'=>$params]);
            if($ret['code'] == 0 && isset($ret['data']['code']) && $ret['data']['code'] == 0)
            {
                $result['plugins_points_data'] = $ret['data']['data'];
            }

D
Devil 已提交
91
            return BaseService::DataReturn($result);
D
v1.2.0  
devil_gong 已提交
92
        }
D
devil 已提交
93
        return $buy_ret;
D
v1.2.0  
devil_gong 已提交
94 95 96 97 98 99 100 101 102 103 104 105 106 107
    }

    /**
     * 订单添加
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-25
     * @desc    description
     */
    public function Add()
    {
        $params = $this->data_post;
        $params['user'] = $this->user;
D
devil_gong 已提交
108
        return BuyService::OrderInsert($params);
D
v1.2.0  
devil_gong 已提交
109 110 111
    }
}
?>