123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517 |
- <?php
- namespace App\Console;
- use App\Model\User;
- use App\Models\OrderTest;
- use App\Models\SeCode;
- use App\Models\UserPay;
- use Endroid\QrCode\ErrorCorrectionLevel;
- use Endroid\QrCode\LabelAlignment;
- use Illuminate\Console\Scheduling\Schedule;
- use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
- use GuzzleHttp\Client;
- use Illuminate\Support\Facades\File;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\DB;
- use SimpleSoftwareIO\QrCode\Facades\QrCode;
- class Kernel extends ConsoleKernel
- {
- /**
- * The Artisan commands provided by your application.
- *
- * @var array
- */
- protected $commands = [
- //
- ];
- /**
- * Define the application's command schedule.
- *
- * @param \Illuminate\Console\Scheduling\Schedule $schedule
- * @return void
- */
- protected function schedule(Schedule $schedule)
- {
- // $schedule->call(function (){
- // $data=DB::table('se_code')->where('id','>=',1778504)->where('model','1:6:36')->where('level',1)->get();
- // foreach ($data as $k=>$v){
- // $name='新36/第'.($k+1).'批';
- // $this->code('http://fangw.jiuweiyun.cn/api/auth/'.$v->code,$k,$v->security_code,$v->level,0,$name);
- // $re=SeCode::where('id','>=',1778504)->where('pid',$v->sort)->with(['get_child'])->get();
- // foreach ($re as $ke=>$va){
- // $this->code('http://fangw.jiuweiyun.cn/api/auth/'.$va->code,$k,$va->security_code,$va->level,$ke+1,$name);
- // foreach ($va->get_child as $kes=>$vas){
- // $this->code('http://fangw.jiuweiyun.cn/api/auth/'.$vas->code,$k,$vas->security_code,$vas->level,$ke+1,$name,$kes+1);
- // }
- // }
- // }
- // })->everyMinute();
- // $schedule->call(function (){
- // $data=SeCode::where('id','>',1777663)->where('model','1:10')->where('level',1)->with(['get_child'])->get();
- // foreach ($data as $k=>$v){
- // $name='10/第'.($k+1).'批';
- // $this->codes('http://fangw.jiuweiyun.cn/api/auth/'.$v->code,$k,$v->security_code,$v->level,0,$name);
- // foreach ($v->get_child as $ke=>$va){
- // $this->codes('http://fangw.jiuweiyun.cn/api/auth/'.$va->code,$k,$va->security_code,$va->level,$ke+1,$name);
- // }
- // }
- // })->everyMinute();
- // $schedule->command('inspire')
- // ->hourly();
- $schedule->call(function (){
- Log::error('s');
- })->everyMinute();
- $schedule->call(function (){
- $data=DB::table('inte_review')->where('season',22)->paginate(200);
- foreach ($data as $ke=>$va){
- $img = file_get_contents($va->imgurl);
- // $img = file_get_contents('1208_1587087511_3wzFd27yxL.jpg');
- $img = base64_encode($img);
- $client=new Client();
- $url='https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token=24.c806ef3eeef3e0686c331b84da7ecb49.2592000.1589681450.282335-14562722';
- // $url='https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=24.c806ef3eeef3e0686c331b84da7ecb49.2592000.1589681450.282335-14562722';
- $array=[
- // 'form_params'=>[
- // 'access_token'=>'24.c806ef3eeef3e0686c331b84da7ecb49.2592000.1589681450.282335-14562722'
- // ],
- 'form_params'=>[
- 'image'=>$img
- ]
- ];
- $data=$client->request('POST',$url,$array);
- $ad = json_decode($data->getBody()->getContents());
- $crr=[];
- foreach ($ad->words_result as $k=>$v){
- $crr[$k]=$v->words;
- }
- $str=implode('',$crr);
- // dump($str);
- if(strpos($str,'查看零钱') || strpos($str,'零钱明细') ||strpos($str,'提现银行')){
- return ['code'=>800];
- }elseif(in_array('交易说明',$crr) || in_array('商家订单号',$crr) ||in_array('发起退款',$crr)){
- $str=implode($crr);
- $pattem1="/(20)\d{26}/";
- preg_match($pattem1,str_replace(" ","",$str),$match1);
- if($match1){
- $order_no=$match1[0];
- }
- $pattem2="/(¥|\+)([1-9]\d{0,2},)*\d{1,3}\.\d{2}/";
- preg_match($pattem2,$str,$match2);
- if($match2){
- $fee=str_replace(",","",mb_substr($match2[0],1));
- }else{
- $pattem2="/(¥|\+)([1-9]\d{0,2})*\d{1,3}\.\d{2}/";
- preg_match($pattem2,$str,$match2);
- if($match2){
- $fee=str_replace(",","",mb_substr($match2[0],1));
- }
- }
- $pattem3="/(20)\d{2}-\d{2}-\d{2}\s?\d{2}:\d{2}/";
- preg_match($pattem3,$str,$match3);
- if($match3){
- $time=substr($match3[0],0,10);
- }
- $type=1;
- }elseif(in_array('收款方式',$crr) || in_array('转账备注',$crr) ||in_array('对方账户',$crr)){
- $str=implode($crr);
- $pattem1="/(20)\d{30}/";
- preg_match($pattem1,str_replace(" ","",$str),$match1);
- if($match1){
- $order_no=$match1[0];
- }else{
- $pattem1="/(订单号2)\d{29,30}/";
- preg_match($pattem1,str_replace(" ","",$str),$match1);
- if($match1){
- $order_no=mb_substr($match1[0],3);
- }
- }
- $pattem2="/(¥|\+)([1-9]\d{0,2},)*\d{1,3}\.\d{2}/";
- preg_match($pattem2,$str,$match2);
- if($match2){
- $fee=str_replace(",","",mb_substr($match2[0],1));
- }
- $pattem3="/(20)\d{2}-\d{2}-\d{2}\s?\d{2}:\d{2}/";
- preg_match($pattem3,$str,$match3);
- if($match3){
- $time=substr($match3[0],0,10);
- }
- $type=1;
- }else{
- $str=implode($crr);
- if(strpos($str,'转账说明') || strpos($str,'转账时间') ||strpos($str,'转账单号')){
- $pattem1="/[1-9]\d{30,32}/";
- preg_match($pattem1,str_replace(" ","",$str),$match1);
- if($match1){
- $order_no=$match1[0];
- }else{
- $pattem1="/(转账单号 1)\d{29,31}/";
- preg_match($pattem1,$str,$match1);
- if($match1){
- $order_no=mb_substr($match1[0],5);
- }
- }
- // $pattem2="/(\+)[1-9]\d*\.\d{2}/";
- $pattem2="/(?<!G)(\+)[1-9]\d*\.\d{2}/";
- preg_match($pattem2,$str,$match2);
- if($match2){
- $fee=mb_substr($match2[0],1);
- }else{
- //新增情况
- $pattem2="/(\十 )[1-9]\d*\.\d{2}/";
- preg_match($pattem2,$str,$match2);
- if($match2){
- $fee=mb_substr($match2[0],2);
- }else{
- $pattem2="/(\十)[1-9]\d*\.\d{2}/";
- preg_match($pattem2,$str,$match2);
- if($match2){
- $fee=mb_substr($match2[0],1);
- }else{
- $pattem2="/(\+)[1-9]\d*\.\d{2}/";
- preg_match($pattem2,$str,$match2);
- if($match2){
- $fee=mb_substr($match2[0],1);
- }
- }
- }
- }
- $pattem3="/(收款时间20)\d{2}-\d{2}-\d{2}\s?\d{2}:\d{2}/";
- preg_match($pattem3,$str,$match3);
- if($match3){
- $time=mb_substr($match3[0],4);
- $time=substr($time,0,10);
- }else{
- $pattem3="/(20)\d{2}-\d{2}-\d{2}\s?\d{2}:\d{2}/";
- preg_match($pattem3,$str,$match3);
- if($match3){
- $time=substr($match3[0],0,10);
- }
- }
- $type=0;
- }elseif(strpos($str,'商户单号')){
- $pattem1="/[1-9]\d{30}/";
- preg_match($pattem1,str_replace(" ","",$str),$match1);
- if($match1){
- $order_no=$match1[0];
- }
- $pattem2="/(\+)[1-9]\d*\.\d{2}/";
- preg_match($pattem2,$str,$match2);
- if($match2){
- $fee=mb_substr($match2[0],1);
- }
- $pattem3="/(20)\d{2}-\d{2}-\d{2}\s?\d{2}:\d{2}/";
- preg_match($pattem3,$str,$match3);
- if($match3){
- $time=substr($match3[0],0,10);
- }
- $type=0;
- }elseif(strpos($str,'创建时间')){
- $str=implode($crr);
- $pattem1="/(20)\d{26}/";
- preg_match($pattem1,str_replace(" ","",$str),$match1);
- if($match1){
- $order_no=$match1[0];
- }
- $pattem2="/(¥|\+)([1-9]\d{0,2},)*\d{1,3}\.\d{2}/";
- preg_match($pattem2,$str,$match2);
- if($match2){
- $fee=str_replace(",","",mb_substr($match2[0],1));
- }
- $pattem3="/(20)\d{2}-\d{2}-\d{2}\s\d{2}:\d{2}/";
- preg_match($pattem3,$str,$match3);
- if($match3){
- $time=$match3[0];
- }
- $type=0;
- }else{
- Log::error('1003');
- // return ['code'=>1003];//不符合格式
- }
- }
- if(empty($order_no)){
- Log::error('1001');
- // return [
- // 'code'=>1001,
- // ];
- }
- if(empty($time)){
- Log::error('1002');
- // return [
- // 'code'=>1002,
- // ];
- }
- if(empty($fee)){
- $fpattem2="/(\-)[1-9]\d*\.\d{2}/";
- preg_match($fpattem2,$str,$fmatch2);
- if($fmatch2){
- $ffee=mb_substr($fmatch2[0],1);
- if($ffee){
- // return ['code'=>1000];
- Log::error('1000');
- }
- }
- // return [
- // 'code'=>1004,
- // 'data'=>[
- // 'time'=>$time,
- // 'number'=>$order_no,
- // 'figure'=>$fee,
- // 'type'=>$type
- // ]
- // ];//未识别到金额
- Log::error('1004');
- }
- if($time && $order_no && $fee){
- // return [
- // 'code'=>200,
- // 'data'=>[
- // 'time'=>$time,
- // 'number'=>$order_no,
- // 'figure'=>$fee,
- // 'type'=>$type
- // ]
- // ];
- Log::error('200');
- }
- }
- })->dailyAt('13:00');
- $schedule->command('AutoCommand')->withoutOverlapping()->everyMinute();
- $schedule->call(function (){
- //
- // $orders = Ordertest::whereIn('pay_status', [0, 1])->where('is_deleted', 0)->get();
- //
- //
- //
- // foreach ($orders as $key => $val) {
- // DB::beginTransaction();
- // try {
- // if (!in_array($val->pay_status, ['0', '1']) || $val->is_deleted == '1') {
- // continue; //订单状态改变,不支付
- // }
- // $user_id = $val->user_id;
- // $user = User::where('id', $user_id)->first();
- // if ($user->money <= 0) {
- // $user->save();
- // continue; //账户没钱,不支付
- // }
- // if ($val->money - $val->pay_money == $val->no_pay_money) {
- // $no_pay_money = $val->no_pay_money;
- // } else {
- // $no_pay_money = $val->money - $val->pay_money;
- // }
- // if ($no_pay_money <= 0) {
- // continue; //没有未支付金额,不支付
- // }
- // if ($user->money >= $no_pay_money) {
- // $user->money = $user->money - $no_pay_money;
- // $pay_money = $no_pay_money;//支付金额
- // } else {
- // $pay_money = $user->money;//支付金额
- // $user->money = 0;
- // }
- // if (!$user->save()) {
- // throw new \Exception('1');
- // }
- // //支付日志
- // $remark = '系统自动支付';
- // $userpay = new Userpay();
- // $userpay->user_id = $user_id;
- // $userpay->pay_money = $pay_money;
- // $userpay->op_name = '系统自动支付';
- // $userpay->type = 1;//支付
- // $userpay->remark = $remark . ',订单编号为' . $val->order_num;
- // $userpay->order_num = $val->order_num;
- // $userpay->pay_num = $this->pay_num($user_id);
- // $userpay->user_money = $user->money;
- // if (!$userpay->save()) {
- // throw new \Exception('2');
- // }
- // //订单变更
- // $order = Ordertest::where('id', $val->id)->sharedLock()->first();
- // if ($order->pay_status == 2) {
- // Log::error('订单编号为:' . $order->order_num . '的订单已经支付');
- // throw new \Exception('1');
- // }
- // if ($order->pay_money != $val->pay_money) {
- // Log::error('订单编号为:' . $order->order_num . '的订单已经部分支付');
- // throw new \Exception('1');
- // }
- // $order->pay_money += $pay_money;
- // $order->no_pay_money = $order->money - $order->pay_money;
- // if ($order->pay_money == $order->money) {
- // $order->pay_status = '2';//全部支付
- // } elseif ($order->pay_money > 0 && $order->pay_money < $order->money) {
- // $order->pay_status = '1';//部分支付
- // } elseif ($order->pay_money == 0) {
- // $order->pay_status = '0';//未支付
- // } elseif ($order->pay_money > $order->money) {
- // $order->pay_status = '3';//需部分退款
- // $order->wait_back_money = $order->pay_money - $order->money;
- // }
- // if (!$order->save()) {
- // throw new \Exception('1');
- // }
- //
- // DB::commit();
- // Log::info('订单编号为' . $val->order_num . '已经自动支付已完成');
- // } catch (\Exception $e) {
- // DB::rollBack();
- // Log::info('自动支付失败' );
- // }
- // }
- })->everyMinute();
- }
- /**
- * Register the commands for the application.
- *
- * @return void
- */
- //支付单号
- public function pay_num($user_id)
- {
- $num = date('Ymd', time()) . '100000' . str_pad($user_id, 6, 0, STR_PAD_LEFT) . rand(11111, 99999);
- $count = UserPay::where('pay_num', $num)->count();
- if ($count > 0) {
- $num = $this->pay_num($user_id);
- return $num;
- }
- return $num;
- }
- public function code($url,$k,$num,$level,$s=0,$file,$t=0){
- $qrCode = new \Endroid\QrCode\QrCode($url);
- // 内容区域宽高,默认为300
- $qrCode->setSize(200);
- // 外边距大小,默认为10
- $qrCode->setMargin(10);
- // 设置编码
- $qrCode->setEncoding('UTF-8');
- // 设置容错等级
- $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH());
- // 设置二维码颜色,默认为黑色
- $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
- // 设置二维码背景色,默认为白色
- $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
- // 设置二维码下方的文字
- switch ($level){
- case 1:
- $level_name='大码';
- break;
- case 2:
- $level_name='中码';
- break;
- case 3:
- $level_name='小码';
- break;
- }
- if ($level!=1){
- $level_name=$level_name.'-'.$s;
- }
- if ($level==3){
- $level_name=$level_name.'-'.$t;
- }
- $qrCode->setLabel($level_name.'-'.$num, 15, null, LabelAlignment::CENTER());
- ##### 二维码中的logo #####
- // $qrCode->setLogoPath('logo.jpg');
- // $qrCode->setLogoSize(100, 90);
- // $qrCode->setLogoWidth(100);
- // $qrCode->setLogoHeight(90);
- ##### 二维码中的logo / #####
- // 启用内置的验证读取器(默认情况下禁用)
- // $qrCode->setValidateResult(false);
- ########## 二维码三种显示方式 ##########
- // 二维码输出在浏览器上
- // header('Content-Type: ' . $qrCode->getContentType());
- // echo $qrCode->writeString();
- // 二维码存在本地
- Log::error(1);
- $path='public/code/'.$file;
- $path = public_path().'/code/'.$file;
- File::makeDirectory($path,$mode = 0777,true,true);
- $qrCode->writeFile('public/code/'.$file.'/'.$level_name.'.png');
- }
- public function codes($url,$k,$num,$level,$s=0,$file,$t=0){
- $qrCode = new \Endroid\QrCode\QrCode($url);
- // 内容区域宽高,默认为300
- $qrCode->setSize(200);
- // 外边距大小,默认为10
- $qrCode->setMargin(10);
- // 设置编码
- $qrCode->setEncoding('UTF-8');
- // 设置容错等级
- $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH());
- // 设置二维码颜色,默认为黑色
- $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
- // 设置二维码背景色,默认为白色
- $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
- // 设置二维码下方的文字
- switch ($level){
- case 1:
- $level_name='大码';
- break;
- case 2:
- $level_name='小码';
- break;
- case 3:
- $level_name='小码';
- break;
- }
- if ($level==2){
- $level_name=$level_name.'-'.$s;
- }
- $qrCode->setLabel($level_name.'-'.$num, 15, null, LabelAlignment::CENTER());
- ##### 二维码中的logo #####
- // $qrCode->setLogoPath('logo.jpg');
- // $qrCode->setLogoSize(100, 90);
- // $qrCode->setLogoWidth(100);
- // $qrCode->setLogoHeight(90);
- ##### 二维码中的logo / #####
- // 启用内置的验证读取器(默认情况下禁用)
- // $qrCode->setValidateResult(false);
- ########## 二维码三种显示方式 ##########
- // 二维码输出在浏览器上
- // header('Content-Type: ' . $qrCode->getContentType());
- // echo $qrCode->writeString();
- // 二维码存在本地
- Log::error(1);
- $path='public/code/'.$file;
- $path = public_path().'/code/'.$file;
- File::makeDirectory($path,$mode = 0777,true,true);
- $qrCode->writeFile('public/code/'.$file.'/'.$level_name.'.png');
- }
- protected function commands()
- {
- $this->load(__DIR__.'/Commands');
- require base_path('routes/console.php');
- }
- }
|