StakeholderIncomeSyncJob.php
2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace App\Jobs;
use App\Helper\CacheKeyTools;
use App\Helper\RedisClient;
use App\Models\Legal\Bills;
use App\Models\Legal\Company;
use App\Services\ApiService;
use App\Traits\TaxReckon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class StakeholderIncomeSyncJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, TaxReckon;
    const COUNT = 1;
    const BLOCK_TIME = 3;
    const TYPE_BILLS = 1001601; //账单分成
    const TYPE_ROYALTY = 1001602; //合作伙伴打款 type = 1 版税分成
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        Log::info(__METHOD__."入账数据同步任务", ['time'=>now()->toDateTimeString()]);
    }
    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $id = '0';
        while (true) {
            $redis = RedisClient::instance('bills');
            $key   = CacheKeyTools::billsSync();
            //处理消息体
            if($msg = $redis->xread([$key=>$id], 1, 3)) {
                $id = key($msg[$key]);
                $income_item = $msg[$key][$id];
                $company = Company::query()->find($income_item['company_id']);
                $bills   = Bills::query()->find($income_item['related_id']);
                $channel = 'TME';
                $title   = "{$bills->bill_section_start}-{$bills->bill_section_end}账单/{$channel}";
                $http_res = ApiService::walletAddIncome([
                    'cardNo'=>$income_item['identifier'],
                    'faxMoney'=>$income_item['fax_money'],
                    'money'=>$income_item['money'],
                    'totalMoney'=>$income_item['total_money'],
                    'paymentCompany'=>$company->receipt_name,
                    'type'=>self::TYPE_BILLS,
                    'title'=>"{$bills->bill_section_start}-{$bills->bill_section_end}账单/{$channel}",
                ]);
                if (empty($http_res)) {
                    //重试 401/403/403
                    Log::info(__METHOD__.'请求失败');
                } else {
                    switch ($http_res['code']) {
                    }
                }
            }
        }
    }
}