|
|
|
@ -20,6 +20,7 @@ use app\common\model\PaymentTrade; |
|
|
|
|
use app\common\model\wxapp\Setting; |
|
|
|
|
use app\common\enum\Client as ClientEnum; |
|
|
|
|
use app\common\library\payment\Facade as PaymentFacade; |
|
|
|
|
use app\common\library\Log; |
|
|
|
|
|
|
|
|
|
// /www/server/php/74/bin/php /server/wwwroot/yanzong/think test |
|
|
|
|
class ProfitSharing extends Command |
|
|
|
@ -49,27 +50,29 @@ class ProfitSharing extends Command |
|
|
|
|
} |
|
|
|
|
var_dump($stores); |
|
|
|
|
foreach ($stores as $store) { |
|
|
|
|
try { |
|
|
|
|
$where = []; |
|
|
|
|
//查询已完成的订单,并且未分账的订单 |
|
|
|
|
$where[] = ['order_status','=', 30]; |
|
|
|
|
$where[] = ['pay_status','=', 20]; |
|
|
|
|
$where[] = ['is_refund','=', 10]; |
|
|
|
|
$where[] = ['is_delete','=', 0]; |
|
|
|
|
$where[] = ['profitsharing_status','=', 0]; |
|
|
|
|
$where[] = ['store_id','=', $store['store_id']]; |
|
|
|
|
$where[] = ['merchant_id','>', 0]; |
|
|
|
|
$orders = Order::where($where) |
|
|
|
|
->field('order_id,total_price,order_price,pay_price,pay_method,cost_price,merchant_id,store_id,order_status,pay_status,delivery_status,receipt_status,delivery_type,delivery_time,create_time,trade_id') |
|
|
|
|
->select(); |
|
|
|
|
// var_dump($orders->toArray()); |
|
|
|
|
// exit(); |
|
|
|
|
if ($orders->isEmpty()) { |
|
|
|
|
echo $store['store_id']."没有已完成的订单要分账".PHP_EOL; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
//微信支付订单抽佣给平台、余额支付抽佣给平台,把订单金额记录到商户账上 |
|
|
|
|
foreach ($orders as $order) { |
|
|
|
|
|
|
|
|
|
$where = []; |
|
|
|
|
//查询已完成的订单,并且未分账的订单 |
|
|
|
|
$where[] = ['order_status','=', 30]; |
|
|
|
|
$where[] = ['pay_status','=', 20]; |
|
|
|
|
$where[] = ['is_refund','=', 10]; |
|
|
|
|
$where[] = ['is_delete','=', 0]; |
|
|
|
|
$where[] = ['profitsharing_status','=', 0]; |
|
|
|
|
$where[] = ['store_id','=', $store['store_id']]; |
|
|
|
|
$where[] = ['merchant_id','>', 0]; |
|
|
|
|
$where[] = ['commission_ratio','>', 0]; |
|
|
|
|
$orders = Order::where($where) |
|
|
|
|
->field('order_id,total_price,order_price,pay_price,pay_method,cost_price,merchant_id,store_id,order_status,pay_status,delivery_status,receipt_status,delivery_type,delivery_time,create_time,trade_id') |
|
|
|
|
->select(); |
|
|
|
|
// var_dump($orders->toArray()); |
|
|
|
|
// exit(); |
|
|
|
|
if ($orders->isEmpty()) { |
|
|
|
|
echo $store['store_id']."没有已完成的订单要分账".PHP_EOL; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
//微信支付订单抽佣给平台、余额支付抽佣给平台,把订单金额记录到商户账上 |
|
|
|
|
foreach ($orders as $order) { |
|
|
|
|
try { |
|
|
|
|
//余额支付 |
|
|
|
|
if ($order->pay_method == PaymentMethodEnum::BALANCE) { |
|
|
|
|
//增加商户支付详情 |
|
|
|
@ -117,14 +120,11 @@ class ProfitSharing extends Command |
|
|
|
|
echo $store['store_id'].$payment->template_id."微信支付模版没有配置11".PHP_EOL; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
//支付信息初始化 |
|
|
|
|
$PaymentModel = new Payment; |
|
|
|
|
$templateInfo = $PaymentModel->getPaymentInfo(PaymentMethodEnum::WECHAT, ClientEnum::MP_WEIXIN, $order->store_id, $order->merchant_id); |
|
|
|
|
// var_dump($templateInfo); |
|
|
|
|
// exit(); |
|
|
|
|
$options = $templateInfo['template']['config'][PaymentMethodEnum::WECHAT]; |
|
|
|
|
|
|
|
|
|
$payment = PaymentFacade::store(PaymentMethodEnum::WECHAT)->setOptions($options, ClientEnum::MP_WEIXIN); |
|
|
|
|
var_dump($payment); |
|
|
|
|
|
|
|
|
|
//平台微信支付配置信息 |
|
|
|
|
$platform_payment = Payment::where('store_id', $order->store_id)->where('merchant_id', 0)->where('method',PaymentMethodEnum::WECHAT)->where('is_enable', 1)->find(); |
|
|
|
@ -160,14 +160,14 @@ class ProfitSharing extends Command |
|
|
|
|
$precent = $model['commission_ratio'] / 1000; |
|
|
|
|
$precentPrice = round($precent * $order->pay_price * 100, 2); |
|
|
|
|
var_dump($precentPrice); |
|
|
|
|
$precentPrice = 100; |
|
|
|
|
//$precentPrice = 100; |
|
|
|
|
if ($precentPrice <= 0) { |
|
|
|
|
echo $order->order_id.":当前订单抽佣金额小于等于0".$precentPrice.PHP_EOL; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
var_dump($payment); |
|
|
|
|
$ret = $payment->addReceiver("MERCHANT_ID", $platform_wechat_config['mchId'], "乔善英", "HEADQUARTER"); |
|
|
|
|
exit(); |
|
|
|
|
//var_dump($payment); |
|
|
|
|
$ret = $payment->addReceiver("MERCHANT_ID", $platform_wechat_config['mchId'], "武汉市汉阳区静好电子商务商行(个体工商户)", "HEADQUARTER"); |
|
|
|
|
//exit(); |
|
|
|
|
$transaction_id = $payment_trade->trade_no; |
|
|
|
|
$out_trade_no = "PS".date("YmdHis").mt_rand(1000,9999); |
|
|
|
|
$receivers = [ |
|
|
|
@ -175,40 +175,27 @@ class ProfitSharing extends Command |
|
|
|
|
"type" => "MERCHANT_ID", |
|
|
|
|
"account" => $platform_wechat_config['mchId'], |
|
|
|
|
"amount" => $precentPrice, |
|
|
|
|
"description" => "分到商户" |
|
|
|
|
"description" => "分到平台" |
|
|
|
|
] |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//var_dump($receiver); |
|
|
|
|
//var_dump($ret); |
|
|
|
|
var_dump($receivers); |
|
|
|
|
//$sharing = $payment->profit_sharing->share($transaction_id, $out_trade_no, $receivers); |
|
|
|
|
$sharing = $payment->profitsharing($transaction_id, $out_trade_no, $receivers); |
|
|
|
|
var_dump($sharing); |
|
|
|
|
exit; |
|
|
|
|
if ($sharing['return_code'] != "SUCCESS") { |
|
|
|
|
echo $order->order_id.":".$sharing['return_msg'].PHP_EOL; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if ($sharing['result_code'] != "SUCCESS") { |
|
|
|
|
echo $order->order_id.":".$sharing['err_code_des'].PHP_EOL; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
var_dump($sharing); |
|
|
|
|
var_dump($sharing->return_code); |
|
|
|
|
var_dump($sharing->result_code); |
|
|
|
|
exit(); |
|
|
|
|
|
|
|
|
|
//更新 |
|
|
|
|
$ret = Order::where('order_id',$order->order_id)->update(['profitsharing_status' => 1, 'profitsharing_time' => time(),'out_order_no' => $out_trade_no]); |
|
|
|
|
echo "微信支付分账中".PHP_EOL; |
|
|
|
|
var_dump($ret); |
|
|
|
|
} |
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
Log::append('微信支付分账失败', [$order->order_id.":".$e->getMessage()]); |
|
|
|
|
echo $order->order_id.":".$e->getMessage(); |
|
|
|
|
$ret = Order::where('order_id',$order->order_id)->update(['profitsharing_status' => 3, 'profitsharing_time' => time(),'out_order_no' => $out_trade_no]); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|