Merge branch 'main' of https://gitea.lihaink.cn/mkm/multi-store
This commit is contained in:
commit
6dbd3b328b
@ -78,6 +78,7 @@ class OrderLogic extends BaseLogic
|
||||
$cart_select[$k]['cost'] = bcmul($v['cart_num'], $productBase['cost'], 2) ?? 0;
|
||||
$cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2);//钱
|
||||
$cart_select[$k]['price'] = $find['price'];
|
||||
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2);//钱
|
||||
$cart_select[$k]['product_id'] = $v['goods'];
|
||||
$cart_select[$k]['old_cart_id'] = $v['id'];
|
||||
$cart_select[$k]['cart_num'] = $v['cart_num'];
|
||||
@ -111,7 +112,7 @@ class OrderLogic extends BaseLogic
|
||||
$discountRate = bcdiv($discountRate, '10', 2);
|
||||
$pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2);
|
||||
} else {
|
||||
$userVip = User::where('id', \request()->userId)->value('user_ship');
|
||||
/* $userVip = User::where('id', \request()->userId)->value('user_ship');
|
||||
if ($userVip) {
|
||||
switch ($userVip) {
|
||||
case UserShipEnum::VIP1:
|
||||
@ -134,7 +135,7 @@ class OrderLogic extends BaseLogic
|
||||
}
|
||||
$discountRate = bcdiv($discountRate, '100', 2);
|
||||
$pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
if (!empty(self::$total) && !empty($pay_price)) {
|
||||
bcscale(2);
|
||||
@ -152,7 +153,7 @@ class OrderLogic extends BaseLogic
|
||||
'vip_price' => $vipPrice,
|
||||
'total_num' => count($cart_select),//总数
|
||||
'pay_type' => $params['pay_type'] ?? 0,
|
||||
'reservation_time' => $params['reservation_time'] ?? '',
|
||||
'reservation_time' => $params['reservation_time'] ?? null,
|
||||
'cart_id' => implode(',', $cartId),
|
||||
'store_id' => $params['store_id'] ?? 0,
|
||||
'shipping_type' => $params['shipping_type'] ?? 1//配送方式 1=快递 ,2=门店自提
|
||||
@ -189,7 +190,7 @@ class OrderLogic extends BaseLogic
|
||||
$_order['pay_type'] = $orderInfo['order']['pay_type'];
|
||||
$_order['verify_code'] = $verify_code;
|
||||
$_order['reservation_time'] = null;
|
||||
if (isset($params['reservation_time'])) {
|
||||
if (isset($params['reservation_time']) && $params['reservation_time']) {
|
||||
$_order['reservation_time'] = $params['reservation_time'];
|
||||
$_order['reservation'] = YesNoEnum::YES;
|
||||
}
|
||||
|
@ -31,7 +31,8 @@ class OrderEnum
|
||||
const CASHIER_ORDER_PAY = 9;
|
||||
const CASHIER_CASH_ORDER_PAY = 10;
|
||||
|
||||
const OWN_GET = 3;
|
||||
const ORDER_MARGIN = 11;
|
||||
const ORDER_COMMITION = 12;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -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\system_store\SystemStore;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserRecharge;
|
||||
use app\common\model\user\UserShip;
|
||||
@ -133,15 +134,15 @@ class PayNotifyLogic extends BaseLogic
|
||||
{
|
||||
//更新状态
|
||||
$order = StoreOrder::where('order_id',$orderSn)->findOrEmpty();
|
||||
// if ($order->isEmpty() || $order->status == OrderEnum::REFUND_PAY) {
|
||||
// return true;
|
||||
// }
|
||||
// $order->status = OrderEnum::REFUND_PAY;
|
||||
// $order->refund_status = OrderEnum::REFUND_STATUS_FINISH;
|
||||
// $order->refund_price = bcdiv($extra['amount']['refund'], 100, 2);
|
||||
// $order->refund_reason_time = time();
|
||||
// $order->refund_num += 1;
|
||||
// $order->save();
|
||||
if ($order->isEmpty() || $order->status == OrderEnum::REFUND_PAY) {
|
||||
return true;
|
||||
}
|
||||
$order->status = OrderEnum::REFUND_PAY;
|
||||
$order->refund_status = OrderEnum::REFUND_STATUS_FINISH;
|
||||
$order->refund_price = bcdiv($extra['amount']['refund'], 100, 2);
|
||||
$order->refund_reason_time = time();
|
||||
$order->refund_num += 1;
|
||||
$order->save();
|
||||
|
||||
// self::afterPay($order,$extra['transaction_id']);
|
||||
}
|
||||
@ -244,16 +245,25 @@ class PayNotifyLogic extends BaseLogic
|
||||
$financeLogic->order = $order;
|
||||
$financeLogic->user = ['uid' => $order['uid']];
|
||||
if ($order->pay_type != 9 || $order->pay_type != 10) {
|
||||
//手续费
|
||||
$fees = bcdiv(bcmul($order->pay_price, '0.02', 2), 1, 2);
|
||||
$financeLogic->in($transaction_id,$order->pay_price, OrderEnum::USER_ORDER_PAY); //用户单入账
|
||||
$financeLogic->in($transaction_id,$fees, OrderEnum::OWN_GET); //手续费入账
|
||||
$financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY); //用户单入账
|
||||
//商户应该获得的钱 每个商品的price-ot_price 利润
|
||||
if($order->profit !== "0.00"){ //要测下写入没
|
||||
$financeLogic->out($transaction_id,$order->pay_price, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0);//商户获得的
|
||||
if ($order->profit !== "0.00") {
|
||||
//手续费
|
||||
$fees = bcdiv(bcmul($order['pay_price'], '0.02', 2), 1, 2);
|
||||
$financeLogic->in($transaction_id, $fees, OrderEnum::ORDER_COMMITION, $order['store_id']); //手续费入账
|
||||
|
||||
$financeLogic->out($transaction_id, $order['profit'], OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0);//商户获得的
|
||||
//冻结金额的
|
||||
$frozen = bcsub($order->profit, $fees, 2);
|
||||
//缴纳齐全了就加商户没有就加到平台
|
||||
$money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find();
|
||||
$deposit = bcsub($money_limt['security_deposit'], $money_limt['paid_deposit'], 2);//剩余额度
|
||||
if ($deposit > 0 && $frozen > 0) {
|
||||
$amount = min($deposit, $frozen);
|
||||
$financeLogic->in($transaction_id, $amount, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id']);
|
||||
}
|
||||
|
||||
}
|
||||
// $financeLogic->in($transaction_id,$order['pay_price'], OrderEnum::USER_ORDER_PAY);
|
||||
// $financeLogic->out($transaction_id,$order['pay_price'], OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0);
|
||||
$financeLogic->save();
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\common\controller\Definitions;
|
||||
use app\store\lists\store_order\StoreOrderLists;
|
||||
use app\store\logic\WorkbenchLogic;
|
||||
use hg\apidoc\annotation as ApiDoc;
|
||||
|
||||
@ -49,7 +50,7 @@ class WorkbenchController extends BaseAdminController
|
||||
}
|
||||
|
||||
#[
|
||||
ApiDoc\Title('配送统计(暂时不用)'),
|
||||
ApiDoc\Title('配送统计'),
|
||||
ApiDoc\url('/store/workbench/delivery'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
@ -61,8 +62,29 @@ class WorkbenchController extends BaseAdminController
|
||||
]
|
||||
public function delivery()
|
||||
{
|
||||
$storeId = $this->request->adminInfo['store_id'];
|
||||
$result = WorkbenchLogic::delivery($storeId);
|
||||
$params = $this->request->get();
|
||||
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||
$result = WorkbenchLogic::delivery($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
#[
|
||||
ApiDoc\Title('配送订单统计'),
|
||||
ApiDoc\url('/store/workbench/deliveryOrder'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Author('中国队长'),
|
||||
ApiDoc\Query(name: 'start_time', type: 'string', require: true, desc: '开始时间'),
|
||||
ApiDoc\Query(name: 'end_time', type: 'string', require: true, desc: '结束时间'),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
ApiDoc\Query(ref: [Definitions::class, "page"]),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function deliveryOrder()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||
$result = WorkbenchLogic::deliveryOrder($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
@ -120,40 +142,4 @@ class WorkbenchController extends BaseAdminController
|
||||
return $workbench->get_product_ranking();
|
||||
}
|
||||
|
||||
#[
|
||||
ApiDoc\Title('用户统计-概况'),
|
||||
ApiDoc\url('/store/workbench/get_user_basic'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Author('中国队长'),
|
||||
ApiDoc\Query(name: 'start_time', type: 'string', require: true, desc: '开始时间'),
|
||||
ApiDoc\Query(name: 'end_time', type: 'string', require: true, desc: '结束时间'),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function get_user_basic(\app\admin\controller\WorkbenchController $workbench)
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||
return $workbench->get_user_basic();
|
||||
}
|
||||
|
||||
#[
|
||||
ApiDoc\Title('用户统计-图表'),
|
||||
ApiDoc\url('/store/workbench/get_user_trend'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Author('中国队长'),
|
||||
ApiDoc\Query(name: 'start_time', type: 'string', require: true, desc: '开始时间'),
|
||||
ApiDoc\Query(name: 'end_time', type: 'string', require: true, desc: '结束时间'),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function get_user_trend(\app\admin\controller\WorkbenchController $workbench)
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||
return $workbench->get_user_trend();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -431,4 +431,102 @@ class WorkbenchLogic extends BaseLogic
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function delivery($params)
|
||||
{
|
||||
$data = [];
|
||||
$storeId = $params['store_id'];
|
||||
$startTime = $params['start_time'];
|
||||
$endTime = $params['end_time'];
|
||||
$endTime = date('Y-m-d', strtotime($endTime) + 86400);
|
||||
$dateDiff = (new \DateTime($endTime))->diff(new \DateTime($startTime));
|
||||
$timeRange = [];
|
||||
if ($dateDiff->days == 1) {
|
||||
$group = 'HOUR(pay_time)';
|
||||
$i = 0;
|
||||
while ($i < 24) {
|
||||
$timeRange[] = date('H', strtotime("+$i hours", strtotime($startTime)));
|
||||
$i++;
|
||||
}
|
||||
$field = 'from_unixtime(pay_time,"%H") as pay_time,sum(pay_price) as pay_price,count(id) as order_num';
|
||||
} elseif ($dateDiff->days <= 31) {
|
||||
$group = 'DAY(pay_time)';
|
||||
$i = 0;
|
||||
while ($i < $dateDiff->days) {
|
||||
$timeRange[] = date('m-d', strtotime("+$i days", strtotime($startTime)));
|
||||
$i++;
|
||||
}
|
||||
$field = 'from_unixtime(pay_time,"%m-%d") as pay_time,sum(pay_price) as pay_price,count(id) as order_num';
|
||||
} else {
|
||||
$group = 'MONTH(pay_time)';
|
||||
$i = 0;
|
||||
$month = 0;
|
||||
if ($dateDiff->y > 0) {
|
||||
$month = $dateDiff->y * 12;
|
||||
}
|
||||
if ($dateDiff->m > 0) {
|
||||
$month += $dateDiff->m;
|
||||
}
|
||||
if ($dateDiff->d > 0) {
|
||||
$month += 1;
|
||||
}
|
||||
while ($i < $month) {
|
||||
$timeRange[] = date('Y-m', strtotime("+$i months", strtotime($startTime)));
|
||||
$i++;
|
||||
}
|
||||
$field = 'from_unixtime(pay_time,"%Y-%m") as pay_time,sum(pay_price) as pay_price,count(id) as order_num';
|
||||
}
|
||||
$amountList = StoreOrder::field($field)
|
||||
->where('store_id', $storeId)
|
||||
->where('paid', 1)
|
||||
->where('shipping_type', 1)
|
||||
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||
->group($group)
|
||||
->select()
|
||||
->toArray();
|
||||
$amountList = reset_index($amountList, 'pay_time');
|
||||
$amountListTmp = [];
|
||||
$countListTmp = [];
|
||||
$range = [];
|
||||
foreach ($timeRange as $item) {
|
||||
$range[] = $item;
|
||||
if (!isset($amountList[$item])) {
|
||||
$amountListTmp[$item] = 0;
|
||||
} else {
|
||||
$amountListTmp[$item] = $amountList[$item]['pay_price'];
|
||||
}
|
||||
if (!isset($amountList[$item])) {
|
||||
$countListTmp[$item] = 0;
|
||||
} else {
|
||||
$countListTmp[$item] = $amountList[$item]['order_num'];
|
||||
}
|
||||
}
|
||||
$data['statistics'] = [
|
||||
'range' => $range,
|
||||
'data' => [
|
||||
'order_amount' => array_values($amountListTmp),
|
||||
'order_count' => array_values($countListTmp)
|
||||
]
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function deliveryOrder($params)
|
||||
{
|
||||
$startTime = $params['start_time'];
|
||||
$endTime = $params['end_time'];
|
||||
$endTime = date('Y-m-d', strtotime($endTime) + 86400);
|
||||
$query = StoreOrder::with('user')->where('store_id', $params['store_id'])
|
||||
->where('paid', 1)
|
||||
->where('shipping_type', 1)
|
||||
->whereBetweenTime('create_time', $startTime, $endTime);
|
||||
$data['count'] = $query->count();
|
||||
$data['page_no'] = $params['page_no'];
|
||||
$data['page_size'] = $params['page_size'];
|
||||
$data['extend'] = [];
|
||||
$data['lists'] = $query->order('create_time', 'desc')
|
||||
->page($params['page_no'], $params['page_size'])
|
||||
->select()->toArray();
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user