Kernel.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <?php
  2. namespace App\Console;
  3. use App\Model\User;
  4. use App\Models\OrderTest;
  5. use App\Models\SeCode;
  6. use App\Models\UserPay;
  7. use Endroid\QrCode\ErrorCorrectionLevel;
  8. use Endroid\QrCode\LabelAlignment;
  9. use Illuminate\Console\Scheduling\Schedule;
  10. use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
  11. use GuzzleHttp\Client;
  12. use Illuminate\Support\Facades\File;
  13. use Illuminate\Support\Facades\Log;
  14. use Illuminate\Support\Facades\DB;
  15. use SimpleSoftwareIO\QrCode\Facades\QrCode;
  16. class Kernel extends ConsoleKernel
  17. {
  18. /**
  19. * The Artisan commands provided by your application.
  20. *
  21. * @var array
  22. */
  23. protected $commands = [
  24. //
  25. ];
  26. /**
  27. * Define the application's command schedule.
  28. *
  29. * @param \Illuminate\Console\Scheduling\Schedule $schedule
  30. * @return void
  31. */
  32. protected function schedule(Schedule $schedule)
  33. {
  34. // $schedule->call(function (){
  35. // $data=DB::table('se_code')->where('id','>=',1778504)->where('model','1:6:36')->where('level',1)->get();
  36. // foreach ($data as $k=>$v){
  37. // $name='新36/第'.($k+1).'批';
  38. // $this->code('http://fangw.jiuweiyun.cn/api/auth/'.$v->code,$k,$v->security_code,$v->level,0,$name);
  39. // $re=SeCode::where('id','>=',1778504)->where('pid',$v->sort)->with(['get_child'])->get();
  40. // foreach ($re as $ke=>$va){
  41. // $this->code('http://fangw.jiuweiyun.cn/api/auth/'.$va->code,$k,$va->security_code,$va->level,$ke+1,$name);
  42. // foreach ($va->get_child as $kes=>$vas){
  43. // $this->code('http://fangw.jiuweiyun.cn/api/auth/'.$vas->code,$k,$vas->security_code,$vas->level,$ke+1,$name,$kes+1);
  44. // }
  45. // }
  46. // }
  47. // })->everyMinute();
  48. // $schedule->call(function (){
  49. // $data=SeCode::where('id','>',1777663)->where('model','1:10')->where('level',1)->with(['get_child'])->get();
  50. // foreach ($data as $k=>$v){
  51. // $name='10/第'.($k+1).'批';
  52. // $this->codes('http://fangw.jiuweiyun.cn/api/auth/'.$v->code,$k,$v->security_code,$v->level,0,$name);
  53. // foreach ($v->get_child as $ke=>$va){
  54. // $this->codes('http://fangw.jiuweiyun.cn/api/auth/'.$va->code,$k,$va->security_code,$va->level,$ke+1,$name);
  55. // }
  56. // }
  57. // })->everyMinute();
  58. // $schedule->command('inspire')
  59. // ->hourly();
  60. $schedule->call(function (){
  61. Log::error('s');
  62. })->everyMinute();
  63. $schedule->call(function (){
  64. $data=DB::table('inte_review')->where('season',22)->paginate(200);
  65. foreach ($data as $ke=>$va){
  66. $img = file_get_contents($va->imgurl);
  67. // $img = file_get_contents('1208_1587087511_3wzFd27yxL.jpg');
  68. $img = base64_encode($img);
  69. $client=new Client();
  70. $url='https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token=24.c806ef3eeef3e0686c331b84da7ecb49.2592000.1589681450.282335-14562722';
  71. // $url='https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=24.c806ef3eeef3e0686c331b84da7ecb49.2592000.1589681450.282335-14562722';
  72. $array=[
  73. // 'form_params'=>[
  74. // 'access_token'=>'24.c806ef3eeef3e0686c331b84da7ecb49.2592000.1589681450.282335-14562722'
  75. // ],
  76. 'form_params'=>[
  77. 'image'=>$img
  78. ]
  79. ];
  80. $data=$client->request('POST',$url,$array);
  81. $ad = json_decode($data->getBody()->getContents());
  82. $crr=[];
  83. foreach ($ad->words_result as $k=>$v){
  84. $crr[$k]=$v->words;
  85. }
  86. $str=implode('',$crr);
  87. // dump($str);
  88. if(strpos($str,'查看零钱') || strpos($str,'零钱明细') ||strpos($str,'提现银行')){
  89. return ['code'=>800];
  90. }elseif(in_array('交易说明',$crr) || in_array('商家订单号',$crr) ||in_array('发起退款',$crr)){
  91. $str=implode($crr);
  92. $pattem1="/(20)\d{26}/";
  93. preg_match($pattem1,str_replace(" ","",$str),$match1);
  94. if($match1){
  95. $order_no=$match1[0];
  96. }
  97. $pattem2="/(¥|\+)([1-9]\d{0,2},)*\d{1,3}\.\d{2}/";
  98. preg_match($pattem2,$str,$match2);
  99. if($match2){
  100. $fee=str_replace(",","",mb_substr($match2[0],1));
  101. }else{
  102. $pattem2="/(¥|\+)([1-9]\d{0,2})*\d{1,3}\.\d{2}/";
  103. preg_match($pattem2,$str,$match2);
  104. if($match2){
  105. $fee=str_replace(",","",mb_substr($match2[0],1));
  106. }
  107. }
  108. $pattem3="/(20)\d{2}-\d{2}-\d{2}\s?\d{2}:\d{2}/";
  109. preg_match($pattem3,$str,$match3);
  110. if($match3){
  111. $time=substr($match3[0],0,10);
  112. }
  113. $type=1;
  114. }elseif(in_array('收款方式',$crr) || in_array('转账备注',$crr) ||in_array('对方账户',$crr)){
  115. $str=implode($crr);
  116. $pattem1="/(20)\d{30}/";
  117. preg_match($pattem1,str_replace(" ","",$str),$match1);
  118. if($match1){
  119. $order_no=$match1[0];
  120. }else{
  121. $pattem1="/(订单号2)\d{29,30}/";
  122. preg_match($pattem1,str_replace(" ","",$str),$match1);
  123. if($match1){
  124. $order_no=mb_substr($match1[0],3);
  125. }
  126. }
  127. $pattem2="/(¥|\+)([1-9]\d{0,2},)*\d{1,3}\.\d{2}/";
  128. preg_match($pattem2,$str,$match2);
  129. if($match2){
  130. $fee=str_replace(",","",mb_substr($match2[0],1));
  131. }
  132. $pattem3="/(20)\d{2}-\d{2}-\d{2}\s?\d{2}:\d{2}/";
  133. preg_match($pattem3,$str,$match3);
  134. if($match3){
  135. $time=substr($match3[0],0,10);
  136. }
  137. $type=1;
  138. }else{
  139. $str=implode($crr);
  140. if(strpos($str,'转账说明') || strpos($str,'转账时间') ||strpos($str,'转账单号')){
  141. $pattem1="/[1-9]\d{30,32}/";
  142. preg_match($pattem1,str_replace(" ","",$str),$match1);
  143. if($match1){
  144. $order_no=$match1[0];
  145. }else{
  146. $pattem1="/(转账单号 1)\d{29,31}/";
  147. preg_match($pattem1,$str,$match1);
  148. if($match1){
  149. $order_no=mb_substr($match1[0],5);
  150. }
  151. }
  152. // $pattem2="/(\+)[1-9]\d*\.\d{2}/";
  153. $pattem2="/(?<!G)(\+)[1-9]\d*\.\d{2}/";
  154. preg_match($pattem2,$str,$match2);
  155. if($match2){
  156. $fee=mb_substr($match2[0],1);
  157. }else{
  158. //新增情况
  159. $pattem2="/(\十 )[1-9]\d*\.\d{2}/";
  160. preg_match($pattem2,$str,$match2);
  161. if($match2){
  162. $fee=mb_substr($match2[0],2);
  163. }else{
  164. $pattem2="/(\十)[1-9]\d*\.\d{2}/";
  165. preg_match($pattem2,$str,$match2);
  166. if($match2){
  167. $fee=mb_substr($match2[0],1);
  168. }else{
  169. $pattem2="/(\+)[1-9]\d*\.\d{2}/";
  170. preg_match($pattem2,$str,$match2);
  171. if($match2){
  172. $fee=mb_substr($match2[0],1);
  173. }
  174. }
  175. }
  176. }
  177. $pattem3="/(收款时间20)\d{2}-\d{2}-\d{2}\s?\d{2}:\d{2}/";
  178. preg_match($pattem3,$str,$match3);
  179. if($match3){
  180. $time=mb_substr($match3[0],4);
  181. $time=substr($time,0,10);
  182. }else{
  183. $pattem3="/(20)\d{2}-\d{2}-\d{2}\s?\d{2}:\d{2}/";
  184. preg_match($pattem3,$str,$match3);
  185. if($match3){
  186. $time=substr($match3[0],0,10);
  187. }
  188. }
  189. $type=0;
  190. }elseif(strpos($str,'商户单号')){
  191. $pattem1="/[1-9]\d{30}/";
  192. preg_match($pattem1,str_replace(" ","",$str),$match1);
  193. if($match1){
  194. $order_no=$match1[0];
  195. }
  196. $pattem2="/(\+)[1-9]\d*\.\d{2}/";
  197. preg_match($pattem2,$str,$match2);
  198. if($match2){
  199. $fee=mb_substr($match2[0],1);
  200. }
  201. $pattem3="/(20)\d{2}-\d{2}-\d{2}\s?\d{2}:\d{2}/";
  202. preg_match($pattem3,$str,$match3);
  203. if($match3){
  204. $time=substr($match3[0],0,10);
  205. }
  206. $type=0;
  207. }elseif(strpos($str,'创建时间')){
  208. $str=implode($crr);
  209. $pattem1="/(20)\d{26}/";
  210. preg_match($pattem1,str_replace(" ","",$str),$match1);
  211. if($match1){
  212. $order_no=$match1[0];
  213. }
  214. $pattem2="/(¥|\+)([1-9]\d{0,2},)*\d{1,3}\.\d{2}/";
  215. preg_match($pattem2,$str,$match2);
  216. if($match2){
  217. $fee=str_replace(",","",mb_substr($match2[0],1));
  218. }
  219. $pattem3="/(20)\d{2}-\d{2}-\d{2}\s\d{2}:\d{2}/";
  220. preg_match($pattem3,$str,$match3);
  221. if($match3){
  222. $time=$match3[0];
  223. }
  224. $type=0;
  225. }else{
  226. Log::error('1003');
  227. // return ['code'=>1003];//不符合格式
  228. }
  229. }
  230. if(empty($order_no)){
  231. Log::error('1001');
  232. // return [
  233. // 'code'=>1001,
  234. // ];
  235. }
  236. if(empty($time)){
  237. Log::error('1002');
  238. // return [
  239. // 'code'=>1002,
  240. // ];
  241. }
  242. if(empty($fee)){
  243. $fpattem2="/(\-)[1-9]\d*\.\d{2}/";
  244. preg_match($fpattem2,$str,$fmatch2);
  245. if($fmatch2){
  246. $ffee=mb_substr($fmatch2[0],1);
  247. if($ffee){
  248. // return ['code'=>1000];
  249. Log::error('1000');
  250. }
  251. }
  252. // return [
  253. // 'code'=>1004,
  254. // 'data'=>[
  255. // 'time'=>$time,
  256. // 'number'=>$order_no,
  257. // 'figure'=>$fee,
  258. // 'type'=>$type
  259. // ]
  260. // ];//未识别到金额
  261. Log::error('1004');
  262. }
  263. if($time && $order_no && $fee){
  264. // return [
  265. // 'code'=>200,
  266. // 'data'=>[
  267. // 'time'=>$time,
  268. // 'number'=>$order_no,
  269. // 'figure'=>$fee,
  270. // 'type'=>$type
  271. // ]
  272. // ];
  273. Log::error('200');
  274. }
  275. }
  276. })->dailyAt('13:00');
  277. $schedule->command('AutoCommand')->withoutOverlapping()->everyMinute();
  278. $schedule->call(function (){
  279. //
  280. // $orders = Ordertest::whereIn('pay_status', [0, 1])->where('is_deleted', 0)->get();
  281. //
  282. //
  283. //
  284. // foreach ($orders as $key => $val) {
  285. // DB::beginTransaction();
  286. // try {
  287. // if (!in_array($val->pay_status, ['0', '1']) || $val->is_deleted == '1') {
  288. // continue; //订单状态改变,不支付
  289. // }
  290. // $user_id = $val->user_id;
  291. // $user = User::where('id', $user_id)->first();
  292. // if ($user->money <= 0) {
  293. // $user->save();
  294. // continue; //账户没钱,不支付
  295. // }
  296. // if ($val->money - $val->pay_money == $val->no_pay_money) {
  297. // $no_pay_money = $val->no_pay_money;
  298. // } else {
  299. // $no_pay_money = $val->money - $val->pay_money;
  300. // }
  301. // if ($no_pay_money <= 0) {
  302. // continue; //没有未支付金额,不支付
  303. // }
  304. // if ($user->money >= $no_pay_money) {
  305. // $user->money = $user->money - $no_pay_money;
  306. // $pay_money = $no_pay_money;//支付金额
  307. // } else {
  308. // $pay_money = $user->money;//支付金额
  309. // $user->money = 0;
  310. // }
  311. // if (!$user->save()) {
  312. // throw new \Exception('1');
  313. // }
  314. // //支付日志
  315. // $remark = '系统自动支付';
  316. // $userpay = new Userpay();
  317. // $userpay->user_id = $user_id;
  318. // $userpay->pay_money = $pay_money;
  319. // $userpay->op_name = '系统自动支付';
  320. // $userpay->type = 1;//支付
  321. // $userpay->remark = $remark . ',订单编号为' . $val->order_num;
  322. // $userpay->order_num = $val->order_num;
  323. // $userpay->pay_num = $this->pay_num($user_id);
  324. // $userpay->user_money = $user->money;
  325. // if (!$userpay->save()) {
  326. // throw new \Exception('2');
  327. // }
  328. // //订单变更
  329. // $order = Ordertest::where('id', $val->id)->sharedLock()->first();
  330. // if ($order->pay_status == 2) {
  331. // Log::error('订单编号为:' . $order->order_num . '的订单已经支付');
  332. // throw new \Exception('1');
  333. // }
  334. // if ($order->pay_money != $val->pay_money) {
  335. // Log::error('订单编号为:' . $order->order_num . '的订单已经部分支付');
  336. // throw new \Exception('1');
  337. // }
  338. // $order->pay_money += $pay_money;
  339. // $order->no_pay_money = $order->money - $order->pay_money;
  340. // if ($order->pay_money == $order->money) {
  341. // $order->pay_status = '2';//全部支付
  342. // } elseif ($order->pay_money > 0 && $order->pay_money < $order->money) {
  343. // $order->pay_status = '1';//部分支付
  344. // } elseif ($order->pay_money == 0) {
  345. // $order->pay_status = '0';//未支付
  346. // } elseif ($order->pay_money > $order->money) {
  347. // $order->pay_status = '3';//需部分退款
  348. // $order->wait_back_money = $order->pay_money - $order->money;
  349. // }
  350. // if (!$order->save()) {
  351. // throw new \Exception('1');
  352. // }
  353. //
  354. // DB::commit();
  355. // Log::info('订单编号为' . $val->order_num . '已经自动支付已完成');
  356. // } catch (\Exception $e) {
  357. // DB::rollBack();
  358. // Log::info('自动支付失败' );
  359. // }
  360. // }
  361. })->everyMinute();
  362. }
  363. /**
  364. * Register the commands for the application.
  365. *
  366. * @return void
  367. */
  368. //支付单号
  369. public function pay_num($user_id)
  370. {
  371. $num = date('Ymd', time()) . '100000' . str_pad($user_id, 6, 0, STR_PAD_LEFT) . rand(11111, 99999);
  372. $count = UserPay::where('pay_num', $num)->count();
  373. if ($count > 0) {
  374. $num = $this->pay_num($user_id);
  375. return $num;
  376. }
  377. return $num;
  378. }
  379. public function code($url,$k,$num,$level,$s=0,$file,$t=0){
  380. $qrCode = new \Endroid\QrCode\QrCode($url);
  381. // 内容区域宽高,默认为300
  382. $qrCode->setSize(200);
  383. // 外边距大小,默认为10
  384. $qrCode->setMargin(10);
  385. // 设置编码
  386. $qrCode->setEncoding('UTF-8');
  387. // 设置容错等级
  388. $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH());
  389. // 设置二维码颜色,默认为黑色
  390. $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
  391. // 设置二维码背景色,默认为白色
  392. $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
  393. // 设置二维码下方的文字
  394. switch ($level){
  395. case 1:
  396. $level_name='大码';
  397. break;
  398. case 2:
  399. $level_name='中码';
  400. break;
  401. case 3:
  402. $level_name='小码';
  403. break;
  404. }
  405. if ($level!=1){
  406. $level_name=$level_name.'-'.$s;
  407. }
  408. if ($level==3){
  409. $level_name=$level_name.'-'.$t;
  410. }
  411. $qrCode->setLabel($level_name.'-'.$num, 15, null, LabelAlignment::CENTER());
  412. ##### 二维码中的logo #####
  413. // $qrCode->setLogoPath('logo.jpg');
  414. // $qrCode->setLogoSize(100, 90);
  415. // $qrCode->setLogoWidth(100);
  416. // $qrCode->setLogoHeight(90);
  417. ##### 二维码中的logo / #####
  418. // 启用内置的验证读取器(默认情况下禁用)
  419. // $qrCode->setValidateResult(false);
  420. ########## 二维码三种显示方式 ##########
  421. // 二维码输出在浏览器上
  422. // header('Content-Type: ' . $qrCode->getContentType());
  423. // echo $qrCode->writeString();
  424. // 二维码存在本地
  425. Log::error(1);
  426. $path='public/code/'.$file;
  427. $path = public_path().'/code/'.$file;
  428. File::makeDirectory($path,$mode = 0777,true,true);
  429. $qrCode->writeFile('public/code/'.$file.'/'.$level_name.'.png');
  430. }
  431. public function codes($url,$k,$num,$level,$s=0,$file,$t=0){
  432. $qrCode = new \Endroid\QrCode\QrCode($url);
  433. // 内容区域宽高,默认为300
  434. $qrCode->setSize(200);
  435. // 外边距大小,默认为10
  436. $qrCode->setMargin(10);
  437. // 设置编码
  438. $qrCode->setEncoding('UTF-8');
  439. // 设置容错等级
  440. $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH());
  441. // 设置二维码颜色,默认为黑色
  442. $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
  443. // 设置二维码背景色,默认为白色
  444. $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
  445. // 设置二维码下方的文字
  446. switch ($level){
  447. case 1:
  448. $level_name='大码';
  449. break;
  450. case 2:
  451. $level_name='小码';
  452. break;
  453. case 3:
  454. $level_name='小码';
  455. break;
  456. }
  457. if ($level==2){
  458. $level_name=$level_name.'-'.$s;
  459. }
  460. $qrCode->setLabel($level_name.'-'.$num, 15, null, LabelAlignment::CENTER());
  461. ##### 二维码中的logo #####
  462. // $qrCode->setLogoPath('logo.jpg');
  463. // $qrCode->setLogoSize(100, 90);
  464. // $qrCode->setLogoWidth(100);
  465. // $qrCode->setLogoHeight(90);
  466. ##### 二维码中的logo / #####
  467. // 启用内置的验证读取器(默认情况下禁用)
  468. // $qrCode->setValidateResult(false);
  469. ########## 二维码三种显示方式 ##########
  470. // 二维码输出在浏览器上
  471. // header('Content-Type: ' . $qrCode->getContentType());
  472. // echo $qrCode->writeString();
  473. // 二维码存在本地
  474. Log::error(1);
  475. $path='public/code/'.$file;
  476. $path = public_path().'/code/'.$file;
  477. File::makeDirectory($path,$mode = 0777,true,true);
  478. $qrCode->writeFile('public/code/'.$file.'/'.$level_name.'.png');
  479. }
  480. protected function commands()
  481. {
  482. $this->load(__DIR__.'/Commands');
  483. require base_path('routes/console.php');
  484. }
  485. }