|
|
<?php
|
|
|
|
|
|
namespace app\mall\controller\api;
|
|
|
|
|
|
use app\mall\model\MallOrder;
|
|
|
use app\mall\model\MallOrderProduct;
|
|
|
use app\mall\model\MallOrderRefund;
|
|
|
use think\facade\Db;
|
|
|
|
|
|
class Order extends Base
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
* 获取下单数据(通过产品 地址 优惠券 整合各类价钱)
|
|
|
* @param int $param ['type'] 下单类型 1--商城 2--秒杀商城
|
|
|
* @param int $param ['buy_type'] 购买类型 1--购物车 2--立即购买
|
|
|
* @param int $param ['my_address_id'] 我的地址ID
|
|
|
* @param int $param ['product_id'] buy_type=2时,产品ID
|
|
|
* @param string $param ['product_sku'] buy_type=2时,产品SKU
|
|
|
* @param int $param ['number'] buy_type=2时,购买数量
|
|
|
* @param int $param ['is_choose_default_coupon'] 是否选择默认的最大可选优惠券
|
|
|
* @param int $param ['my_coupon_id'] 我的优惠券ID
|
|
|
* @param int $param ['spike_product_id'] type=2时,秒杀产品ID
|
|
|
* @date 2022-10-13
|
|
|
*/
|
|
|
public function getOrderReady()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
$result = $order_logic->getOrderReady($param['buy_type'], $param['my_address_id'],
|
|
|
$param['product_id'], $param['product_sku'], $param['number'], $param['is_choose_default_coupon'], $param['my_coupon_id'],
|
|
|
$param['type'], $param['spike_product_id']);
|
|
|
|
|
|
if ($result['code']) {
|
|
|
return json($result);
|
|
|
}
|
|
|
|
|
|
return json($result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 提交订单
|
|
|
* @param int $param ['buy_type'] 购买类型 1--购物车 2--立即购买
|
|
|
* @param int $param ['my_address_id'] 我的地址ID
|
|
|
* @param int $param ['product_id'] buy_type=2时,产品ID
|
|
|
* @param string $param ['product_sku'] buy_type=2时,产品SKU
|
|
|
* @param int $param ['number'] buy_type=2时,购买数量
|
|
|
* @param int $param ['my_coupon_id'] 我的优惠券ID
|
|
|
* @param int $param ['type'] 下单类型 1--商城 2--秒杀商城
|
|
|
* @param int $param ['spike_product_id'] type=2时,秒杀产品ID
|
|
|
* @param int $param ['pay_type'] 支付方式 0--不用支付 1--微信支付 2--支付宝支付 3--余额支付
|
|
|
* @param string $param ['remark'] 备注
|
|
|
* @date 2022-10-21
|
|
|
*/
|
|
|
public function insertOrder()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
// 验证参数
|
|
|
$validate = [
|
|
|
'my_address_id' => 'require'
|
|
|
];
|
|
|
$this->validate($param, $validate, [
|
|
|
'my_address_id.require' => '请选择地址'
|
|
|
]);
|
|
|
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
// 提交订单
|
|
|
$result = $order_logic->insertOrder($param['buy_type'], $param['my_address_id'],
|
|
|
$param['product_id'], $param['product_sku'], $param['number'], $param['my_coupon_id'],
|
|
|
$param['type'], $param['spike_product_id'], $param ['pay_type'], $param ['remark']);
|
|
|
|
|
|
return json($result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取我的订单列表
|
|
|
* @param int $param ['last_id'] 列表的最后一条数据ID
|
|
|
* @param int $param ['index'] 订单状态 0--所有 1--待支付 2--待发货 3--待收货 4--待评价
|
|
|
* @param string $param ['keyword'] 订单关键字
|
|
|
* @date 2022-09-28
|
|
|
*/
|
|
|
public function listMyOrder()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
// 获取我的订单列表
|
|
|
$result = $order_logic->listMyOrder($param['last_id'], $param['index'], $param['keyword']);
|
|
|
|
|
|
return json($result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取我的订单详情
|
|
|
* @param int $param ['order_id'] 订单ID
|
|
|
* @date 2022-09-28
|
|
|
*/
|
|
|
public function getMyOrderDetail()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
// 获取我的订单详情
|
|
|
$result = $order_logic->getMyOrderDetail($param['order_id']);
|
|
|
|
|
|
return json($result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取订单数量
|
|
|
* @date 2022-12-28
|
|
|
*/
|
|
|
public function countOrderNumber()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
// 订单再次支付
|
|
|
$result = $order_logic->countOrderNumber();
|
|
|
|
|
|
return json($result);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 订单再支付
|
|
|
* @param int $param ['order_id'] 订单ID
|
|
|
* @param int $param ['pay_type'] 支付方式 0--不用支付 1--微信支付 2--支付宝支付 3--余额支付
|
|
|
* @date 2022-10-31
|
|
|
*/
|
|
|
public function rePayOrder()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
// 订单再次支付
|
|
|
$result = $order_logic->rePayOrder($param['order_id'], $param['pay_type']);
|
|
|
|
|
|
return json($result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单取消
|
|
|
* @param int $param ['order_id'] 订单ID
|
|
|
* @date 2022-10-31
|
|
|
*/
|
|
|
public function cancelOrder()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
Db::startTrans();
|
|
|
$res = $order_logic->cancelOrder($param['order_id'], USER_ID);
|
|
|
if ($res['code'] != 0) {
|
|
|
Db::rollback();
|
|
|
return json($res);
|
|
|
}
|
|
|
Db::commit();
|
|
|
|
|
|
return sendSuccessMessage([], '取消成功');
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//*******************************下面未整合**************
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 订单删除
|
|
|
* @date 2021-03-01
|
|
|
*/
|
|
|
public function orderDel()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
Db::startTrans();
|
|
|
$res = $order_logic->orderDel($param['order_id'], USER_ID);
|
|
|
if ($res['code'] != 0) {
|
|
|
Db::rollback();
|
|
|
return json($res);
|
|
|
}
|
|
|
Db::commit();
|
|
|
|
|
|
return sendSuccessMessage([], '删除成功');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单再购买
|
|
|
* @date 2021-03-01
|
|
|
*/
|
|
|
public function orderReBuy()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
Db::startTrans();
|
|
|
$res = $order_logic->orderReBuy($param['order_id'], USER_ID);
|
|
|
if ($res['code'] != 0) {
|
|
|
Db::rollback();
|
|
|
return json($res);
|
|
|
}
|
|
|
Db::commit();
|
|
|
|
|
|
return sendSuccessMessage([], '加入购物车成功');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单提醒发货
|
|
|
* @date 2021-03-01
|
|
|
*/
|
|
|
public function orderRemind()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
Db::startTrans();
|
|
|
$res = $order_logic->orderRemind($param['order_id'], USER_ID);
|
|
|
if ($res['code'] != 0) {
|
|
|
Db::rollback();
|
|
|
return json($res);
|
|
|
}
|
|
|
Db::commit();
|
|
|
|
|
|
return sendSuccessMessage([], '已提醒店家尽快发货');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单确认收货
|
|
|
* @date 2021-03-01
|
|
|
*/
|
|
|
public function orderFinish()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
Db::startTrans();
|
|
|
$res = $order_logic->orderFinish($param['order_id'], USER_ID);
|
|
|
if ($res['code'] != 0) {
|
|
|
Db::rollback();
|
|
|
return json($res);
|
|
|
}
|
|
|
Db::commit();
|
|
|
|
|
|
return sendSuccessMessage([], '确认收货成功');
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 订单物流
|
|
|
* @date 2022-11-22
|
|
|
*/
|
|
|
public function getLogistics()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
$res = $order_logic->getLogistics($param['order_id']);
|
|
|
|
|
|
return json($res);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取退款产品
|
|
|
* @param int $id 订单产品表ID
|
|
|
* @date 2022-05-26
|
|
|
*/
|
|
|
public function getRefundProductData()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
$order_product_model = new MallOrderProduct();
|
|
|
|
|
|
//获取订单产品表信息
|
|
|
$order_product = $order_product_model->getOneData(['uid' => UID, 'id' => $param['id']],
|
|
|
'id,order_id,product_id,product_cover_img,product_name,product_sku_name,number - refund_total_number - refund_cur_number as actual_number');
|
|
|
|
|
|
return sendSuccessMessage([
|
|
|
'order_product' => $order_product //订单产品数据
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取退款产品列表
|
|
|
* @param int $id 订单产品表ID
|
|
|
* @date 2021-06-01
|
|
|
*/
|
|
|
public function getRefundList()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
$order_product_model = new MallOrderProduct();
|
|
|
$refund_model = new MallOrderRefund();
|
|
|
$refund_list = $refund_model->getAllRefund(['uid' => UID, 'order_product_id' => $param['id']]);
|
|
|
|
|
|
return sendSuccessMessage([
|
|
|
'refund_list' => $refund_list
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取退款产品列表
|
|
|
* @date 2021-06-01
|
|
|
*/
|
|
|
public function getRefundData()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
|
|
|
$refund_model = new MallOrderRefund();
|
|
|
|
|
|
$where = [
|
|
|
['id', '=', $param['id']],
|
|
|
['uid', '=', UID]
|
|
|
];
|
|
|
#TODO *改为具体字段
|
|
|
$data = $refund_model->getOneRefund($where, '*');
|
|
|
|
|
|
return sendSuccessMessage([
|
|
|
'data' => $data
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取产品退款金额
|
|
|
* @date 2021-06-01
|
|
|
*/
|
|
|
public function getOrderRefundMoney()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
|
|
|
$res = $order_logic->getOrderRefundMoney($param['id'], $param['number']);
|
|
|
if ($res['code'] != 0) {
|
|
|
return json($res);
|
|
|
}
|
|
|
|
|
|
return sendSuccessMessage(['refund_money' => $res['data']['refund_money']]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单产品申请退款
|
|
|
* @date 2021-06-01
|
|
|
*/
|
|
|
public function orderRefund()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
//验证参数
|
|
|
$validate = [
|
|
|
'refund_id' => 'require',
|
|
|
];
|
|
|
$this->validate($param, $validate, [
|
|
|
'refund_id.require' => '请选择退款原因'
|
|
|
]);
|
|
|
|
|
|
//处理参数
|
|
|
if (!empty($param['refund_images'])) {
|
|
|
$param['refund_images'] = explode(',', $param['refund_images']);
|
|
|
} else {
|
|
|
$param['refund_images'] = [];
|
|
|
}
|
|
|
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
Db::startTrans();
|
|
|
|
|
|
//申请退款
|
|
|
$res = $order_logic->orderRefund($param['id'], $param['number'], $param['refund_id'], $param['refund_images'], $param['remark']);
|
|
|
if ($res['code'] != 0) {
|
|
|
Db::rollback();
|
|
|
return json($res);
|
|
|
}
|
|
|
|
|
|
Db::commit();
|
|
|
return sendSuccessMessage([], '申请退款成功,等待审核');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单产品申请退款-撤销申请
|
|
|
* @date 2021-06-01
|
|
|
*/
|
|
|
public function orderRefundCancel()
|
|
|
{
|
|
|
$param = input('post.');
|
|
|
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
Db::startTrans();
|
|
|
$res = $order_logic->orderRefundCancel($param['id']);
|
|
|
if ($res['code'] != 0) {
|
|
|
Db::rollback();
|
|
|
return json($res);
|
|
|
}
|
|
|
Db::commit();
|
|
|
return sendSuccessMessage([], '撤销成功');
|
|
|
}
|
|
|
|
|
|
}
|