This commit is contained in:
mkm 2024-06-18 18:14:35 +08:00
commit 17706c1f98
6 changed files with 125 additions and 30 deletions

View File

@ -366,12 +366,18 @@ class OrderController extends BaseApiController
public function detail()
{
$order_id = (int)$this->request->get('order_id');
$lat = $this->request->get('lat','');
$lng = $this->request->get('long','');
$where = [
'id' => $order_id,
'uid' => $this->userId,
];
$url = 'https://'.$this->request->host(true);
$order = OrderLogic::detail($where,$url);
$parm = [
'lat'=>$lat,
'long'=>$lng
];
$order = OrderLogic::detail($where,$url,$parm);
if ($order) {
return $this->data($order);
} else {

View File

@ -85,23 +85,32 @@ class OrderLogic extends BaseLogic
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
$cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额
// if ($user && $user['user_ship'] == 4) {
// $deduction_price_count=bcmul(bcsub($find['price'], $find['purchase'], 2),$v['cart_num'],2);
// $cart_select[$k]['deduction_price'] =$deduction_price_count;
// self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
// }
if ($user && $user['user_ship'] == 1) {
//更新 会员为1的时候原价减去会员价
$deduction_price_count=bcmul(bcsub($find['price'], $find['vip_price'], 2),$v['cart_num'],2);
$cart_select[$k]['deduction_price'] =$deduction_price_count;
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
}
if ($user && $user['user_ship'] == 4) {
//更新 为4商户的时候减去商户价格
$deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2);
$cart_select[$k]['deduction_price'] =$deduction_price_count;
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
}
//利润
// $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润
$cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本
$cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单支付金额
$cart_select[$k]['store_price'] = bcmul($v['cart_num'], $find['cost'], 2)??0; //门店零售价
$cart_select[$k]['vip_price'] = bcmul($v['cart_num'], $find['vip_price'], 2)??0; //vip售价
$cart_select[$k]['product_id'] = $find['product_id'];
$cart_select[$k]['old_cart_id'] = $v['id'];
$cart_select[$k]['cart_num'] = $v['cart_num'];
$cart_select[$k]['verify_code'] = $params['verify_code'] ?? '';
//vip1待返回金额
$cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'],$cart_select[$k]['store_price'],2);
$cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'],$cart_select[$k]['vip_price'],2);
// d($cart_select[$k]['pay_price'],$cart_select[$k]['store_price'],$cart_select[$k]['vip_price'] );
$cartInfo = $cart_select[$k];
$cartInfo['name'] = $find['store_name'];
@ -119,13 +128,7 @@ class OrderLogic extends BaseLogic
self::$store_price = bcadd(self::$store_price, $cart_select[$k]['store_price'], 2);//门店零售价格
// self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2);
}
$preferential_amount = 0;//差价(用户为UserShipEnum::DISCOUNT_ARRAY 的时候的优惠差价)
$pay_price =bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额
if($user && in_array($user['user_ship'],UserShipEnum::DISCOUNT_ARRAY)){
$pay_price =bcsub(self::$store_price, self::$activity_price, 2); //减去活动优惠金额
$preferential_amount = bcsub(self::$pay_price,self::$store_price,2);
}
$vipPrice = 0;
//成本价 收益
@ -148,8 +151,6 @@ class OrderLogic extends BaseLogic
'activities' => self::$activity_price>0?1:0,
'deduction_price' => self::$activity_price,
'is_vip' => 0,
'preferential_amount' => $preferential_amount,
];
$order['default_delivery'] = 0;
if ($params['store_id']) {
@ -337,7 +338,7 @@ class OrderLogic extends BaseLogic
}
public static function detail($params,$url=''): array
public static function detail($params,$url='',$param=[]): array
{
$find = StoreOrder::where($params)->findOrEmpty()->toArray();
if ($find) {
@ -359,6 +360,24 @@ class OrderLogic extends BaseLogic
if($find['verify_img']){
$find['verify_img'] = $url.$find['verify_img'];
}
//处理返回最近的店铺
if($param['lat'] && $param['long']){
$storeAll = SystemStore::field('id,name,phone,address,detailed_address,latitude,longitude')->select()->toArray();
$nearestStore = null;
$minDistance = PHP_FLOAT_MAX;
foreach ($storeAll as $value){
$value['distance'] = haversineDistance($value['latitude'],$value['longitude'],$param['lat'] ,$param['long']);
if ($value['distance'] < $minDistance) {
$minDistance = $value['distance'];
$nearestStore = $value;
}
}
if ($nearestStore) {
$find['near_store'] =$nearestStore;
}
}
}
return $find;
}

View File

@ -15,6 +15,8 @@ use app\common\{logic\BaseLogic,
model\user\UserRecharge,
model\user\UserShip,
service\wechat\WeChatMnpService};
use think\facade\Db;
/**
* 会员逻辑层
@ -90,8 +92,8 @@ class UserLogic extends BaseLogic
$data['store_id'] = $check['store_id'];
}
}
$data['return_money'] = StoreFinanceFlow::
where(['user_id'=>$uid,'status'=>0,'financial_pm'=>0])
$data['return_money'] = Db::name('vip_flow')->
where(['user_id'=>$uid,'status'=>0])
->sum('number');
}else{

View File

@ -10,6 +10,7 @@ use app\common\model\finance\PayNotifyLog;
use app\common\model\pay\PayNotify;
use app\common\model\store_finance_flow\StoreFinanceFlow;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User;
use app\common\model\user\UserAddress;
@ -114,7 +115,7 @@ class PayNotifyLogic extends BaseLogic
$capitalFlowDao = new CapitalFlowLogic($user);
$capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $order['id'], $order['pay_price'],'',1,$order['store_id']);
if ($user['user_ship'] == 1) {
VipLogic::dealVipAmount($order, PayEnum::PURCHASE_FUNDS);
self::dealVipAmount($order, PayEnum::PURCHASE_FUNDS);
}
// self::afterPay($order);
@ -303,14 +304,15 @@ class PayNotifyLogic extends BaseLogic
$financeLogic = new StoreFinanceFlowLogic();
$user_sing = new UserSign();
$financeLogic->order = $order;
$financeLogic->user = ['uid' => $order['uid']];
// if ($order->pay_type != 9 || $order->pay_type != 10) {
$financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付
$count_frees = 0;
//商户应该获得的钱 每个商品的price-ot_price 利润
// if (isset($order->profit) && $order->profit > 0) {
if ($order['uid'] > 0) {
// 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去
$vipFrozenAmount = self::dealFrozenPrice($order['id']);
$order['pay_price'] = bcsub($order['pay_price'],$vipFrozenAmount,2);
//用户下单该用户等级为1得时候才处理冻结金额
$user = User::where('id', $order['uid'])->find();
if ($user['user_ship'] == 1) {
self::dealVipAmount($order, $order['pay_type']);
}
$user_number = bcmul($order['pay_price'], '0.10', 2);
$sing = [
'uid' => $order['uid'],
@ -323,6 +325,12 @@ class PayNotifyLogic extends BaseLogic
User::where('id', $order['uid'])->inc('integral', $user_number)->update();
}
$financeLogic->order = $order;
$financeLogic->user = ['uid' => $order['uid']];
// if ($order->pay_type != 9 || $order->pay_type != 10) {
$financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付
$count_frees = 0;
//平台手续费
$fees = bcdiv(bcmul($order['pay_price'], '0.02', 2), 1, 2);
$count_frees = bcadd($count_frees, $fees, 2);
@ -460,4 +468,54 @@ class PayNotifyLogic extends BaseLogic
];
PayNotify::create($data);
}
/**
* 冻结金额
* @param $oid
* @return int|mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function dealFrozenPrice($oid)
{
$detail = StoreOrderCartInfo::where('oid',$oid)->select()->toArray();
$total_vip = 0;
foreach ($detail as $value){
$total_vip +=$value['cart_info']['vip_frozen_price'];
}
return $total_vip;
}
/**
* 处理用户为vip1时得冻结资金
* @param $order
* @param $pay_type
* @param $transaction_id
* @return true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function dealVipAmount($order,$pay_type =1,$transaction_id = 0)
{
$total_vip = self::dealFrozenPrice($order['id']);
$data=[
'order_id' => $order['id'],
'transaction_id' => $transaction_id??0,
'order_sn' =>$order['order_id'],
'user_id' => $order['uid'],
'number' => $total_vip,
'pay_type' => $pay_type??1,
'status' => 0,
'store_id' => $order['store_id'],
'staff_id' => $order['staff_id'],
'create_time'=>time()
];
Db::name('vip_flow')->insert($data);
return true;
}
}

View File

@ -62,8 +62,16 @@ class StoreOrderLogic extends BaseLogic
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
$cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额
if ($user && $user['user_ship'] == 1) {
//更新 会员为1的时候原价减去会员价
$deduction_price_count=bcmul(bcsub($find['price'], $find['vip_price'], 2),$v['cart_num'],2);
$cart_select[$k]['deduction_price'] =$deduction_price_count;
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
}
if ($user && $user['user_ship'] == 4) {
$deduction_price_count=bcmul(bcsub($find['price'], $find['purchase'], 2),$v['cart_num'],2);
//更新 为4商户的时候减去商户价格
$deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2);
$cart_select[$k]['deduction_price'] =$deduction_price_count;
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
}
@ -72,13 +80,14 @@ class StoreOrderLogic extends BaseLogic
$cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本
$cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单支付金额
$cart_select[$k]['store_price'] = bcmul($v['cart_num'], $find['cost'], 2)??0; //门店零售价
$cart_select[$k]['vip_price'] = bcmul($v['cart_num'], $find['vip_price'], 2)??0; //vip售价
$cart_select[$k]['product_id'] = $find['product_id'];
$cart_select[$k]['old_cart_id'] = $v['id'];
$cart_select[$k]['cart_num'] = $v['cart_num'];
$cart_select[$k]['verify_code'] = $params['verify_code'] ?? '';
//vip1待返回金额
$cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'],$cart_select[$k]['store_price'],2);
$cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'],$cart_select[$k]['vip_price'],2);
$cartInfo = $cart_select[$k];
$cartInfo['name'] = $find['store_name'];
$cartInfo['image'] = $find['image'];

View File

@ -82,7 +82,8 @@ class StoreOrderController extends BaseAdminController
$cartId = (array)$this->request->post('cart_id', []);
$params = $this->request->post();
$params['store_id'] = $this->adminInfo['store_id'];
$res = StoreOrderLogic::cartIdByOrderInfo($cartId, null, null, $params);
$user=User::where('id',$params['uid'])->find();
$res = StoreOrderLogic::cartIdByOrderInfo($cartId, null, $user, $params);
if ($res == false) {
$msg = StoreOrderLogic::getError();
if ($msg == '购物车为空') {