|
@@ -8,6 +8,8 @@
|
|
|
|
|
|
namespace App\Console\Commands\Channel;
|
|
|
|
|
|
+use App\Modules\Channel\Services\ReportToChannelUserAndOrderService;
|
|
|
+use GuzzleHttp\Client;
|
|
|
use Illuminate\Console\Command;
|
|
|
use DB;
|
|
|
|
|
@@ -34,20 +36,85 @@ class ReportUserAndOrderToChannel extends Command
|
|
|
*
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public function handle(){
|
|
|
+ const SUCCESS = 'success';
|
|
|
|
|
|
+ public function handle(){
|
|
|
+ $date = date('Y-m-d H:i:s',time()-3600);
|
|
|
+ $type = $this->option('type');
|
|
|
+ if($type == 'users'){
|
|
|
+ $this->reportUsers($date);
|
|
|
+ }
|
|
|
+ if($type == 'orders'){
|
|
|
+ $this->reportOrders($date);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private function reportOrders(){
|
|
|
|
|
|
+
|
|
|
+ private function reportOrders($date){
|
|
|
+ $result = ReportToChannelUserAndOrderService::getOrderErrorRecord($date);
|
|
|
+ if(!$result) return ;
|
|
|
+ $client = new Client(['timeout'=>5.0]);
|
|
|
+ foreach ($result as $item){
|
|
|
+ $distribution_channel_id = $item->distribution_channel_id;
|
|
|
+ $uid = $item->uid;
|
|
|
+ $price = $item->price;
|
|
|
+ $order_created_at = $item->order_created_at;
|
|
|
+
|
|
|
+ $link = ReportToChannelUserAndOrderService::getReportUrl($distribution_channel_id,ReportToChannelUserAndOrderService::$user_type);
|
|
|
+ try{
|
|
|
+ $result = $client->request('post',$link,['form_params'=>[
|
|
|
+ 'uid'=>$uid,
|
|
|
+ 'distribution_channel_id'=>$distribution_channel_id,
|
|
|
+ 'price'=>$price,
|
|
|
+ 'order_created_at'=>$order_created_at,
|
|
|
+ 'event'=>'order'
|
|
|
+ ]])->getBody()->getContents();
|
|
|
+ if($result && str_contains(strtolower($result),self::SUCCESS)){
|
|
|
+ ReportToChannelUserAndOrderService::updateOrderErrorRecord($item->id,['report_status'=>2]);
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ $error = 'result error ,'.$result;
|
|
|
+ }catch (\Exception $e){
|
|
|
+ $error = 'exception,'.$e->getMessage();
|
|
|
+ }
|
|
|
+ ReportToChannelUserAndOrderService::updateOrderErrorRecord($item->id,['report_status'=>1,'error_msg'=>$error]);
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private function reportUsers($date){
|
|
|
- $result = DB::table('report_to_channel_users')->where('created_at','>=',$date)
|
|
|
- ->where('report_status',0)
|
|
|
- ->select('id','uid','distribution_channel_id','register_ip','user_agent','user_created_at')->get();
|
|
|
- if(!$result)return ;
|
|
|
+ $result = ReportToChannelUserAndOrderService::getUserErrorRecord($date);
|
|
|
+ if(!$result) return ;
|
|
|
+ $client = new Client(['timeout'=>5.0]);
|
|
|
foreach ($result as $item){
|
|
|
+ $distribution_channel_id = $item->distribution_channel_id;
|
|
|
+ $uid = $item->uid;
|
|
|
+ $register_ip = $item->register_ip;
|
|
|
+ $user_agent = $item->user_agent;
|
|
|
+ $user_created_at = $item->user_created_at;
|
|
|
+
|
|
|
+ $link = ReportToChannelUserAndOrderService::getReportUrl($distribution_channel_id,ReportToChannelUserAndOrderService::$user_type);
|
|
|
+ try{
|
|
|
+ $result = $client->request('post',$link,['form_params'=>[
|
|
|
+ 'uid'=>$uid,
|
|
|
+ 'distribution_channel_id'=>$distribution_channel_id,
|
|
|
+ 'register_ip'=>$register_ip,
|
|
|
+ 'user_agent'=>$user_agent,
|
|
|
+ 'user_created_at'=>$user_created_at,
|
|
|
+ 'event'=>'user'
|
|
|
+ ]])->getBody()->getContents();
|
|
|
+ if($result && str_contains(strtolower($result),self::SUCCESS)){
|
|
|
+ ReportToChannelUserAndOrderService::updateUserErrorRecord($item->id,['report_status'=>2]);
|
|
|
+
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ $error = 'result error ,'.$result;
|
|
|
+ }catch (\Exception $e){
|
|
|
+ $error = 'exception,'.$e->getMessage();
|
|
|
+ }
|
|
|
+ ReportToChannelUserAndOrderService::updateUserErrorRecord($item->id,['report_status'=>1,'error_msg'=>$error]);
|
|
|
+
|
|
|
|
|
|
}
|
|
|
}
|