Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
aimeiyue
service
Commits
d5a103f5
Commit
d5a103f5
authored
Feb 24, 2025
by
jack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分账给平台
parent
5d0b0dd8
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
245 additions
and
28 deletions
+245
-28
app/Admin/Actions/TransferToPlatForm.php
+89
-0
app/Admin/Controllers/OrderDivideRecordController.php
+12
-1
app/Admin/Forms/TransferBillsPlatForm.php
+102
-0
app/Http/Controllers/Api/HfOrderController.php
+11
-9
app/Jobs/AutoOrderDivide.php
+4
-3
app/Models/Adapay.php
+3
-5
app/Models/OrderDivideRecord.php
+24
-10
No files found.
app/Admin/Actions/TransferToPlatForm.php
0 → 100644
View file @
d5a103f5
<?php
namespace
App\Admin\Actions
;
use
Dcat\Admin\Actions\Response
;
use
App\Admin\Forms\TransferBillsPlatForm
;
use
Dcat\Admin\Grid\RowAction
;
use
Dcat\Admin\Traits\HasPermissions
;
use
Illuminate\Contracts\Auth\Authenticatable
;
use
Illuminate\Http\Request
;
use
Dcat\Admin\Widgets\Modal
;
class
TransferToPlatForm
extends
RowAction
{
protected
$id
=
0
;
/**
* 接收参数
*/
public
function
__construct
(
$title
=
''
,
$id
=
0
)
{
$this
->
id
=
$id
;
parent
::
__construct
(
$title
);
$this
->
title
=
$title
;
}
/**
* 按钮文本
*
* @return string|void
*/
public
function
title
()
{
return
'<i class="feather icon-edit"></i> '
.
$this
->
title
;
}
/**
* Handle the action request.
*
* @param Request $request
*
* @return Response
*/
public
function
handle
(
Request
$request
)
{
$id
=
$this
->
getKey
()
??
0
;
return
$this
->
response
()
->
success
(
'成功'
)
->
refresh
();
}
/**
* 渲染模态框.
* @return Modal
*/
public
function
render
()
{
// 这里直接创建一个modal框 model的内容由工具表单提供,这里也需要创建一个工具表单才行
return
Modal
::
make
()
->
lg
()
->
title
(
$this
->
title
)
->
button
(
$this
->
title
())
->
body
(
TransferBillsPlatForm
::
make
()
->
payload
([
'id'
=>
$this
->
id
]));
}
/**
* @return string|array|void
*/
public
function
confirm
()
{
//return ['Confirm?', 'contents'];
}
/**
* @param Model|Authenticatable|HasPermissions|null $user
*
* @return bool
*/
protected
function
authorize
(
$user
)
:
bool
{
return
true
;
}
/**
* @return array
*/
protected
function
parameters
()
{
return
[];
}
}
app/Admin/Controllers/OrderDivideRecordController.php
View file @
d5a103f5
...
...
@@ -9,6 +9,7 @@
use
Dcat\Admin\Grid
;
use
Dcat\Admin\Show
;
use
Dcat\Admin\Http\Controllers\AdminController
;
use
App\Admin\Actions\TransferToPlatForm
;
class
OrderDivideRecordController
extends
AdminController
{
...
...
@@ -35,7 +36,7 @@ protected function grid()
$grid
->
column
(
'is_div'
,
'是否分账'
)
->
display
(
function
(
$val
)
{
return
$val
==
1
?
'是'
:
'否'
;
});
$grid
->
column
(
'um_id'
,
'推荐
信息
'
)
->
display
(
function
(
$val
)
{
$grid
->
column
(
'um_id'
,
'推荐
公司/分享人
'
)
->
display
(
function
(
$val
)
{
$stype
=
$this
->
sh_type
;
$name
=
''
;
if
(
$stype
==
3
)
{
...
...
@@ -49,7 +50,10 @@ protected function grid()
$grid
->
column
(
'created_at'
);
//$grid->column('updated_at')->sortable();
$grid
->
disableCreateButton
();
$grid
->
disableViewButton
();
$grid
->
disableEditButton
();
$grid
->
disableDeleteButton
();
$grid
->
disableRowSelector
();
$grid
->
filter
(
function
(
Grid\Filter
$filter
)
{
...
...
@@ -57,6 +61,13 @@ protected function grid()
$filter
->
panel
();
$filter
->
like
(
'order.order_sn'
,
'订单号'
)
->
width
(
3
);
});
$grid
->
actions
(
function
(
Grid\Displayers\Actions
$actions
)
{
//分账给平台
if
(
$actions
->
row
->
is_div
==
0
&&
in_array
(
$actions
->
row
->
sh_type
,
[
1
,
2
]))
{
$actions
->
append
(
new
TransferToPlatForm
(
'分账给平台'
,
$actions
->
row
->
id
));
}
});
});
}
...
...
app/Admin/Forms/TransferBillsPlatForm.php
0 → 100644
View file @
d5a103f5
<?php
namespace
App\Admin\Forms
;
use
App\Models\OrderDivideRecord
;
use
App\Command\Log
;
use
App\Models\OrderInfo
;
use
App\Models\Adapay
;
use
App\Models\User
;
use
App\Models\PaymentRecord
;
use
Dcat\Admin\Widgets\Form
;
use
Dcat\Admin\Contracts\LazyRenderable
;
use
Dcat\Admin\Traits\LazyWidget
;
use
Exception
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Request
;
class
TransferBillsPlatForm
extends
Form
implements
LazyRenderable
{
use
LazyWidget
;
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public
function
handle
(
array
$input
)
{
$payment_confirm
=
new
\NwVVVS\AdapaySdk\PaymentConfirm
();
//支付确认
$id
=
$this
->
payload
[
'id'
];
DB
::
beginTransaction
();
try
{
$remark
=
trim
(
$input
[
'remark'
]);
$recordObj
=
OrderDivideRecord
::
find
(
$id
);
if
(
!
$recordObj
&&
$recordObj
->
is_div
==
1
)
{
throw
new
Exception
(
'数据不存在或该用户已分账!'
);
}
$divide_price
=
$recordObj
->
divide_price
;
//分账佣金
$um_id
=
$recordObj
->
um_id
;
//推荐分享人
$userObj
=
User
::
find
(
$um_id
);
Log
::
add
(
'推荐人信息'
,
$userObj
->
toArray
());
//交易记录
$order_no
=
OrderInfo
::
where
(
'id'
,
$recordObj
->
order_id
)
->
value
(
'order_sn'
);
$prObj
=
PaymentRecord
::
where
(
'order_sn'
,
$order_no
)
->
first
();
# 支付确认参数设置
$payment_params
=
array
(
"payment_id"
=>
$prObj
->
payment_id
,
"order_no"
=>
'payconfirm_'
.
date
(
"YmdHis"
)
.
rand
(
100000
,
999999
),
"confirm_amt"
=>
$divide_price
,
"description"
=>
""
,
"div_members"
=>
""
//分账参数列表 默认是数组List
);
$userObj
->
total_revenue
-=
$divide_price
;
$userObj
->
save
();
Log
::
add
(
'推荐人账户更新信息'
,
$userObj
->
toArray
());
# 发起支付确认创建
$payment_params
[
'div_members'
]
=
[
'member_id'
=>
0
,
'amount'
=>
sprintf
(
"%.2f"
,
$divide_price
),
'fee_flag'
=>
'Y'
];
$result
=
(
new
Adapay
())
->
createPaymentConfirm
(
$payment_params
);
# 对支付确认创建结果进行处理
if
(
$result
[
'status'
]
==
'succeeded'
)
{
//成功处理
Log
::
add
(
'分账给平台成功'
,
[
'recond_id'
=>
$recordObj
->
id
]);
$recordObj
->
remark
=
$remark
;
$recordObj
->
payconfirm_no
=
$result
[
'order_no'
];
$recordObj
->
save
();
}
DB
::
commit
();
}
catch
(
\Exception
$exception
)
{
DB
::
rollBack
();
return
$this
->
response
()
->
error
(
$exception
->
getMessage
())
->
refresh
();
}
return
$this
->
response
()
->
success
(
'提交成功'
)
->
refresh
();
}
/**
* Build a form here.
*/
public
function
form
()
{
$this
->
text
(
'remark'
,
'备注'
)
->
required
();
}
/**
* The data of the form.
*
* @return array
*/
public
function
default
()
{
// 获取外部传递参数
return
[];
}
}
app/Http/Controllers/Api/HfOrderController.php
View file @
d5a103f5
...
...
@@ -49,27 +49,29 @@ public function paymentConfirm(Request $request)
$payment_params
=
array
(
"payment_id"
=>
$prObj
->
payment_id
,
"order_no"
=>
'payconfirm_'
.
date
(
"YmdHis"
)
.
rand
(
100000
,
999999
),
"confirm_amt"
=>
$prObj
->
money
,
"confirm_amt"
=>
0
,
"description"
=>
""
,
"div_members"
=>
""
//分账参数列表 默认是数组List
);
//分账列表
$divResult
=
OrderDivideRecord
::
divide
(
$orderObj
->
id
);
//返回分账参数列表
$payment_params
[
'div_members'
]
=
$divResult
[
'div_members'
];
$payment_params
[
'confirm_amt'
]
=
$divResult
[
'confirm_amt'
];
Log
::
add
(
'发起支付确认'
,
$payment_params
);
DB
::
beginTransaction
();
try
{
//分账列表
$divResult
=
OrderDivideRecord
::
divide
(
$orderObj
->
id
,
$payment_params
[
'order_no'
]);
//返回分账参数列表
$payment_params
[
'div_members'
]
=
$divResult
[
'div_members'
];
$payment_params
[
'confirm_amt'
]
=
$divResult
[
'confirm_amt'
];
Log
::
add
(
'发起支付确认'
,
$payment_params
);
$orderObj
->
freeze_stat
=
'UNFREEZE'
;
if
(
$orderObj
->
save
())
{
(
new
Adapay
())
->
createPaymentConfirm
(
$payment_params
);
$result
=
(
new
Adapay
())
->
createPaymentConfirm
(
$payment_params
);
}
DB
::
commit
();
}
catch
(
\Exception
$e
)
{
Log
::
add
(
'解冻,支付确认对象失败'
,
$e
);
Log
::
add
(
'解冻,支付确认对象失败'
,
$e
->
getMessage
()
);
DB
::
rollBack
();
return
false
;
return
$this
->
JsonResponse
(
''
,
$e
->
getMessage
(),
201
)
;
}
return
$this
->
JsonResponse
(
$result
);
}
}
...
...
app/Jobs/AutoOrderDivide.php
View file @
d5a103f5
...
...
@@ -46,7 +46,7 @@ public function handle()
$spObj
=
User
::
find
(
$this
->
um_id
);
$member_id
=
$spObj
->
member_id
;
$chunkSize
=
10
;
// 每次处理数量
$orders
=
OrderDivideRecord
::
where
([
'um_id'
=>
$this
->
um_id
,
'is_div'
=>
0
])
->
whereIn
(
'
um_id
'
,
[
1
,
2
])
->
orderBy
(
'id'
)
->
take
(
$chunkSize
);
$orders
=
OrderDivideRecord
::
where
([
'um_id'
=>
$this
->
um_id
,
'is_div'
=>
0
])
->
whereIn
(
'
sh_type
'
,
[
1
,
2
])
->
orderBy
(
'id'
)
->
take
(
$chunkSize
);
while
(
$orders
->
count
()
>
0
)
{
$orders
->
chunk
(
$chunkSize
,
function
(
$batch
)
use
(
$member_id
,
$payment_confirm
)
{
foreach
(
$batch
as
$item
)
{
...
...
@@ -65,14 +65,14 @@ public function handle()
$payment_params
[
'div_members'
]
=
[
'member_id'
=>
$member_id
,
'amount'
=>
$item
->
divide_price
,
'fee_flag'
=>
'
Y
'
'fee_flag'
=>
'
N
'
];
# 发起支付确认创建
$payment_confirm
->
create
(
$payment_params
);
# 对支付确认创建结果进行处理
if
(
$payment_confirm
->
isError
())
{
//失败处理
Log
::
add
(
'支付确认失败'
,
$payment_confirm
->
result
);
Log
::
add
(
'
用户绑卡,
支付确认失败'
,
$payment_confirm
->
result
);
$result
=
$payment_confirm
->
result
;
//throw new Exception($result['error_msg']);
}
else
{
...
...
@@ -81,6 +81,7 @@ public function handle()
$result
=
$payment_confirm
->
result
;
if
(
$result
[
'status'
]
==
'succeeded'
)
{
$item
->
is_div
=
1
;
$item
->
payconfirm_no
=
$result
[
'order_no'
];
$item
->
save
();
Log
::
add
(
'分账成功'
,
[
'order_sn'
=>
$order_sn
,
'member_id'
=>
$member_id
]);
}
...
...
app/Models/Adapay.php
View file @
d5a103f5
...
...
@@ -173,7 +173,7 @@ public function payNotify($params = [])
DB
::
beginTransaction
();
try
{
//分账列表
$divResult
=
OrderDivideRecord
::
divide
(
$orderObj
->
id
);
//返回分账参数列表
$divResult
=
OrderDivideRecord
::
divide
(
$orderObj
->
id
,
$payment_params
[
'order_no'
]
);
//返回分账参数列表
$payment_params
[
'div_members'
]
=
$divResult
[
'div_members'
];
$payment_params
[
'confirm_amt'
]
=
$divResult
[
'confirm_amt'
];
Log
::
add
(
'发起支付确认'
.
$order_no
,
$payment_params
);
...
...
@@ -218,13 +218,11 @@ public function createPaymentConfirm($payment_params)
if
(
$payment
->
isError
())
{
//失败处理
Log
::
add
(
'支付确认返回结果,失败'
,
$payment
->
result
);
echo
"<pre>"
;
print_r
(
$payment
->
result
);
throw
new
Exception
(
$payment
->
result
[
'error_msg'
]);
}
else
{
//成功处理
echo
"<pre>"
;
Log
::
add
(
'支付确认返回结果,成功'
,
$payment
->
result
);
print_r
(
$payment
->
result
)
;
return
$payment
->
result
;
}
}
...
...
app/Models/OrderDivideRecord.php
View file @
d5a103f5
...
...
@@ -20,8 +20,12 @@ class OrderDivideRecord extends Model
];
//收益分配
public
static
function
divide
(
$order_id
)
/**
* 收益分配
* order_id 订单ID
* payconfirm_no 发起确认支付,订单流水号
*/
public
static
function
divide
(
$order_id
,
$payconfirm_no
=
''
)
{
$div_members
=
[];
//汇付 分账对象
$orderObj
=
OrderInfo
::
find
(
$order_id
);
...
...
@@ -115,33 +119,42 @@ public static function divide($order_id)
}
//组合分账参数
if
(
$spuid
&&
$first_commission
>=
1
&&
$first_commission
<
100
&&
$commissionPreData
[
'first_amount'
]
>
0
)
{
self
::
addRecord
(
$sp_ogid
,
$order_id
,
$orderObj
->
goods_amount
,
$commissionPreData
[
'first_amount'
],
$first_proportion
,
$spuid
,
$buyer_id
,
1
,
$isFirstRealName
);
self
::
addRecord
(
$sp_ogid
,
$order_id
,
$orderObj
->
goods_amount
,
$commissionPreData
[
'first_amount'
],
$first_proportion
,
$spuid
,
$buyer_id
,
1
,
$isFirstRealName
,
$payconfirm_no
);
if
(
$isFirstRealName
)
{
array_push
(
$div_members
,
[
'member_id'
=>
$commissionPreData
[
'first_member_id'
],
'amount'
=>
sprintf
(
"%.2f"
,
$commissionPreData
[
'first_amount'
]),
'fee_flag'
=>
'
Y
'
]);
array_push
(
$div_members
,
[
'member_id'
=>
$commissionPreData
[
'first_member_id'
],
'amount'
=>
sprintf
(
"%.2f"
,
$commissionPreData
[
'first_amount'
]),
'fee_flag'
=>
'
N
'
]);
}
}
if
(
$second_spuid
&&
$second_commission
>=
1
&&
$second_commission
<
100
&&
$commissionPreData
[
'second_amount'
]
>
0
)
{
self
::
addRecord
(
$sp_ogid
,
$order_id
,
$orderObj
->
goods_amount
,
$commissionPreData
[
'second_amount'
],
$second_proportion
,
$second_spuid
,
$buyer_id
,
2
,
$isSecondRealName
);
self
::
addRecord
(
$sp_ogid
,
$order_id
,
$orderObj
->
goods_amount
,
$commissionPreData
[
'second_amount'
],
$second_proportion
,
$second_spuid
,
$buyer_id
,
2
,
$isSecondRealName
,
$payconfirm_no
);
if
(
$isSecondRealName
)
{
array_push
(
$div_members
,
[
'member_id'
=>
$commissionPreData
[
'second_member_id'
],
'amount'
=>
sprintf
(
"%.2f"
,
$commissionPreData
[
'second_amount'
]),
'fee_flag'
=>
'
Y
'
]);
array_push
(
$div_members
,
[
'member_id'
=>
$commissionPreData
[
'second_member_id'
],
'amount'
=>
sprintf
(
"%.2f"
,
$commissionPreData
[
'second_amount'
]),
'fee_flag'
=>
'
N
'
]);
}
}
if
(
$merchant_id
&&
$merchant_commission
>=
1
&&
$merchant_commission
<
100
&&
$commissionPreData
[
'merchant_amount'
]
>
0
)
{
self
::
addRecord
(
$sp_ogid
,
$order_id
,
$orderObj
->
goods_amount
,
$commissionPreData
[
'merchant_amount'
],
$merchant_proportion
,
$merchant_id
,
$buyer_id
,
3
,
$isMerchantRealName
);
self
::
addRecord
(
$sp_ogid
,
$order_id
,
$orderObj
->
goods_amount
,
$commissionPreData
[
'merchant_amount'
],
$merchant_proportion
,
$merchant_id
,
$buyer_id
,
3
,
$isMerchantRealName
,
$payconfirm_no
);
if
(
$isMerchantRealName
)
{
array_push
(
$div_members
,
[
'member_id'
=>
$commissionPreData
[
'merchant_member_id'
],
'amount'
=>
sprintf
(
"%.2f"
,
$commissionPreData
[
'merchant_amount'
]),
'fee_flag'
=>
'
Y
'
]);
array_push
(
$div_members
,
[
'member_id'
=>
$commissionPreData
[
'merchant_member_id'
],
'amount'
=>
sprintf
(
"%.2f"
,
$commissionPreData
[
'merchant_amount'
]),
'fee_flag'
=>
'
N
'
]);
}
}
//商户本身
$aimeiyuePrice
=
$total_amount
-
$commissionPreData
[
'first_amount'
]
-
$commissionPreData
[
'second_amount'
]
-
$commissionPreData
[
'merchant_amount'
];
self
::
addRecord
(
$sp_ogid
,
$order_id
,
$orderObj
->
goods_amount
,
$aimeiyuePrice
,
''
,
0
,
$buyer_id
,
0
,
1
);
self
::
addRecord
(
$sp_ogid
,
$order_id
,
$orderObj
->
goods_amount
,
$aimeiyuePrice
,
''
,
0
,
$buyer_id
,
0
,
1
,
$payconfirm_no
);
array_push
(
$div_members
,
[
'member_id'
=>
0
,
'amount'
=>
sprintf
(
"%.2f"
,
$aimeiyuePrice
),
'fee_flag'
=>
'Y'
]);
//确认分佣金额
if
(
!
$isFirstRealName
)
{
$commissionPreData
[
'first_amount'
]
=
0
;
}
if
(
!
$isSecondRealName
)
{
$commissionPreData
[
'second_amount'
]
=
0
;
}
if
(
!
$isMerchantRealName
)
{
$commissionPreData
[
'merchant_amount'
]
=
0
;
}
$confirm_amt
=
$aimeiyuePrice
+
$commissionPreData
[
'first_amount'
]
+
$commissionPreData
[
'second_amount'
]
+
$commissionPreData
[
'merchant_amount'
];
return
[
'div_members'
=>
$div_members
,
'confirm_amt'
=>
sprintf
(
"%.2f"
,
$confirm_amt
)];
}
public
static
function
addRecord
(
$og_id
,
$order_id
,
$goods_amount
,
$divide_price
,
$commission
=
''
,
$um_id
=
0
,
$buyer_id
,
$sh_type
=
0
,
$isExistAccount
)
public
static
function
addRecord
(
$og_id
,
$order_id
,
$goods_amount
,
$divide_price
,
$commission
=
''
,
$um_id
=
0
,
$buyer_id
,
$sh_type
=
0
,
$isExistAccount
,
$payconfirm_no
)
{
$recordObj
=
new
self
();
$recordObj
->
order_id
=
$order_id
;
...
...
@@ -153,6 +166,7 @@ public static function addRecord($og_id, $order_id, $goods_amount, $divide_price
$recordObj
->
um_id
=
$um_id
;
$recordObj
->
sh_type
=
$sh_type
;
$recordObj
->
is_div
=
$isExistAccount
?
1
:
0
;
//是否分账
$recordObj
->
payconfirm_no
=
$isExistAccount
?
$payconfirm_no
:
''
;
$recordObj
->
save
();
Log
::
add
(
'订单分佣记录'
,
$recordObj
->
toArray
());
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment