123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace App\Handlers;
- use App\Models\ProfitSharing as ProfitSharingW;
- use Illuminate\Console\Command;
- class ProfitSharing extends Command
- {
- public function getprofitsharing($bill_date){
- $url='https://api.mch.weixin.qq.com/v3/profitsharing/bills?bill_date='.$bill_date;
- $merchant_id=config('wechat.payment.default.mch_id');
- $serial_no=config('wechat.payment.default.serial_no');
- $handle=new SignHandler();
- $mch_private_key=$handle->getPublicKey();
- $timestamp=time();
- $nonce=$handle->nonce_str();
- $body="";
- $sign=$handle->sign($url,'GET',$timestamp,$nonce,$body,$mch_private_key,$merchant_id,$serial_no);
- $header=[
- 'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $sign,
- 'Accept:application/json',
- 'User-Agent:' . $merchant_id,
- 'Content-Type:application/json',
- 'Wechatpay-Serial:' . $handle->getzhengshu()
- ];
- $result=$handle->curl($url,'',$header,'GET');
- $res=json_decode($result,true);
- $con= $this->down($res['download_url'],'sharing');
- }
- public function down($url){
- $merchant_id=config('wechat.payment.default.mch_id');
- $serial_no=config('wechat.payment.default.serial_no');
- $handle=new SignHandler();
- $mch_private_key=$handle->getPublicKey();
- $timestamp=time();
- $nonce=$handle->nonce_str();
- $body="";
- $sign=$handle->sign($url,'GET',$timestamp,$nonce,$body,$mch_private_key,$merchant_id,$serial_no);
- $header=[
- 'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $sign,
- 'Accept:application/json',
- 'User-Agent:' . $merchant_id,
- 'Content-Type:application/json',
- 'Wechatpay-Serial:' . $handle->getzhengshu()
- ];
- $result=$handle->curl($url,'',$header,'GET');
- $res = $this->deal_profit_sharing($result);
- $sharing_date = $res['sharing'][0]['sharing_date'];
- $sharing_info = ProfitSharingW::where('sharing_date',$sharing_date)->first();
- if(!$sharing_info){
- if(count($res['sharing']) > 1000){
- $arr = array_chunk($res['sharing'],1000);
- foreach($arr as $key=>$val){
- ProfitSharingW::insert($val);
- }
- }else{
- ProfitSharingW::insert($res['sharing']);
- }
- }
- return $res;
- }
- public function deal_profit_sharing($response)
- {
- $result = array();
- $response = str_replace(",", " ", $response);
- $response = explode(PHP_EOL, $response);
- foreach ($response as $key => $val) {
- if (strpos($val, '`') !== false) {
- $data = explode('`', $val);
- array_shift($data);
- if (count($data) == 9) {
- $result['sharing'][] = array(
- 'sharing_time' => $data[0],
- 'sharing_originator' => $data[1],
- 'sharing_user' => $data[2],
- 'wx_order_no' => $data[3],
- 'wx_refund_no' => $data[4],
- 'sharing_detail_no' => $data[5],
- 'mch_refund_no' => $data[6],
- 'order_amount' => $data[7],
- 'sharing_recipient' => explode(' ',$data[8])[0],
- 'amount' => explode(' ',$data[8])[1],
- 'sharing_type' => explode(' ',$data[8])[2],
- 'sharing_status' => explode(' ',$data[8])[3],
- 'sharing_desc' => explode(' ',$data[8])[4],
- 'remark' => explode(' ',$data[8])[5],
- 'sharing_date' => date("Y-m-d", strtotime($data[0])),
- );
- }
- if(count($data) == 5){
- $result['summary'] = array(
- 'sharing_num' => $data[0],
- 'sharing_success_amount' => $data[1],
- 'sharing_fail_turnover' => $data[2],
- 'thaw_funds_amount' => $data[3],
- 'refund_amount' => $data[4],
- );
- }
- }
- }
- return $result;
- }
- }
|