TipWithdraw.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Events\TipSend as TipSends;
  4. use App\Models\Agent\AgentOperationLog;
  5. use App\Http\Controllers\Admin\StoreController as Sc;
  6. use App\Models\Order;
  7. use App\Models\OrderW;
  8. use App\Models\Store;
  9. use App\Models\TipWithdraw as Tip;
  10. use App\Models\User;
  11. use App\Models\DwbsUser;
  12. use Carbon\Carbon;
  13. use Illuminate\Console\Command;
  14. use Illuminate\Support\Facades\Cache;
  15. use Illuminate\Support\Facades\Log;
  16. use Illuminate\Support\Facades\DB;
  17. use Overtrue\EasySms\EasySms;
  18. class TipWithdraw extends Command
  19. {
  20. /**
  21. * The name and signature of the console command.
  22. *
  23. * @var string
  24. */
  25. protected $signature = 'tip_withdraw';
  26. /**
  27. * The console command description.
  28. *
  29. * @var string
  30. */
  31. protected $description = '提醒提现';
  32. /**
  33. * Create a new command instance.
  34. *
  35. * @return void
  36. */
  37. public function __construct()
  38. {
  39. parent::__construct();
  40. }
  41. /**
  42. * Execute the console command.
  43. *
  44. * @return mixed
  45. */
  46. public function handle()
  47. {
  48. Log::info('提示提现发送短信');
  49. $operation=AgentOperationLog::query()->where('type',4)
  50. ->where('created_at','>=',Carbon::now()->subMinutes(2))->get();
  51. foreach($operation as $key=>$val){
  52. $store=Store::where('user_id',$val->user_id)->first();
  53. if($store){
  54. $total = Order::where('store_id',$store->id)->where('status','<','3')->where('is_pay',1)->whereIn('apply_cancel',[0,1,3])->count();
  55. Log::info($store);
  56. $store->delete();
  57. }else{
  58. $total = 0;
  59. }
  60. $sc=new Sc();
  61. $result=$sc->getAccount($val->user_id);
  62. $account=$result['pending_amount']+$result['available_amount'];
  63. Log::info('.............1............');
  64. if($account > 0 || $total > 0){
  65. Log::info('..........2...............');
  66. $tip=Tip::where('user_id',$val->user_id)->first();
  67. if(empty($tip)){
  68. Log::info('.............3............');
  69. DB::beginTransaction();
  70. Tip::create([
  71. 'user_id'=>$val->user_id,
  72. 'num'=>1,
  73. 'send_at'=>Carbon::now(),
  74. ]);
  75. $phone=DwbsUser::withTrashed()->where('id',$val->user_id)->value('mobile');
  76. $config=config('easysms');
  77. $easySms = new EasySms($config);
  78. $content="您的微店铺账号已被删除,请及时处理订单,并完成提现。点击链接进入微店铺 https://dllzff.cn/U1oTQeNj 如已处理请忽略。";
  79. Log::info('.........4................');
  80. try{
  81. $easySms->send($phone, ['content' =>$content ]);
  82. DB::commit();
  83. Log::info('短信发送成功');
  84. } catch (\Overtrue\EasySms\Exceptions\NoGatewayAvailableException $exception) {
  85. $message = $exception->getException('qcloud')->getMessage();
  86. DB::rollBack();
  87. Log::info($message);
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }