shopxo/app/api/controller/Order.php

276 lines
8.2 KiB
PHP
Raw Normal View History

2018-12-28 18:58:37 +08:00
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
2021-03-16 10:34:52 +08:00
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
2018-12-28 18:58:37 +08:00
// +----------------------------------------------------------------------
2021-03-16 10:34:52 +08:00
// | Licensed ( https://opensource.org/licenses/mit-license.php )
2018-12-28 18:58:37 +08:00
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\api\controller;
2021-07-20 23:45:54 +08:00
use app\service\ApiService;
2021-04-11 15:51:06 +08:00
use app\service\SystemBaseService;
use app\service\PaymentService;
use app\service\OrderService;
2019-10-10 19:13:50 +08:00
use app\service\GoodsCommentsService;
2019-11-25 21:08:55 +08:00
use app\service\ConfigService;
2021-01-27 22:21:04 +08:00
use app\service\ResourcesService;
2018-12-28 18:58:37 +08:00
/**
* 我的订单
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class Order extends Common
{
/**
* [__construct 构造方法]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-03T12:39:08+0800
*/
public function __construct()
{
// 调用父类前置方法
parent::__construct();
// 是否登录
2019-03-02 23:17:30 +08:00
$this->IsLogin();
2018-12-28 18:58:37 +08:00
}
/**
* [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;
2019-01-10 11:32:15 +08:00
$params['user_type'] = 'user';
2018-12-28 18:58:37 +08:00
// 分页
$number = 10;
$page = max(1, isset($this->data_post['page']) ? intval($this->data_post['page']) : 1);
// 条件
$where = OrderService::OrderListWhere($params);
// 获取总数
$total = OrderService::OrderTotal($where);
$page_total = ceil($total/$number);
$start = intval(($page-1)*$number);
// 获取列表
$data_params = array(
2019-10-04 20:50:14 +08:00
'm' => $start,
'n' => $number,
'where' => $where,
'is_orderaftersale' => 1,
2018-12-28 18:58:37 +08:00
);
$data = OrderService::OrderList($data_params);
// 支付方式
$payment_list = PaymentService::BuyPaymentList(['is_enable'=>1, 'is_open_user'=>1]);
// 返回数据
$result = [
2021-01-06 21:26:19 +08:00
'total' => $total,
'page_total' => $page_total,
'data' => $data['data'],
'payment_list' => $payment_list,
2018-12-28 18:58:37 +08:00
];
2021-07-20 23:45:54 +08:00
return ApiService::ApiDataReturn(SystemBaseService::DataReturn($result));
2018-12-28 18:58:37 +08:00
}
/**
* [Detail 获取详情]
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2018-05-21T10:18:27+0800
*/
public function Detail()
{
// 参数
$params = $this->data_post;
$params['user'] = $this->user;
2019-10-09 18:41:38 +08:00
$params['user_type'] = 'user';
2021-07-20 23:45:54 +08:00
if(!empty($params['id']))
2018-12-28 18:58:37 +08:00
{
2021-07-20 23:45:54 +08:00
// 条件
$where = OrderService::OrderListWhere($params);
2019-11-25 21:12:22 +08:00
2021-07-20 23:45:54 +08:00
// 获取列表
$data_params = array(
'm' => 0,
'n' => 1,
'where' => $where,
'is_orderaftersale' => 1,
);
$data = OrderService::OrderList($data_params);
if(!empty($data['data'][0]))
2019-11-25 21:12:22 +08:00
{
2021-07-20 23:45:54 +08:00
// 返回信息
$result = [
'data' => $data['data'][0],
'site_fictitious' => null,
];
// 虚拟销售配置
if($result['data']['order_model'] == 3 && $result['data']['pay_status'] == 1 && in_array($result['data']['status'], [3,4]))
{
$site_fictitious = ConfigService::SiteFictitiousConfig();
$result['site_fictitious'] = $site_fictitious['data'];
}
$ret = SystemBaseService::DataReturn($result);
} else {
$ret = DataReturn('数据不存在或已删除', -100);
2019-11-25 21:12:22 +08:00
}
2021-07-20 23:45:54 +08:00
} else {
$ret = DataReturn('参数有误', -1);
2018-12-28 18:58:37 +08:00
}
2021-07-20 23:45:54 +08:00
return ApiService::ApiDataReturn($ret);
2018-12-28 18:58:37 +08:00
}
2019-10-09 18:41:38 +08:00
/**
* 评价页面
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-10-08
* @desc description
*/
public function Comments()
{
// 参数
$params = $this->data_post;
$params['user'] = $this->user;
$params['user_type'] = 'user';
if(empty($params['id']))
{
2021-07-20 23:45:54 +08:00
$ret = DataReturn('参数有误', -1);
} else {
// 条件
$where = OrderService::OrderListWhere($params);
2019-10-09 18:41:38 +08:00
2021-07-20 23:45:54 +08:00
// 获取列表
$data_params = [
'm' => 0,
'n' => 1,
'where' => $where,
];
$data = OrderService::OrderList($data_params);
if(!empty($data['data'][0]))
2019-10-10 19:13:50 +08:00
{
2021-07-20 23:45:54 +08:00
// 是否已评论
if($data['data'][0]['user_is_comments'] > 0)
{
$ret = ApiService::ApiDataReturn(DataReturn('你已进行过评论', -100));
} else {
// 返回数据
$result = [
'data' => $data['data'][0],
'editor_path_type' => ResourcesService::EditorPathTypeValue('order_comments-'.$this->user['id'].'-'.$data['data'][0]['id']),
];
$ret = SystemBaseService::DataReturn($result);
}
} else {
$ret = DataReturn('没有相关数据', -100);
2019-10-10 19:13:50 +08:00
}
2019-10-09 18:41:38 +08:00
}
2021-07-20 23:45:54 +08:00
return ApiService::ApiDataReturn($ret);
2019-10-09 18:41:38 +08:00
}
/**
* 评价保存
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-10-09
* @desc description
*/
public function CommentsSave()
{
$params = $this->data_post;
$params['user'] = $this->user;
$params['business_type'] = 'order';
2021-07-20 23:45:54 +08:00
return ApiService::ApiDataReturn(GoodsCommentsService::Comments($params));
2019-10-09 18:41:38 +08:00
}
2018-12-28 18:58:37 +08:00
/**
* 订单支付
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-28
* @desc description
*/
public function Pay()
{
$params = $this->data_post;
$params['user'] = $this->user;
2021-07-20 23:45:54 +08:00
return ApiService::ApiDataReturn(OrderService::Pay($params));
2018-12-28 18:58:37 +08:00
}
/**
* [Cancel 订单取消]
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2018-05-21T10:48:48+0800
*/
public function Cancel()
{
$params = $this->data_post;
$params['user_id'] = $this->user['id'];
$params['creator'] = $this->user['id'];
$params['creator_name'] = $this->user['user_name_view'];
2021-07-20 23:45:54 +08:00
return ApiService::ApiDataReturn(OrderService::OrderCancel($params));
2018-12-28 18:58:37 +08:00
}
/**
* [Collect 订单收货]
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2018-05-21T10:48:48+0800
*/
public function Collect()
{
$params = $this->data_post;
$params['user_id'] = $this->user['id'];
$params['creator'] = $this->user['id'];
$params['creator_name'] = $this->user['user_name_view'];
2021-07-20 23:45:54 +08:00
return ApiService::ApiDataReturn(OrderService::OrderCollect($params));
2018-12-28 18:58:37 +08:00
}
/**
* 订单删除
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-30
* @desc description
*/
public function Delete()
{
$params = $this->data_post;
$params['user_id'] = $this->user['id'];
$params['creator'] = $this->user['id'];
$params['creator_name'] = $this->user['user_name_view'];
$params['user_type'] = 'user';
2021-07-20 23:45:54 +08:00
return ApiService::ApiDataReturn(OrderService::OrderDelete($params));
2018-12-28 18:58:37 +08:00
}
}
?>