发票
Showing
12 changed files
with
268 additions
and
99 deletions
| ... | @@ -6,7 +6,8 @@ use App\Helper\CacheKeyTools; | ... | @@ -6,7 +6,8 @@ use App\Helper\CacheKeyTools; |
| 6 | use App\Helper\RedisClient; | 6 | use App\Helper\RedisClient; |
| 7 | use App\Models\Legal\Bills; | 7 | use App\Models\Legal\Bills; |
| 8 | use App\Models\Legal\Company; | 8 | use App\Models\Legal\Company; |
| 9 | use App\Models\Legal\StakeholderIncomeByPayer; | 9 | use App\Models\Legal\StakeholderIncomeSyncApp; |
| 10 | use App\Models\Legal\StakeholderIncomeSyncAppDetails; | ||
| 10 | use App\Services\ApiService; | 11 | use App\Services\ApiService; |
| 11 | use Illuminate\Console\Command; | 12 | use Illuminate\Console\Command; |
| 12 | use Illuminate\Support\Facades\Log; | 13 | use Illuminate\Support\Facades\Log; |
| ... | @@ -18,6 +19,8 @@ use Illuminate\Support\Facades\Log; | ... | @@ -18,6 +19,8 @@ use Illuminate\Support\Facades\Log; |
| 18 | */ | 19 | */ |
| 19 | class StakeholderIncomeSyncCommand extends Command | 20 | class StakeholderIncomeSyncCommand extends Command |
| 20 | { | 21 | { |
| 22 | use \App\Traits\Bills; | ||
| 23 | |||
| 21 | /** | 24 | /** |
| 22 | * The name and signature of the console command. | 25 | * The name and signature of the console command. |
| 23 | * | 26 | * |
| ... | @@ -36,8 +39,8 @@ class StakeholderIncomeSyncCommand extends Command | ... | @@ -36,8 +39,8 @@ class StakeholderIncomeSyncCommand extends Command |
| 36 | const COUNT = 1; | 39 | const COUNT = 1; |
| 37 | const BLOCK_TIME = 1000; | 40 | const BLOCK_TIME = 1000; |
| 38 | 41 | ||
| 39 | const TYPE_BILLS = 1001601; //账单分成 | 42 | const TYPE_BILLS = "1001601"; //账单分成 |
| 40 | const TYPE_ROYALTY = 1001602; //合作伙伴打款 type = 1 版税分成 | 43 | const TYPE_ROYALTY = "1001602"; //合作伙伴打款 type = 1 版税分成 |
| 41 | 44 | ||
| 42 | /** | 45 | /** |
| 43 | * Create a new command instance. | 46 | * Create a new command instance. |
| ... | @@ -67,59 +70,103 @@ class StakeholderIncomeSyncCommand extends Command | ... | @@ -67,59 +70,103 @@ class StakeholderIncomeSyncCommand extends Command |
| 67 | if($msg = $redis->xread([$key=>$id], self::COUNT, self::BLOCK_TIME)) { | 70 | if($msg = $redis->xread([$key=>$id], self::COUNT, self::BLOCK_TIME)) { |
| 68 | 71 | ||
| 69 | $id = key($msg[$key]); | 72 | $id = key($msg[$key]); |
| 70 | $income_item = $msg[$key][$id]; | 73 | $serial_no = $msg[$key][$id]['serial_no']; |
| 71 | |||
| 72 | Log::channel('api')->warning(__METHOD__."streamid:{$id}-即将处理任务", ['income_item'=>$income_item]); | ||
| 73 | |||
| 74 | $company = Company::query()->find($income_item['company_id']); | ||
| 75 | $bills = Bills::query()->find($income_item['related_id']); | ||
| 76 | $channel = 'TME'; | ||
| 77 | |||
| 78 | $http_data = [ | ||
| 79 | 'busiId'=>$income_item['serial_no'], | ||
| 80 | 'cardNo'=>$income_item['identifier'], | ||
| 81 | 'faxMoney'=>$income_item['fax_money'], | ||
| 82 | 'money'=>$income_item['money'], | ||
| 83 | 'totalMoney'=>$income_item['total_money'], | ||
| 84 | 'paymentCompany'=>$company->receipt_name, | ||
| 85 | 'type'=>self::TYPE_BILLS, | ||
| 86 | 'title'=>"{$bills->bill_section_start}-{$bills->bill_section_end}账单/{$channel}", | ||
| 87 | ]; | ||
| 88 | 74 | ||
| 89 | if ($res = StakeholderIncomeByPayer::query()->where(['serial_no'=>$income_item['serial_no']])->first()) { | 75 | Log::channel('api')->warning(__METHOD__."streamid:{$id}-即将处理任务", ['item'=>$msg[$key][$id]]); |
| 90 | 76 | ||
| 91 | if ($res['sync_status'] == 0) { | 77 | //获取记录 |
| 92 | 78 | if ($http_data = $this->resolveSyncData($serial_no)) { | |
| 93 | //直接未同步的数据才请求api | 79 | //http |
| 94 | $http_res = ApiService::walletAddIncome($http_data); | 80 | $http_res = ApiService::walletAddIncome($http_data); |
| 95 | 81 | ||
| 96 | if (empty($http_res)) { | 82 | if (empty($http_res)) { |
| 97 | //重试 401/403/403 | 83 | //重试 401/403/403 |
| 98 | Log::channel('api')->warning(__METHOD__."streamid:{$id}-api请求失败", ['income_item'=>$income_item, 'http_data'=>$http_data]); | 84 | Log::channel('api')->warning(__METHOD__."streamid:{$id}-api请求失败", ['income_item'=>$income_item, 'http_data'=>$http_data]); |
| 99 | } else { | 85 | } else { |
| 86 | //成功 | ||
| 100 | 87 | ||
| 101 | $update = [ | 88 | } |
| 102 | 'http_log'=>json_encode($http_res, JSON_UNESCAPED_UNICODE), | ||
| 103 | 'busi_id'=>$http_res['data']['busiId'], | ||
| 104 | ]; | ||
| 105 | 89 | ||
| 106 | if ($http_res['code'] == 0) { | ||
| 107 | $update['sync_status'] = 1; | ||
| 108 | } else { | 90 | } else { |
| 109 | $update['sync_status'] = 2; | 91 | Log::channel('api')->info(__METHOD__, ['msg'=>'找不到需要同步的对应的收益记录', 'serial_no'=>$serial_no]); |
| 92 | $this->consumeTask($redis, $key, $id); | ||
| 110 | } | 93 | } |
| 111 | 94 | ||
| 112 | //记录请求api返回体并修改状态 | 95 | } |
| 113 | if (StakeholderIncomeByPayer::query()->where(['serial_no'=>$income_item['serial_no']])->update($update)) { | ||
| 114 | $redis->xdel($key, [$id]); | ||
| 115 | } | 96 | } |
| 116 | } | 97 | } |
| 117 | 98 | ||
| 118 | } else { | 99 | /** |
| 119 | $redis->xdel($key, [$id]); | 100 | * 消费任务 |
| 101 | * @param $redis | ||
| 102 | * @param $key | ||
| 103 | * @param $id | ||
| 104 | * @return mixed | ||
| 105 | */ | ||
| 106 | private function consumeTask($redis, $key, $id) | ||
| 107 | { | ||
| 108 | return $redis->xdel($key, [$id]); | ||
| 109 | } | ||
| 110 | |||
| 111 | /** | ||
| 112 | * 生成http请求数据 | ||
| 113 | * @param $serial_no | ||
| 114 | * @return array | ||
| 115 | */ | ||
| 116 | private function resolveSyncData($serial_no) | ||
| 117 | { | ||
| 118 | if ($income = StakeholderIncomeSyncApp::query()->where(['serial_no'=>$serial_no, 'sync_status'=>0])->first()) { | ||
| 119 | $income_detail = StakeholderIncomeSyncAppDetails::query()->where(['track_serial_no'=>$serial_no])->orderBy('month')->get(); | ||
| 120 | |||
| 121 | if ($income_detail->isNotEmpty()) { | ||
| 122 | return $this->formatHttpBody($income, $income_detail); | ||
| 120 | } | 123 | } |
| 121 | } | 124 | } |
| 125 | |||
| 126 | return []; | ||
| 122 | } | 127 | } |
| 128 | |||
| 129 | /** | ||
| 130 | * @param $income | ||
| 131 | * @param $income_detail | ||
| 132 | * @return array | ||
| 133 | */ | ||
| 134 | private function formatHttpBody($income, $income_detail) | ||
| 135 | { | ||
| 136 | |||
| 137 | $company = Company::query()->find($income->company_id); | ||
| 138 | $bills = Bills::query()->find($income->related_id); | ||
| 139 | |||
| 140 | $body = [ | ||
| 141 | 'busiId' => $income->serial_no, | ||
| 142 | 'cardNo' => $income->identifier, | ||
| 143 | 'cost' => $income->cost_amount, | ||
| 144 | 'deductAmount' => $income->deduct_prepaid, | ||
| 145 | 'faxMoney' => $income->fax_money, | ||
| 146 | 'money' => $income->money, | ||
| 147 | 'totalMoney' => $income->total_money, | ||
| 148 | 'type' => self::TYPE_BILLS, | ||
| 149 | 'title' => $this->billsTitle($bills),//账单标题 | ||
| 150 | 'paymentCompany'=> $company->receipt_name, //付款公司营业执照全称 | ||
| 151 | 'addLevelTwoIncomeRequests' => [], | ||
| 152 | ]; | ||
| 153 | |||
| 154 | foreach ($income_detail as $item) { | ||
| 155 | $body['addLevelTwoIncomeRequests'][] = [ | ||
| 156 | 'actualTime' => (string)$item->created_at, | ||
| 157 | 'busiId' => $item->serial_no, | ||
| 158 | 'faxMoney' => $item->fax_money, | ||
| 159 | 'money' => $item->money, | ||
| 160 | 'totalMoney' => $item->total_money, | ||
| 161 | 'paymentCompany' => $company->receipt_name, //付款公司营业执照全称 | ||
| 162 | 'songNum' => $item->song_num, | ||
| 163 | 'title' => $this->billsSubTitle($item->month), | ||
| 164 | 'type' => self::TYPE_BILLS, | ||
| 165 | ]; | ||
| 123 | } | 166 | } |
| 167 | |||
| 168 | return $body; | ||
| 124 | } | 169 | } |
| 170 | |||
| 171 | |||
| 125 | } | 172 | } | ... | ... |
| ... | @@ -17,4 +17,13 @@ class CacheKeyTools | ... | @@ -17,4 +17,13 @@ class CacheKeyTools |
| 17 | { | 17 | { |
| 18 | return config('cache.key')['bills_sync']; | 18 | return config('cache.key')['bills_sync']; |
| 19 | } | 19 | } |
| 20 | |||
| 21 | /** | ||
| 22 | * @return mixed | ||
| 23 | */ | ||
| 24 | public static function channelname() | ||
| 25 | { | ||
| 26 | return config('cache.key')['channelname']; | ||
| 27 | } | ||
| 28 | |||
| 20 | } | 29 | } | ... | ... |
app/Models/Legal/Channel.php
0 → 100644
| 1 | <?php | ||
| 2 | namespace App\Models\Legal; | ||
| 3 | |||
| 4 | use App\Helper\CacheKeyTools; | ||
| 5 | use App\Models\BaseModel; | ||
| 6 | use Illuminate\Database\Eloquent\SoftDeletes; | ||
| 7 | use Illuminate\Support\Facades\Cache; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * Class Channel | ||
| 11 | * @package App\Models | ||
| 12 | */ | ||
| 13 | class Channel extends BaseModel | ||
| 14 | { | ||
| 15 | use SoftDeletes; | ||
| 16 | |||
| 17 | const TIME = 86400; | ||
| 18 | |||
| 19 | |||
| 20 | /** | ||
| 21 | * @return mixed | ||
| 22 | */ | ||
| 23 | public static function getChannelName() | ||
| 24 | { | ||
| 25 | if (!$res = Cache::get(CacheKeyTools::channelname())) { | ||
| 26 | $res = Channel::query()->where(['pid'=>0])->pluck('name', 'id')->toArray(); | ||
| 27 | Cache::put(CacheKeyTools::channelname(), $res, self::TIME); | ||
| 28 | } | ||
| 29 | return $res; | ||
| 30 | } | ||
| 31 | |||
| 32 | |||
| 33 | |||
| 34 | } |
| 1 | <?php | ||
| 2 | |||
| 3 | namespace App\Models\Legal; | ||
| 4 | |||
| 5 | use App\Models\BaseModel; | ||
| 6 | use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * 进账收益流水 | ||
| 10 | * Class StakeholderIncomeByPayer | ||
| 11 | * @package App\Models\Legal | ||
| 12 | */ | ||
| 13 | class StakeholderIncomeByPayer extends BaseModel | ||
| 14 | { | ||
| 15 | use HasFactory; | ||
| 16 | |||
| 17 | const TYPE_INCOME = 1; | ||
| 18 | const TYPE_PAY = 2; | ||
| 19 | |||
| 20 | |||
| 21 | public $table = 'stakeholder_income_by_payer'; | ||
| 22 | |||
| 23 | /** | ||
| 24 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||
| 25 | */ | ||
| 26 | public function company() | ||
| 27 | { | ||
| 28 | return $this->belongsTo(Company::class, 'company_id', 'company_id'); | ||
| 29 | } | ||
| 30 | } |
| 1 | <?php | ||
| 2 | |||
| 3 | namespace App\Models\Legal; | ||
| 4 | |||
| 5 | use App\Models\BaseModel; | ||
| 6 | use Illuminate\Support\Facades\DB; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * Class stakeholderIncomeSyncApp | ||
| 10 | * @package App\Models | ||
| 11 | */ | ||
| 12 | class StakeholderIncomeSyncApp extends BaseModel | ||
| 13 | { | ||
| 14 | const TYPE_INCOME = 1; //收入 | ||
| 15 | const TYPE_PAY = 2; //支出 | ||
| 16 | |||
| 17 | /** | ||
| 18 | * @var string | ||
| 19 | */ | ||
| 20 | protected $table = 'stakeholder_income_sync_app'; | ||
| 21 | |||
| 22 | /** | ||
| 23 | * @var array | ||
| 24 | */ | ||
| 25 | protected $guarded = []; | ||
| 26 | |||
| 27 | /** | ||
| 28 | * 付款方 | ||
| 29 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||
| 30 | */ | ||
| 31 | public function subject() | ||
| 32 | { | ||
| 33 | return $this->belongsTo(Subject::class, 'subject_no', 'no')->where('attr', 'like', '%1%'); | ||
| 34 | } | ||
| 35 | |||
| 36 | /** | ||
| 37 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||
| 38 | */ | ||
| 39 | public function stakeholder() | ||
| 40 | { | ||
| 41 | return $this->belongsTo(Stakeholder::class, 'stakeholder_id'); | ||
| 42 | } | ||
| 43 | |||
| 44 | } |
| 1 | <?php | ||
| 2 | |||
| 3 | namespace App\Models\Legal; | ||
| 4 | |||
| 5 | use App\Models\BaseModel; | ||
| 6 | use Illuminate\Support\Facades\DB; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * Class stakeholderIncomeSyncApp | ||
| 10 | * @package App\Models | ||
| 11 | */ | ||
| 12 | class StakeholderIncomeSyncAppDetails extends BaseModel | ||
| 13 | { | ||
| 14 | const TYPE_INCOME = 1; //收入 | ||
| 15 | const TYPE_PAY = 2; //支出 | ||
| 16 | |||
| 17 | /** | ||
| 18 | * @var string | ||
| 19 | */ | ||
| 20 | protected $table = 'stakeholder_income_sync_app_details'; | ||
| 21 | |||
| 22 | /** | ||
| 23 | * @var array | ||
| 24 | */ | ||
| 25 | protected $guarded = []; | ||
| 26 | |||
| 27 | /** | ||
| 28 | * 付款方 | ||
| 29 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||
| 30 | */ | ||
| 31 | public function subject() | ||
| 32 | { | ||
| 33 | return $this->belongsTo(Subject::class, 'subject_no', 'no')->where('attr', 'like', '%1%'); | ||
| 34 | } | ||
| 35 | |||
| 36 | /** | ||
| 37 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||
| 38 | */ | ||
| 39 | public function stakeholder() | ||
| 40 | { | ||
| 41 | return $this->belongsTo(Stakeholder::class, 'stakeholder_id'); | ||
| 42 | } | ||
| 43 | |||
| 44 | } |
| 1 | <?php | ||
| 2 | |||
| 3 | namespace App\Models\Legal; | ||
| 4 | |||
| 5 | use App\Models\BaseModel; | ||
| 6 | use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * Class StakeholderIncomeSyncLogs | ||
| 10 | * @package App\Models\Legal | ||
| 11 | */ | ||
| 12 | class StakeholderIncomeSyncLogs extends BaseModel | ||
| 13 | { | ||
| 14 | public $table = 'stakeholder_income_sync_logs'; | ||
| 15 | } |
| ... | @@ -15,7 +15,7 @@ use App\Models\Legal\StakeholderIncomeByPayer; | ... | @@ -15,7 +15,7 @@ use App\Models\Legal\StakeholderIncomeByPayer; |
| 15 | class ApiService | 15 | class ApiService |
| 16 | { | 16 | { |
| 17 | protected static $uri = [ | 17 | protected static $uri = [ |
| 18 | 'walletAddIncome'=> '/api/wallet/addIncome', //外部系统入账-外部可调用 | 18 | 'walletAddIncome'=> '/api/income/addIncomeAndDetail', //外部系统入账-外部可调用 |
| 19 | ]; | 19 | ]; |
| 20 | 20 | ||
| 21 | /** | 21 | /** | ... | ... |
| ... | @@ -41,22 +41,18 @@ class MusicianWithdrawService extends Service | ... | @@ -41,22 +41,18 @@ class MusicianWithdrawService extends Service |
| 41 | */ | 41 | */ |
| 42 | public function receiptInfoByName() | 42 | public function receiptInfoByName() |
| 43 | { | 43 | { |
| 44 | /* | ||
| 45 | if (!StakeholderIncomeByPayer::query()->where(['sync_status'=>1, 'withdraw_status'=>0, 'identifier'=>$this->identifier->identifier])->count()) { | ||
| 46 | return Response::error(ErrorCode::WITHDRAW_NO_RECORD); | ||
| 47 | } | ||
| 48 | */ | ||
| 49 | |||
| 50 | if ($receipt = Company::query()->where(['receipt_name'=>$this->request->input('name')])->first()) { | 44 | if ($receipt = Company::query()->where(['receipt_name'=>$this->request->input('name')])->first()) { |
| 51 | return Response::success([ | 45 | return Response::success([ |
| 52 | 'receipt_type'=>$receipt->receipt_type, | 46 | 'receipt_type' => $receipt->receipt_type, |
| 53 | 'receipt_consignee'=>$receipt->receipt_consignee, | 47 | 'receipt_name' => $receipt->receipt_name, |
| 54 | 'receipt_name'=>$receipt->receipt_name, | 48 | 'receipt_no' => $receipt->receipt_no, |
| 55 | 'receipt_no' =>$receipt->receipt_no, | 49 | 'receipt_tel' => $receipt->receipt_tel, |
| 56 | 'receipt_tel' =>$receipt->receipt_tel, | 50 | 'receipt_address' => $receipt->receipt_address, |
| 57 | 'receipt_address'=>$receipt->receipt_address, | 51 | 'receipt_bank' => $receipt->receipt_bank, |
| 58 | 'receipt_bank'=>$receipt->receipt_bank, | 52 | 'receipt_bank_no' => $receipt->receipt_bank_no, |
| 59 | 'receipt_bank_no'=>$receipt->receipt_bank_no, | 53 | 'receipt_consignee' => $receipt->post_consignee, //收件人 |
| 54 | 'post_address' => $receipt->post_address, //邮寄地址 | ||
| 55 | 'post_phone' => $receipt->post_phone, //邮寄电话 | ||
| 60 | ]); | 56 | ]); |
| 61 | } else { | 57 | } else { |
| 62 | return Response::error(); | 58 | return Response::error(); | ... | ... |
app/Traits/Bills.php
0 → 100644
| 1 | <?php | ||
| 2 | |||
| 3 | |||
| 4 | namespace App\Traits; | ||
| 5 | |||
| 6 | use App\Models\Legal\Channel; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * 账单 | ||
| 10 | * Class Bills | ||
| 11 | * @package App\Traits | ||
| 12 | */ | ||
| 13 | trait Bills | ||
| 14 | { | ||
| 15 | |||
| 16 | /** | ||
| 17 | * 获取账单名字 | ||
| 18 | * @param \App\Models\Legal\Bills $bills | ||
| 19 | */ | ||
| 20 | public function billsTitle(\App\Models\Legal\Bills $bills) | ||
| 21 | { | ||
| 22 | $start_month = date('m', strtotime($bills->bill_section_start)); | ||
| 23 | $end_month = date('m', strtotime($bills->bill_section_end)); | ||
| 24 | $channel = Channel::getChannelName()[$bills->channel] ?? ''; | ||
| 25 | |||
| 26 | return "{$start_month}-{$end_month}月{$channel}版税账单"; | ||
| 27 | } | ||
| 28 | |||
| 29 | /** | ||
| 30 | * @param $month | ||
| 31 | * @return string | ||
| 32 | */ | ||
| 33 | public function billsSubTitle($month) | ||
| 34 | { | ||
| 35 | return $month . "月账单"; | ||
| 36 | } | ||
| 37 | |||
| 38 | |||
| 39 | } |
| ... | @@ -38,7 +38,7 @@ Route::group([], function (){ | ... | @@ -38,7 +38,7 @@ Route::group([], function (){ |
| 38 | //提现发票抬头 | 38 | //提现发票抬头 |
| 39 | Route::post('withdraw/receipt', 'MusicianWithdrawController@receipt'); | 39 | Route::post('withdraw/receipt', 'MusicianWithdrawController@receipt'); |
| 40 | //提现发票抬头 - 通过公司中文 | 40 | //提现发票抬头 - 通过公司中文 |
| 41 | Route::post('withdraw/receipt_by_name', 'MusicianWithdrawController@receiptByName'); | 41 | Route::get('withdraw/receipt_by_name', 'MusicianWithdrawController@receiptByName'); |
| 42 | //账单状态修改 | 42 | //账单状态修改 |
| 43 | Route::post('withdraw/status', 'MusicianWithdrawController@status'); | 43 | Route::post('withdraw/status', 'MusicianWithdrawController@status'); |
| 44 | 44 | ... | ... |
-
Please register or sign in to post a comment