This commit is contained in:
mkm 2024-06-08 13:34:49 +08:00
commit 2c224fa60a
7 changed files with 155 additions and 7 deletions

View File

@ -7,8 +7,10 @@ use app\api\controller\BaseApiController;
use app\api\lists\order\OrderList;
use app\api\validate\OrderValidate;
use app\common\enum\PayEnum;
use app\common\enum\YesNoEnum;
use app\common\logic\PaymentLogic;
use app\common\logic\PayNotifyLogic;
use app\common\model\dict\DictData;
use app\common\model\store_order\StoreOrder;
use app\common\model\system_store\SystemStoreStaff;
use app\common\model\user\UserAddress;
@ -18,6 +20,7 @@ use hg\apidoc\annotation as ApiDoc;
#[ApiDoc\title('订单')]
class OrderController extends BaseApiController
{
public $notNeedLogin = ['refund_reason'];
/**
* 订单列表
@ -350,6 +353,15 @@ class OrderController extends BaseApiController
return $this->fail('支付失败');
}
#[
ApiDoc\Title('订单详情'),
ApiDoc\url('/api/order/order/detail'),
ApiDoc\Method('GET'),
ApiDoc\Param(name: "order_id", type: "int", require: true, desc: "订单id"),
ApiDoc\NotHeaders(),
ApiDoc\ResponseSuccess("data", type: "array"),
]
public function detail()
{
$order_id = (int)$this->request->get('order_id');
@ -484,6 +496,7 @@ class OrderController extends BaseApiController
ApiDoc\Param(name: "refund_num", type: "int", require: true, desc: "退款数量"),
ApiDoc\Param(name: "id", type: "int", require: true, desc: "订单id"),
ApiDoc\Param(name: "old_cart_id", type: "int", require: true, desc: "购物车id"),
ApiDoc\Param(name: "refund_type", type: "int", require: true, desc: "退款申请类型"),
ApiDoc\NotHeaders(),
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
ApiDoc\ResponseSuccess("data", type: "array"),
@ -496,6 +509,46 @@ class OrderController extends BaseApiController
OrderLogic::dealRefund($uid,$params);
return $this->success('申请成功');
}
#[
ApiDoc\Title('订单退款原因'),
ApiDoc\url('/api/order/order/refund_reason'),
ApiDoc\Method('GET'),
ApiDoc\Param(),
ApiDoc\NotHeaders(),
ApiDoc\ResponseSuccess("data", type: "array"),
]
public function refund_reason()
{
$data = DictData::where('type_value','reason')->where('status',YesNoEnum::YES)
->select()->toArray();
return $this->success('ok',$data);
}
#[
ApiDoc\Title('取消售后'),
ApiDoc\url('/api/order/order/cancel_sale'),
ApiDoc\Method('GET'),
ApiDoc\Param(name: "order_id", type: "int", require: true, desc: "订单id"),
ApiDoc\NotHeaders(),
ApiDoc\ResponseSuccess("data", type: "array"),
]
public function cancel_sale()
{
$order_id = (int)$this->request->get('order_id');
$where = [
'id' => $order_id,
'uid' => $this->userId,
];
$order = OrderLogic::cancelSell($where);
if ($order) {
return $this->success();
} else {
return $this->fail('取消失败');
}
}

View File

@ -7,6 +7,7 @@ use app\admin\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product_unit\StoreProductUnit;
/**
* 零售订单列表
@ -44,7 +45,7 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface
{
$userId=$this->request->userId;
if(!$userId) return [];
return StoreOrder::with(['store'])->where($this->searchWhere)->where('uid',$userId)
$data = StoreOrder::with(['store'])->where($this->searchWhere)->where('uid',$userId)
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
@ -55,6 +56,18 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface
$item['goods_count']=count(explode(',',$item['cart_id']));
})
->toArray();
foreach ($data as &$value){
if($value['refund_reason_time']){
$value['refund_reason_time'] = date('Y-m-d H:i:s',$value['refund_reason_time']);
}
if($value['pay_time']){
$value['pay_time'] = date('Y-m-d H:i:s',$value['pay_time']);
}
foreach ($value['goods_list'] as &$vv){
$vv['unit'] =StoreProductUnit::where('id',$vv['unit'])->value('name')??'';
}
}
return $data;
}

View File

@ -4,6 +4,7 @@ namespace app\api\lists\product;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\dict\DictType;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product\StoreProduct;
use app\common\lists\ListsSearchInterface;
@ -134,7 +135,11 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface
->toArray();
}
$check = DictType::where('type','activities')->find();
foreach ($data as &$value){
if(isset($check) && $check['status'] == 1){
$value['price'] = StoreProduct::where('product_id',$value['product_id'])->value('ot_price');
}
$value['is_default'] = 0;
if($store_id == 2){
$value['is_default'] = 1;

View File

@ -57,11 +57,15 @@ class OrderLogic extends BaseLogic
try {
self::$total = 0;
/** 计算价格 */
$check = DictType::where('type','activities')->find();
foreach ($cart_select as $k => $v) {
$find = StoreBranchProduct::where(['id' => $v['goods']])->field('store_name,image,unit,price')->find();
$find = StoreBranchProduct::where(['id' => $v['goods']])->field('store_name,image,unit,price,product_id')->find();
if (!$find) {
continue;
}
if(isset($check) && $check['status'] == 1){
$find['price'] = StoreProduct::where('product_id',$find['product_id'])->value('ot_price');
}
$cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2);//钱
$cart_select[$k]['price'] = $find['price'];
$cart_select[$k]['product_id'] = $v['goods'];
@ -87,7 +91,6 @@ class OrderLogic extends BaseLogic
//TODO 收单打9.9折 会员按照比例打折 等级按照充值去升级
$pay_price = self::$total;
// $check = StoreOrder::where('uid',\request()->userId)->count();//首单逻辑
$check = DictType::where('type','activities')->find();
$vipPrice = 0;
if(isset($check) && $check['status'] == 1){
// $discountRate = '0.99';//首单逻辑
@ -445,6 +448,20 @@ class OrderLogic extends BaseLogic
return $find;
}
//取消售后
public static function cancelSell($where)
{
return StoreOrder::where($where)->update(
[
'refund_status'=>OrderEnum::CANCEL_SALE,
'status'=>OrderEnum::CANCEL_ORDER,
'refund_cancle_time'=>date('Y-m-d H:i:s',time())
]
);
}
//核销
@ -619,6 +636,7 @@ class OrderLogic extends BaseLogic
$price =bcsub($price, $onePrice);
}
$order->refund_price = $price;
$order->refund_type = $params['refund_type'];
$order->save();
}else{
// 多单的情况 拆主订单为新的2单 修改新的2单的核销码 修改cart_info的核销码 和订单id 退款直接退一单的钱
@ -631,7 +649,7 @@ class OrderLogic extends BaseLogic
->whereNotIn('old_cart_id',$params['old_cart_id'])
->select()->toArray();
if($cart_info){
$leftOrder = self::dealCreateLeftOrder($order,$cart_info);
$leftOrder = self::dealCreateLeftOrder($order,$cart_info,$params);
self::dealChangeCartInfo($leftOrder);
}
$refundOrder = self::dealCreateRefundOrder($order,$params);
@ -666,7 +684,7 @@ class OrderLogic extends BaseLogic
public static function dealCreateLeftOrder($order,$cart_info)
public static function dealCreateLeftOrder($order,$cart_info,$params)
{
//查出不在这个退货中的数据
$order['order_id'] = $order['order_id'].'-2';
@ -694,6 +712,7 @@ class OrderLogic extends BaseLogic
}
$order['cart_id'] = implode(',',$allOldCartIds);
$order['total_num'] = count($cart_info);
$order['refund_type'] = $params['refund_type'];
$order['total_price'] = number_format($totalTotal, 2);
$order['pay_price'] = number_format($totalPrice, 2);
$order['vip_price'] = number_format($totalVipPrice, 2);
@ -740,6 +759,7 @@ class OrderLogic extends BaseLogic
$order['vip_price'] = number_format($totalVipPrices, 2);
$order['refund_price'] = number_format($totalPrice, 2);
$order['verify_code'] = verificationCode();
$order['refund_reason_time'] = time();
$order['create_time'] = time()+1;
$order['update_time'] = null;
$order['delete_time'] = null;

View File

@ -22,6 +22,7 @@ class OrderValidate extends BaseValidate
'refund_num' => 'require|number',
'id' => 'require|number',
'old_cart_id' => 'require|array',
'refund_type' => 'require|number',
];
@ -35,6 +36,7 @@ class OrderValidate extends BaseValidate
'refund_num' => '退款数量',
'id' => '订单id',
'old_cart_id' => '购物车id',
'refund_type' => '退款申请类型',
];
@ -55,7 +57,7 @@ class OrderValidate extends BaseValidate
*/
public function sceneAdd()
{
return $this->only(['refund_message','refund_num','id','old_cart_id']);
return $this->only(['refund_message','refund_num','id','old_cart_id','refund_type']);
}

View File

@ -95,9 +95,19 @@ class OrderEnum
const SUPPLIER = 3;
const SYSTEM = 4;
/**
* 订单状态
* @CANCEL_ORDER 取消售后
*/
const CANCEL_ORDER = 5;
//退款状态
const REFUND_STATUS_NO = 0;
const REFUND_STATUS_YES = 1;
const REFUND_STATUS_FINISH = 2;
const CANCEL_SALE = 3;
/**
* @notes 获取支付类型

View File

@ -14,7 +14,9 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\user\UserAddress;
use app\Request;
use app\common\service\pay\PayService;
use Exception;
use support\Cache;
use think\facade\Db;
class StoreOrderLogic extends BaseLogic
@ -197,4 +199,47 @@ class StoreOrderLogic extends BaseLogic
return StoreOrder::where($where)->sum('pay_price');
}
/**
* 退款
* @param $order_sn
* @param $refund_money
* @param $total
* @return bool
* @throws Exception
*/
public function refund($order_sn,$refund_money,$total)
{
try {
$wechat = new PayService(1);
$time = time();
$order = [
'out_trade_no' => $order_sn,
'out_refund_no' => 'BO'.$time,
'amount' => [
'refund' => $refund_money,
'total' => $total,
'currency' => 'CNY',
],
// '_action' => 'jsapi', // jsapi 退款,默认
// '_action' => 'app', // app 退款
// '_action' => 'combine', // 合单退款
// '_action' => 'h5', // h5 退款
// '_action' => 'miniapp', // 小程序退款
// '_action' => 'native', // native 退款
];
$res = $wechat->wechat->refund($order);
if($res['status'] == 'PROCESSING'){
return true;
}
return false;
} catch (Exception $e) {
\support\Log::info($e->extra['message']?? $e->getMessage());
throw new \Exception($e->extra['message']?? $e->getMessage());
}
}
}