Order.php 10.1 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\index\controller;

13 14
use app\service\OrderService;
use app\service\PaymentService;
D
devil_gong 已提交
15
use app\service\GoodsCommentsService;
D
devil_gong 已提交
16
use app\service\ConfigService;
D
devil_gong 已提交
17
use app\service\SeoService;
D
v1.2.0  
devil_gong 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

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

        // 是否登录
41
        $this->IsLogin();
D
v1.2.0  
devil_gong 已提交
42 43 44 45 46 47 48 49 50 51 52 53
    }

    /**
     * 订单列表
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-28
     * @desc    description
     */
    public function Index()
    {
D
devil 已提交
54 55
        // 总数
        $total = OrderService::OrderTotal($this->form_where);
D
v1.2.0  
devil_gong 已提交
56 57

        // 分页
D
devil 已提交
58 59 60 61 62 63 64
        $page_params = [
            'number'    =>  $this->page_size,
            'total'     =>  $total,
            'where'     =>  $this->data_request,
            'page'      =>  $this->page,
            'url'       =>  MyUrl('admin/order/index'),
        ];
D
v1.2.0  
devil_gong 已提交
65 66 67
        $page = new \base\Page($page_params);

        // 获取列表
D
devil 已提交
68
        $data_params = [
D
devil 已提交
69 70 71 72 73
            'm'                 => $page->GetPageStarNumber(),
            'n'                 => $this->page_size,
            'where'             => $this->form_where,
            'is_orderaftersale' => 1,
            'user_type'         => 'user',
D
devil 已提交
74 75
        ];
        $ret = OrderService::OrderList($data_params);
D
v1.2.0  
devil_gong 已提交
76

D
devil 已提交
77 78 79
        // 发起支付 - 支付方式
        $this->assign('buy_payment_list', PaymentService::BuyPaymentList(['is_enable'=>1, 'is_open_user'=>1]));

D
devil 已提交
80 81
        // 加载百度地图api
        $this->assign('is_load_baidu_map_api', 1);
D
v1.2.0  
devil_gong 已提交
82

D
devil_gong 已提交
83 84 85
        // 浏览器名称
        $this->assign('home_seo_site_title', SeoService::BrowserSeoTitle('我的订单', 1));

D
devil 已提交
86 87 88 89
        // 基础参数赋值
        $this->assign('params', $this->data_request);
        $this->assign('page_html', $page->GetPageHtml());
        $this->assign('data_list', $ret['data']);
D
v1.2.0  
devil_gong 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102
        return $this->fetch();
    }

    /**
     * 订单详情
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-10-08
     * @desc    description
     */
    public function Detail()
    {
D
devil 已提交
103
        $data = $this->OrderFirst();
D
devil 已提交
104
        if(!empty($data))
D
v1.2.0  
devil_gong 已提交
105
        {
D
devil 已提交
106
            // 发起支付 - 支付方式
D
v1.2.0  
devil_gong 已提交
107 108
            $this->assign('buy_payment_list', PaymentService::BuyPaymentList(['is_enable'=>1, 'is_open_user'=>1]));

D
devil_gong 已提交
109 110 111 112
            // 虚拟销售配置
            $site_fictitious = ConfigService::SiteFictitiousConfig();
            $this->assign('site_fictitious', $site_fictitious['data']);

D
devil_gong 已提交
113 114 115
            // 加载百度地图api
            $this->assign('is_load_baidu_map_api', 1);

D
devil 已提交
116
            // 浏览器名称
D
devil 已提交
117
            $this->assign('home_seo_site_title', SeoService::BrowserSeoTitle('订单详情', 1));
D
devil 已提交
118

D
devil 已提交
119 120 121
            // 数据赋值
            $this->assign('data', $data);
            $this->assign('params', $this->data_request);
D
v1.2.0  
devil_gong 已提交
122
            return $this->fetch();
G
gongfuxiang 已提交
123
        }
D
v1.2.0  
devil_gong 已提交
124 125 126 127 128 129 130 131 132 133 134
    }

    /**
     * 评价页面
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-10-08
     * @desc    description
     */
    public function Comments()
D
devil 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
    {
        $data = $this->OrderFirst();
        if(!empty($data))
        {
            $this->assign('referer_url', empty($_SERVER['HTTP_REFERER']) ? MyUrl('index/order/index') : $_SERVER['HTTP_REFERER']);
            $this->assign('data', $data);

            // 编辑器文件存放地址
            $this->assign('editor_path_type', 'order_comments-'.$this->user['id'].'-'.$data['id']);
            return $this->fetch();
        } else {
            $this->assign('msg', '没有相关数据');
            return $this->fetch('public/tips_error');
        }
    }

    /**
     * 获取一条订单信息
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2020-07-25
     * @desc    description
     */
    public function OrderFirst()
D
v1.2.0  
devil_gong 已提交
160
    {
D
devil 已提交
161 162 163 164 165 166 167 168 169 170
        $data = [];
        if(!empty($this->data_request['id']))
        {
            // 条件
            $where = [
                ['is_delete_time', '=', 0],
                ['user_is_delete_time', '=', 0],
                ['id', '=', intval($this->data_request['id'])],
                ['user_id', '=', $this->user['id']],
            ];
D
v1.2.0  
devil_gong 已提交
171

D
devil 已提交
172 173
            // 获取列表
            $data_params = [
D
devil 已提交
174 175 176 177 178
                'm'                 => 0,
                'n'                 => 1,
                'where'             => $where,
                'is_orderaftersale' => 1,
                'user_type'         => 'user',
D
devil 已提交
179 180 181 182
            ];
            $ret = OrderService::OrderList($data_params);
            $data = (empty($ret['data']) || empty($ret['data'][0])) ? [] : $ret['data'][0];
        }
D
devil 已提交
183
        return $data;
D
v1.2.0  
devil_gong 已提交
184 185 186 187 188 189 190 191 192 193 194 195
    }

    /**
     * 评价保存
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-10-09
     * @desc    description
     */
    public function CommentsSave()
    {
D
devil 已提交
196
        if($this->data_post)
D
v1.2.0  
devil_gong 已提交
197
        {
D
devil 已提交
198
            $params = $this->data_post;
D
v1.2.0  
devil_gong 已提交
199
            $params['user'] = $this->user;
G
gongfuxiang 已提交
200
            $params['business_type'] = 'order';
D
devil_gong 已提交
201
            return GoodsCommentsService::Comments($params);
D
v1.2.0  
devil_gong 已提交
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
        } else {
            $this->assign('msg', '非法访问');
            return $this->fetch('public/tips_error');
        }
    }

    /**
     * 订单支付
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-28
     * @desc    description
     */
    public function Pay()
    {
D
devil 已提交
218
        $params = $this->data_request;
D
v1.2.0  
devil_gong 已提交
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
        $params['user'] = $this->user;
        $ret = OrderService::Pay($params);
        if($ret['code'] == 0)
        {
            return redirect($ret['data']['data']);
        } else {
            $this->assign('msg', $ret['msg']);
            return $this->fetch('public/tips_error');
        }
    }

    /**
     * 支付同步返回处理
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-28
     * @desc    description
     */
    public function Respond()
    {
D
devil_gong 已提交
240
        // 参数
D
devil 已提交
241
        $params = $this->data_request;
D
devil_gong 已提交
242 243 244 245

        // 是否自定义状态
        if(isset($params['appoint_status']))
        {
D
devil_gong 已提交
246
            $ret = ($params['appoint_status'] == 0) ? DataReturn('支付成功', 0) : DataReturn('支付失败', -100);
D
devil_gong 已提交
247 248 249 250 251 252

            // 获取支付回调数据
        } else {
            $params['user'] = $this->user;
            $ret = OrderService::Respond($params);
        }
G
gongfuxiang 已提交
253 254 255 256 257 258

        // 自定义链接
        $this->assign('to_url', MyUrl('index/order/index'));
        $this->assign('to_title', '我的订单');

        // 状态
D
devil 已提交
259
        $this->assign('msg', $ret['msg']);
D
v1.2.0  
devil_gong 已提交
260 261
        if($ret['code'] == 0)
        {
G
gongfuxiang 已提交
262
            return $this->fetch('public/tips_success');
D
v1.2.0  
devil_gong 已提交
263
        }
D
devil 已提交
264
        return $this->fetch('public/tips_error');
D
v1.2.0  
devil_gong 已提交
265 266 267 268 269 270 271 272 273 274 275 276
    }

    /**
     * 订单取消
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-30
     * @desc    description
     */
    public function Cancel()
    {
D
devil 已提交
277
        if($this->data_post)
D
v1.2.0  
devil_gong 已提交
278
        {
D
devil 已提交
279
            $params = $this->data_post;
D
v1.2.0  
devil_gong 已提交
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
            $params['user_id'] = $this->user['id'];
            $params['creator'] = $this->user['id'];
            $params['creator_name'] = $this->user['user_name_view'];
            return OrderService::OrderCancel($params);
        } else {
            $this->assign('msg', '非法访问');
            return $this->fetch('public/tips_error');
        }
    }

    /**
     * 订单收货
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-30
     * @desc    description
     */
    public function Collect()
    {
D
devil 已提交
300
        if($this->data_post)
D
v1.2.0  
devil_gong 已提交
301
        {
D
devil 已提交
302
            $params = $this->data_post;
D
v1.2.0  
devil_gong 已提交
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
            $params['user_id'] = $this->user['id'];
            $params['creator'] = $this->user['id'];
            $params['creator_name'] = $this->user['user_name_view'];
            return OrderService::OrderCollect($params);
        } else {
            $this->assign('msg', '非法访问');
            return $this->fetch('public/tips_error');
        }
    }

    /**
     * 订单删除
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-30
     * @desc    description
     */
    public function Delete()
    {
D
devil 已提交
323
        if($this->data_post)
D
v1.2.0  
devil_gong 已提交
324
        {
D
devil 已提交
325
            $params = $this->data_post;
D
v1.2.0  
devil_gong 已提交
326 327 328 329 330 331 332 333 334 335 336
            $params['user_id'] = $this->user['id'];
            $params['creator'] = $this->user['id'];
            $params['creator_name'] = $this->user['user_name_view'];
            $params['user_type'] = 'user';
            return OrderService::OrderDelete($params);
        } else {
            $this->assign('msg', '非法访问');
            return $this->fetch('public/tips_error');
        }
    }

D
devil_gong 已提交
337 338 339 340 341 342 343 344 345 346
    /**
     * 支付状态校验
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2019-01-08
     * @desc    description
     */
    public function PayCheck()
    {
D
devil 已提交
347
        if($this->data_post)
D
devil_gong 已提交
348
        {
D
devil 已提交
349
            $params = $this->data_post;
D
devil_gong 已提交
350 351 352 353 354 355 356
            $params['user'] = $this->user;
            return OrderService::OrderPayCheck($params);
        } else {
            $this->assign('msg', '非法访问');
            return $this->fetch('public/tips_error');
        }
    }
D
v1.2.0  
devil_gong 已提交
357 358
}
?>