This commit is contained in:
luofei 2024-01-20 15:02:27 +08:00
commit a991fc0789
7 changed files with 121 additions and 33 deletions

View File

@ -163,6 +163,7 @@ class StoreOrderRepository extends BaseRepository
Db::commit();
} catch (Exception $e) {
Db::rollback();
halt($e);
throw new ValidateException('余额支付失败');
}
@ -315,8 +316,28 @@ class StoreOrderRepository extends BaseRepository
if($order->source==103){
$_payPrice = $order->procure_price;
$finance[] = [
'order_id' => $order->order_id,
'order_sn' => $order->order_sn,
'user_info' => $groupOrder->user->nickname,
'user_id' => $uid,
'financial_type' => 'supply_chain',
'financial_pm' => 0,
'type' => 1,
'number' => $_payPrice,
'mer_id' => $order->mer_id,
'financial_record_sn' => $financeSn . ($i++)
];
//计算手续费
$_order_rate=bcsub($order->pay_price,$_payPrice,2);
//计算镇级供应链云仓实际获得金额
if($_order_rate>0){
$commission_rate = bcdiv(3,100,2);
$_payPrice = bcmul($_order_rate, $commission_rate, 2);
}else{
$_payPrice=0;
}
}else{
$_payPrice = $order->pay_price;
$_order_rate = 0;

View File

@ -495,6 +495,11 @@ class FinancialRecordRepository extends BaseRepository
$expend['count_auto_margin'] . '笔'
],
[
'自动下单市供应链',
$expend['number_supply_chain'] . '元',
$expend['count_supply_chain'] . '笔'
],
[
'佣金',
bcsub($expend['number_brokerage'], $expend['number_refund_brokerage'], 2) . '元',
@ -673,7 +678,10 @@ class FinancialRecordRepository extends BaseRepository
//平台手续费
$financialType = ['order_charge', 'presell_charge'];
[$data['count_order_charge'], $data['number_order_charge']] = $this->dao->getDataByType($type, $where, $date, $financialType);
//转给市级供应链
$financialType = ['supply_chain'];
[$data['count_supply_chain'], $data['number_supply_chain']] = $this->dao->getDataByType($type, $where, $date, $financialType);
//商户押金
$financialType = ['auto_margin'];
[$data['count_auto_margin'], $data['number_auto_margin']] = $this->dao->getDataByType($type, $where, $date, $financialType);
@ -705,10 +713,19 @@ class FinancialRecordRepository extends BaseRepository
$number = bcsub($data['number_brokerage'], $data['number_refund_brokerage'], 2);
//平台手续费 = order_charge + 预售手续费 presell_charge - 平台退给商户的手续费 refund_charge
$number_1 = bcsub($data['number_order_charge'], $data['number_charge'], 2);
if($data['number_supply_chain']>0){
$financialType = ['order_true'];
$where['type']=2;
$where['mer_id']=$where['is_mer'];
unset($where['is_mer']);
[$data['count_order'], $data['number_order']] = $this->dao->getDataByType($type, $where, $date, $financialType);
$number_1=bcadd($number_1, $data['number_supply_chain'], 2);
$number_1=bcsub( $number_1, $data['number_order'], 2);
}
//退回收入 refund_order + 退回佣金
$number_2 = bcadd(bcadd($data['number_refund'], $data['number_coupon'], 2), $data['number_svipcoupon'], 2);
$data['count'] = $data['count_brokerage'] + $data['count_refund'] + $data['count_order_charge'] + $data['count_refund_brokerage'] + $data['count_svipcoupon'] + $data['count_auto_margin']-$data['count_charge'];
$data['count'] =$data['count_supply_chain']+ $data['count_brokerage'] + $data['count_refund'] + $data['count_order_charge'] + $data['count_refund_brokerage'] + $data['count_svipcoupon'] + $data['count_auto_margin']-$data['count_charge'];
$data['number'] = bcadd(bcadd($number3,bcadd($number_2, $number, 2),2), $number_1, 2);
} else { //平台的

View File

@ -6,6 +6,7 @@ use app\common\model\system\merchant\Merchant;
use think\facade\Db;
use crmeb\basic\BaseController;
use think\facade\Log;
use app\common\repositories\system\merchant\FinancialRecordRepository;
/**
* 订单处理
@ -20,32 +21,60 @@ class StoreProcessing extends BaseController
$merchant_two = Db::name('merchant')->where('mer_id', $order['mer_id'])->find();
$order['uid'] = $merchant_two['uid'];
$order['real_name'] =$merchant_two['mer_name'].'-'. $merchant_two['real_name'];
$order['user_phone'] = $merchant_two['mer_phone'];
$order['user_address'] = $merchant_two['mer_address'];
$store_group_order = Db::name('store_group_order')->where('group_order_id', $order['group_order_id'])->find();
$store_group_order_other = Db::name('store_group_order_other')->where('group_order_sn', $order['order_sn'])->find();
if (!$store_group_order_other) {
unset($store_group_order['group_order_id']);
$group_order_id=Db::name('store_group_order_other')->insertGetId($store_group_order);
$group_order_id = Db::name('store_group_order_other')->insertGetId($store_group_order);
}
$select = Db::name('store_order_product')->where('order_id', $order['order_id'])->select();
if ($order['source'] == 103 && $select) {
$arr=$select->toArray();
unset($order['order_id'],$order['orderProduct'],$order['user'],$order['supply_chain_rate'],$order['logistics_code'],$order['logistics_phone']);
$order['group_order_id']=$group_order_id;
$order['mer_id']=$select[0]['product_mer_id'];
$order['source']=104;
$order_id=Db::name('store_order_other')->insertGetId($order);
// $financialRecordRepository = app()->make(FinancialRecordRepository::class);
// $financeSn = $financialRecordRepository->getSn();
$arr = $select->toArray();
$order['group_order_id'] = $group_order_id;
$order['source'] = 104;
//镇级支出
// $finance[] = [
// 'order_id' => $order['order_id'],
// 'order_sn' => $order['order_sn'],
// 'user_info' => $order['real_name'],
// 'user_id' => $order['uid'],
// 'financial_type' => 'supply_chain',
// 'financial_pm' => 0,
// 'type' => 0,
// 'number' => $order['procure_price'],
// 'mer_id' => $order['mer_id'],
// 'financial_record_sn' => $financeSn . '1'
// ];
$order['mer_id'] = $select[0]['product_mer_id'];
$order['uid'] = $merchant_two['uid'];
$order['real_name'] = $merchant_two['mer_name'] . '-' . $merchant_two['real_name'];
$order['user_phone'] = $merchant_two['mer_phone'];
$order['user_address'] = $merchant_two['mer_address'];
//市级获得
// $finance[] = [
// 'order_id' => $order['order_id'],
// 'order_sn' => $order['order_sn'],
// 'user_info' => $order['real_name'],
// 'user_id' => $order['uid'],
// 'financial_type' => 'supply_chain',
// 'financial_pm' => 1,
// 'type' => 0,
// 'number' => $order['procure_price'],
// 'mer_id' => $order['mer_id'],
// 'financial_record_sn' => $financeSn . '2'
// ];
unset($order['order_id'], $order['orderProduct'], $order['user'], $order['supply_chain_rate'], $order['logistics_code'], $order['logistics_phone']);
$order_id = Db::name('store_order_other')->insertGetId($order);
foreach ($arr as $key => $value) {
$arr[$key]['order_id'] = $order_id;
$arr[$key]['source'] = 104;
unset($arr[$key]['order_product_id']);
}
// $financialRecordRepository->insertAll($finance);
Db::name('store_order_product_other')->insertAll($arr);
}
}

View File

@ -56,8 +56,16 @@ class OrderOther extends BaseController
public function lst()
{
[$page, $limit] = $this->getPage();
$where = $this->request->params(['status', 'date', 'order_sn', 'username', 'order_type', 'keywords', 'order_id', 'activity_type', 'group_order_sn', 'store_name','source']);
$where['mer_id'] = $this->request->merId();
$where = $this->request->params(['type','status', 'date', 'order_sn', 'username', 'order_type', 'keywords', 'order_id', 'activity_type', 'group_order_sn', 'store_name','source']);
if($where['type']=='user'){
$uid = Db::name('merchant')->where('mer_id',$this->request->merId())->value('uid');
if(!$uid){
return app('json')->fail('商户不存在');
}
$where['uid'] = $uid;
}else{
$where['mer_id'] = $this->request->merId();
}
$where['paid']=1;
if($where['source']<=0){
$where['source']=105;

View File

@ -21,6 +21,7 @@ use app\common\repositories\store\order\StoreOrderRepository;
use think\facade\Db;
use think\App;
use app\common\dao\store\order\StoreOrderDao;
use app\common\repositories\system\merchant\FinancialRecordRepository;
/**代发订单
* Class StoreOrder
@ -133,22 +134,31 @@ class StoreOrderBehalf extends BaseController
$mer_id = $this->request->merId();
$status = $this->request->param('status');
$id = $this->request->param('id');
$type_id = Db::name('merchant')->where('mer_id', $mer_id)->value('type_id');
$type_code = Db::name('merchant_type')->where('mer_type_id', $type_id)->value('type_code');
$res=0;
if ($status == 1) {
if($type_code=='TypeSupplyChain'){
$res = Db::name('store_order_behalf')->where('product_mer_id', $mer_id)
->where('order_id',$id)->where('status',0)->update(['status'=>1]);
}
}
if ($status == 3) {
if($type_code!='TypeSupplyChain'){
$res = Db::name('store_order_behalf')->where('master_mer_id', $mer_id)
->where('order_id',$id)->where('status',1)->update(['status'=>3]);
}
}
$uid = Db::name('merchant')->where('mer_id', $mer_id)->value('uid');
$res = Db::name('store_order_other')->where('uid', $uid)->where('order_id', $id)->update(['status' => $status]);
$find = Db::name('store_order_other')->where('uid', $uid)->where('order_id', $id)->find();
$find_two = Db::name('store_order')->where('order_sn', $find['order_sn'])->find();
if($res){
if($status==3){
//进入市级供应链待分润状态
$financialRecordRepository = app()->make(FinancialRecordRepository::class);
$financeSn = $financialRecordRepository->getSn();
//市级供应链获得
$finance[] = [
'order_id' =>$find_two['order_id'],
'order_sn' => $find_two['order_id'],
'user_info' => $find['real_name'],
'user_id' => $uid,
'financial_type' => 'supply_chain',
'financial_pm' =>1,
'type' => 0,
'number' => $find['procure_price'],
'mer_id' => $find['mer_id'],
'financial_record_sn' => $financeSn.'1'
];
$financialRecordRepository->insertAll($finance);
}
return app('json')->success('设置成功');
}else{
return app('json')->fail('设置失败');

View File

@ -43,7 +43,7 @@ class paySuccess
$this->recordOrderAddr($order);
}
} catch (\Exception $e) {
Log::error('支付后逻辑报错:' . $e->getMessage() . 'lien:' . $e->getLine());
Log::error('支付后逻辑报错:' . $e->getMessage() . 'lien:' . $e->getLine().'。file:'.$e->getFile());
}
}

View File

@ -335,9 +335,11 @@ class ExcelService
presell 收入 公共 新订单
presell_charge 支出 商户 手续费
presell_true 支出 平台 商户入账
supply_chain 供应链商户入账
*/
$financialType = [
'order' => '订单支付',
'supply_chain' => '供应链',
'presell' => '预售订单(尾款)',
'brokerage_one' => '一级佣金',
'brokerage_two' => '二级佣金',
@ -368,8 +370,9 @@ class ExcelService
'commission_to_cloud_warehouse' => '订单平台佣金',
'commission_to_entry_merchant_refund' => '退回平台佣金',
'commission_to_cloud_warehouse_refund' => '退回平台佣金',
'first_order_commission' => '首单拉新',
];
$sys_pm_1 = ['order', 'presell', 'order_charge', 'order_presell', 'presell_charge', 'refund_brokerage_one', 'refund_brokerage_two', 'commission_to_platform'];
$sys_pm_1 = ['first_order_commission','supply_chain','order', 'presell', 'order_charge', 'order_presell', 'presell_charge', 'refund_brokerage_one', 'refund_brokerage_two', 'commission_to_platform'];
$mer_pm_1 = ['order', 'presell', 'refund_brokerage_one', 'refund_brokerage_two', 'mer_presell',
'order_platform_coupon', 'commission_to_cloud_warehouse', 'commission_to_entry_merchant', 'commission_to_town', 'commission_to_village', 'commission_to_service_team'];
$date_ = $where['date'];