Преглед на файлове

add report notify 增加回传通知

fly преди 4 години
родител
ревизия
5a4a05e8a1

+ 23 - 0
app/Http/Controllers/Common/ChargeFeedbackController.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Http\Controllers\Common;
+
+use App\Http\Controllers\Controller;
+use App\Http\Requests\ReportUserChargeRecordRequest;
+use App\Http\Requests\ReportUserRecordRequest;
+use App\Modules\Order\Services\OrderService;
+
+class ChargeFeedbackController extends Controller
+{
+    public function userBind(ReportUserRecordRequest $request)
+    {
+        (new OrderService)->saveReportUserRecord($request->all());
+        return response()->success();
+    }
+
+    public function notify(ReportUserChargeRecordRequest $request)
+    {
+        (new OrderService)->saveReportUserChargeRecord($request->all());
+        return response()->success();
+    }
+}

+ 23 - 0
app/Http/Requests/ReportUserChargeRecordRequest.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Http\Requests;
+
+class ReportUserChargeRecordRequest extends Request
+{
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array
+     */
+    public function rules()
+    {
+        return [
+            'order_no' => 'required|string|exists:orders,trade_no',
+            'uid' => 'required|integer|exists:users,id',
+            'status' => 'required|integer',
+            'content' => 'required|string',
+            'config_percent' => 'numeric',
+            'report_percent' => 'numeric',
+        ];
+    }
+}

+ 26 - 0
app/Http/Requests/ReportUserRecordRequest.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace App\Http\Requests;
+
+
+class ReportUserRecordRequest extends Request
+{
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array
+     */
+    public function rules()
+    {
+        return [
+            'uid' => 'required|integer|exists:users,id',
+            'adid' => 'required|string',
+            'platform' => 'required|string',
+            'is_qapp' => 'required|integer',
+            'link' => 'required_if:is_qapp,0|string',
+            'callback' => 'required_if:is_qapp,1|string',
+            'muid' => 'string',
+            'os' => 'string',
+        ];
+    }
+}

+ 119 - 1
app/Http/Requests/Request.php

@@ -2,9 +2,127 @@
 
 namespace App\Http\Requests;
 
+use Illuminate\Contracts\Validation\Validator;
 use Illuminate\Foundation\Http\FormRequest;
+use Illuminate\Http\Exceptions\HttpResponseException;
 
 abstract class Request extends FormRequest
 {
-    //
+    public function authorize()
+    {
+        return true;
+    }
+
+    public function failedValidation(Validator $validator)
+    {
+        throw (new HttpResponseException(response()->json([
+            'code' => -1,
+            'msg' => '请求错误',
+            'data' => $validator->errors()->first(),
+        ], 200)));
+    }
+
+    public function messages()
+    {
+        return [
+            'required' => '缺少参数:attribute',
+            'integer' => ':attribute 必须是整数类型',
+            'date' => ':attribute 必须是日期格式',
+            'max' => [
+                'numeric' => ':attribute不能超过 :max.',
+                'file' => '文件:attribute大小不能超过 :max kilobytes.',
+                'string' => '字符:attribute 不能超过 :max 长度.',
+                'array' => '数组:attribute 不能超过 :max 长度.',
+            ],
+            'accepted' => 'The :attribute must be accepted.',
+            'active_url' => ':attribute 是个无效链接.',
+            'after' => 'The :attribute must be a date after :date.',
+            'after_or_equal' => 'The :attribute must be a date after or equal to :date.',
+            'alpha' => 'The :attribute may only contain letters.',
+            'alpha_dash' => 'The :attribute may only contain letters, numbers, dashes and underscores.',
+            'alpha_num' => 'The :attribute may only contain letters and numbers.',
+            'array' => 'The :attribute must be an array.',
+            'before' => 'The :attribute must be a date before :date.',
+            'before_or_equal' => 'The :attribute must be a date before or equal to :date.',
+            'between' => 'The :attribute 必须处于 :min 和 :max 之间',
+            'boolean' => 'The :attribute field must be true or false.',
+            'confirmed' => 'The :attribute confirmation does not match.',
+            'date_equals' => 'The :attribute must be a date equal to :date.',
+            'date_format' => 'The :attribute does not match the format :format.',
+            'different' => 'The :attribute and :other must be different.',
+            'digits' => 'The :attribute must be :digits digits.',
+            'digits_between' => 'The :attribute must be between :min and :max digits.',
+            'dimensions' => 'The :attribute has invalid image dimensions.',
+            'distinct' => 'The :attribute field has a duplicate value.',
+            'email' => 'The :attribute must be a valid email address.',
+            'ends_with' => 'The :attribute must end with one of the following: :values',
+            'exists' => ':attribute 不存在.',
+            'file' => 'The :attribute must be a file.',
+            'filled' => 'The :attribute field must have a value.',
+            'gt' => [
+                'numeric' => 'The :attribute must be greater than :value.',
+                'file' => 'The :attribute must be greater than :value kilobytes.',
+                'string' => 'The :attribute must be greater than :value characters.',
+                'array' => 'The :attribute must have more than :value items.',
+            ],
+            'gte' => [
+                'numeric' => 'The :attribute must be greater than or equal :value.',
+                'file' => 'The :attribute must be greater than or equal :value kilobytes.',
+                'string' => 'The :attribute must be greater than or equal :value characters.',
+                'array' => 'The :attribute must have :value items or more.',
+            ],
+            'image' => 'The :attribute 必须是一张图片.',
+            'in' => '选项 :attribute 不在给定范围中.',
+            'in_array' => 'The :attribute field does not exist in :other.',
+            'ip' => 'The :attribute must be a valid IP address.',
+            'ipv4' => 'The :attribute must be a valid IPv4 address.',
+            'ipv6' => 'The :attribute must be a valid IPv6 address.',
+            'json' => 'The :attribute must be a valid JSON string.',
+            'lt' => [
+                'numeric' => 'The :attribute must be less than :value.',
+                'file' => 'The :attribute must be less than :value kilobytes.',
+                'string' => 'The :attribute must be less than :value characters.',
+                'array' => 'The :attribute must have less than :value items.',
+            ],
+            'lte' => [
+                'numeric' => 'The :attribute must be less than or equal :value.',
+                'file' => 'The :attribute must be less than or equal :value kilobytes.',
+                'string' => 'The :attribute must be less than or equal :value characters.',
+                'array' => 'The :attribute must not have more than :value items.',
+            ],
+            'mimes' => 'The :attribute must be a file of type: :values.',
+            'mimetypes' => 'The :attribute must be a file of type: :values.',
+            'min' => [
+                'numeric' => 'The :attribute must be at least :min.',
+                'file' => 'The :attribute must be at least :min kilobytes.',
+                'string' => 'The :attribute must be at least :min characters.',
+                'array' => 'The :attribute must have at least :min items.',
+            ],
+            'not_in' => 'The selected :attribute is invalid.',
+            'not_regex' => 'The :attribute format is invalid.',
+            'numeric' => 'The :attribute must be a number.',
+            'present' => 'The :attribute field must be present.',
+            'regex' => 'The :attribute format is invalid.',
+            'required_if' => 'The :attribute field is required when :other is :value.',
+            'required_unless' => 'The :attribute field is required unless :other is in :values.',
+            'required_with' => 'The :attribute field is required when :values is present.',
+            'required_with_all' => 'The :attribute field is required when :values are present.',
+            'required_without' => 'The :attribute field is required when :values is not present.',
+            'required_without_all' => 'The :attribute field is required when none of :values are present.',
+            'same' => 'The :attribute and :other must match.',
+            'size' => [
+                'numeric' => 'The :attribute must be :size.',
+                'file' => 'The :attribute must be :size kilobytes.',
+                'string' => 'The :attribute must be :size characters.',
+                'array' => 'The :attribute must contain :size items.',
+            ],
+            'starts_with' => 'The :attribute must start with one of the following: :values',
+            'string' => 'The :attribute must be a string.',
+            'timezone' => 'The :attribute must be a valid zone.',
+            'unique' => 'The :attribute has already been taken.',
+            'uploaded' => 'The :attribute failed to upload.',
+            'url' => 'The :attribute format is invalid.',
+            'uuid' => 'The :attribute must be a valid UUID.',
+        ];
+    }
 }

+ 11 - 0
app/Http/Routes/Common/CommonRoute.php

@@ -0,0 +1,11 @@
+<?php
+
+/**
+ * 公共接口路由
+ */
+Route::group(['domain' => env('WECHAT_DOMAIN'), 'namespace' => 'App\Http\Controllers\Common'], function () {
+    Route::group(['middleware' => 'ChargeFeedbackCheckSign'], function () {
+        Route::any('chargeFeedback', 'ChargeFeedbackController@notify');
+        Route::any('userBind', 'ChargeFeedbackController@userBind');
+    });
+});

+ 19 - 0
app/Modules/Order/Models/ReportUserBindRecord.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Modules\Order\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class ReportUserBindRecord extends Model
+{
+    protected  $table = 'report_user_bind_records';
+    protected  $fillable = [
+        'uid',
+        'adid',
+        'platform',
+        'link',
+        'muid',
+        'os',
+        'callback',
+    ];
+}

+ 18 - 0
app/Modules/Order/Models/ReportUserChargeRecord.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace App\Modules\Order\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class ReportUserChargeRecord extends Model
+{
+    protected  $table = 'report_user_charge_records';
+    protected  $fillable = [
+        'uid',
+        'order_no',
+        'status',
+        'content',
+        'config_percent',
+        'report_percent',
+    ];
+}

+ 104 - 87
app/Modules/Order/Services/OrderService.php

@@ -6,6 +6,8 @@ use App\Modules\Order\Models\ChannelOrderStatistic;
 use App\Modules\Order\Models\ChannelOrderStatisticDate;
 use App\Modules\Order\Models\ChannelSendOrderStatistic;
 use App\Modules\Order\Models\ChannelSendOrderStatisticDate;
+use App\Modules\Order\Models\ReportUserBindRecord;
+use App\Modules\Order\Models\ReportUserChargeRecord;
 use App\Modules\Trade\Models\Order;
 use App\Modules\User\Models\User;
 use DB;
@@ -19,35 +21,35 @@ class OrderService
     public function increaseSendOrderAmount(string $date, int $channel_id, int $send_order_id, float $amount, string $pay_time)
     {
         $date_statistic = ChannelSendOrderStatisticDate::where([
-                                                                   'date'          => $date,
-                                                                   'channel_id'    => $channel_id,
-                                                                   'send_order_id' => $send_order_id,
-                                                               ])->first();
+            'date'          => $date,
+            'channel_id'    => $channel_id,
+            'send_order_id' => $send_order_id,
+        ])->first();
         if ($date_statistic) {
             $date_statistic->amount += $amount;
             $date_statistic->save();
         } else {
             ChannelSendOrderStatisticDate::create([
-                                                      'date'          => $date,
-                                                      'channel_id'    => $channel_id,
-                                                      'send_order_id' => $send_order_id,
-                                                      'amount'        => $amount,
-                                                  ]);
+                'date'          => $date,
+                'channel_id'    => $channel_id,
+                'send_order_id' => $send_order_id,
+                'amount'        => $amount,
+            ]);
         }
         $statistic = ChannelSendOrderStatistic::where([
-                                                          'channel_id'    => $channel_id,
-                                                          'send_order_id' => $send_order_id,
-                                                      ])->first();
+            'channel_id'    => $channel_id,
+            'send_order_id' => $send_order_id,
+        ])->first();
         if ($statistic) {
             $statistic->amount += $amount;
             $statistic->save();
         } else {
             ChannelSendOrderStatistic::create([
-                                                  'channel_id'     => $channel_id,
-                                                  'send_order_id'  => $send_order_id,
-                                                  'first_pay_time' => $pay_time,
-                                                  'amount'         => $amount,
-                                              ]);
+                'channel_id'     => $channel_id,
+                'send_order_id'  => $send_order_id,
+                'first_pay_time' => $pay_time,
+                'amount'         => $amount,
+            ]);
         }
     }
 
@@ -57,35 +59,35 @@ class OrderService
     public function increaseUserSendOrderAmount(string $date, int $channel_id, int $send_order_id, float $amount, string $pay_time)
     {
         $date_statistic = ChannelSendOrderStatisticDate::where([
-                                                                   'date'          => $date,
-                                                                   'channel_id'    => $channel_id,
-                                                                   'send_order_id' => $send_order_id,
-                                                               ])->first();
+            'date'          => $date,
+            'channel_id'    => $channel_id,
+            'send_order_id' => $send_order_id,
+        ])->first();
         if ($date_statistic) {
             $date_statistic->user_amount += $amount;
             $date_statistic->save();
         } else {
             ChannelSendOrderStatisticDate::create([
-                                                      'date'          => $date,
-                                                      'channel_id'    => $channel_id,
-                                                      'send_order_id' => $send_order_id,
-                                                      'user_amount'   => $amount,
-                                                  ]);
+                'date'          => $date,
+                'channel_id'    => $channel_id,
+                'send_order_id' => $send_order_id,
+                'user_amount'   => $amount,
+            ]);
         }
         $statistic = ChannelSendOrderStatistic::where([
-                                                          'channel_id'    => $channel_id,
-                                                          'send_order_id' => $send_order_id,
-                                                      ])->first();
+            'channel_id'    => $channel_id,
+            'send_order_id' => $send_order_id,
+        ])->first();
         if ($statistic) {
             $statistic->user_amount += $amount;
             $statistic->save();
         } else {
             ChannelSendOrderStatistic::create([
-                                                  'channel_id'     => $channel_id,
-                                                  'send_order_id'  => $send_order_id,
-                                                  'first_pay_time' => $pay_time,
-                                                  'user_amount'    => $amount,
-                                              ]);
+                'channel_id'     => $channel_id,
+                'send_order_id'  => $send_order_id,
+                'first_pay_time' => $pay_time,
+                'user_amount'    => $amount,
+            ]);
         }
     }
 
@@ -95,18 +97,18 @@ class OrderService
     public function increaseChannelAmount(string $date, int $channel_id, float $amount)
     {
         $date_statistic = ChannelOrderStatisticDate::where([
-                                                               'date'       => $date,
-                                                               'channel_id' => $channel_id,
-                                                           ])->first();
+            'date'       => $date,
+            'channel_id' => $channel_id,
+        ])->first();
         if ($date_statistic) {
             $date_statistic->amount += $amount;
             $date_statistic->save();
         } else {
             ChannelOrderStatisticDate::create([
-                                                  'date'       => $date,
-                                                  'channel_id' => $channel_id,
-                                                  'amount'     => $amount,
-                                              ]);
+                'date'       => $date,
+                'channel_id' => $channel_id,
+                'amount'     => $amount,
+            ]);
         }
         $statistic = ChannelOrderStatistic::where('channel_id', $channel_id)->first();
         if ($statistic) {
@@ -114,9 +116,9 @@ class OrderService
             $statistic->save();
         } else {
             ChannelOrderStatistic::create([
-                                              'channel_id' => $channel_id,
-                                              'amount'     => $amount,
-                                          ]);
+                'channel_id' => $channel_id,
+                'amount'     => $amount,
+            ]);
         }
     }
 
@@ -126,10 +128,10 @@ class OrderService
     private function findOrders(string $date)
     {
         return Order::where([
-                                ['status', '=', 'PAID'],
-                                ['created_at', '>=', $date],
-                                ['created_at', '<=', $date . ' 23:59:59'],
-                            ])
+            ['status', '=', 'PAID'],
+            ['created_at', '>=', $date],
+            ['created_at', '<=', $date . ' 23:59:59'],
+        ])
             ->select('send_order_id', 'distribution_channel_id', 'created_at', 'uid', 'price')
             ->get();
     }
@@ -142,11 +144,11 @@ class OrderService
     public function getSendOrdersByDate(string $startTime, string $endTime): array
     {
         $result = Order::where([
-                                   ['created_at', '>=', $startTime],
-                                   ['created_at', '<=', $endTime],
-                                   ['send_order_id', '>', 0],
-//            ['status', '=', 'PAID'],
-                               ])->get();
+            ['created_at', '>=', $startTime],
+            ['created_at', '<=', $endTime],
+            ['send_order_id', '>', 0],
+            //            ['status', '=', 'PAID'],
+        ])->get();
 
         return $result ? $result->toArray() : [];
     }
@@ -165,17 +167,17 @@ class OrderService
     private function reCalcChannelOrderAmount(string $date, int $channel_id, float $amount)
     {
         ChannelOrderStatisticDate::updateOrCreate([
-                                                      'date'       => $date,
-                                                      'channel_id' => $channel_id,
-                                                  ], [
-                                                      'amount' => $amount,
-                                                  ]);
+            'date'       => $date,
+            'channel_id' => $channel_id,
+        ], [
+            'amount' => $amount,
+        ]);
         $amount = ChannelOrderStatisticDate::where('channel_id', $channel_id)->sum('amount');
         ChannelOrderStatistic::updateOrCreate([
-                                                  'channel_id' => $channel_id,
-                                              ], [
-                                                  'amount' => $amount,
-                                              ]);
+            'channel_id' => $channel_id,
+        ], [
+            'amount' => $amount,
+        ]);
     }
 
     /**
@@ -190,19 +192,19 @@ class OrderService
             $uids   = collect($item)->pluck('id')->all();
             $amount = $orders->whereIn('uid', $uids)->sum('price');
             ChannelSendOrderStatisticDate::updateOrCreate([
-                                                              'date'          => $date,
-                                                              'channel_id'    => $channel_id,
-                                                              'send_order_id' => $send_order_id,
-                                                          ], [
-                                                              'user_amount' => $amount,
-                                                          ]);
+                'date'          => $date,
+                'channel_id'    => $channel_id,
+                'send_order_id' => $send_order_id,
+            ], [
+                'user_amount' => $amount,
+            ]);
             $amount = ChannelSendOrderStatisticDate::where('send_order_id', $send_order_id)->sum('user_amount');
             ChannelSendOrderStatistic::updateOrCreate([
-                                                          'channel_id'    => $channel_id,
-                                                          'send_order_id' => $send_order_id,
-                                                      ], [
-                                                          'user_amount' => $amount,
-                                                      ]);
+                'channel_id'    => $channel_id,
+                'send_order_id' => $send_order_id,
+            ], [
+                'user_amount' => $amount,
+            ]);
         }
     }
 
@@ -215,21 +217,21 @@ class OrderService
         foreach ($send_order_users as $send_order_id => $item) {
             $amount = collect($item)->sum('price');
             ChannelSendOrderStatisticDate::updateOrCreate([
-                                                              'date'          => $date,
-                                                              'channel_id'    => $channel_id,
-                                                              'send_order_id' => $send_order_id,
-                                                          ], [
-                                                              'amount' => $amount,
-                                                          ]);
+                'date'          => $date,
+                'channel_id'    => $channel_id,
+                'send_order_id' => $send_order_id,
+            ], [
+                'amount' => $amount,
+            ]);
             $amount         = ChannelSendOrderStatisticDate::where('send_order_id', $send_order_id)->sum('amount');
             $first_pay_time = Order::where(['send_order_id' => $send_order_id, 'status' => 'PAID'])->min('created_at');
             ChannelSendOrderStatistic::updateOrCreate([
-                                                          'channel_id'    => $channel_id,
-                                                          'send_order_id' => $send_order_id,
-                                                      ], [
-                                                          'amount'         => $amount,
-                                                          'first_pay_time' => $first_pay_time,
-                                                      ]);
+                'channel_id'    => $channel_id,
+                'send_order_id' => $send_order_id,
+            ], [
+                'amount'         => $amount,
+                'first_pay_time' => $first_pay_time,
+            ]);
         }
     }
 
@@ -364,7 +366,7 @@ class OrderService
      * @param int $first_pay_type 首充类型 -1全部 0非首充  1首充
      * @return array
      */
-    public function getSendOrderPayUserCountByHour($start, $end, $hour, $first_pay_type =-1): array
+    public function getSendOrderPayUserCountByHour($start, $end, $hour, $first_pay_type = -1): array
     {
         $order  = new Order();
         $result = $order->getSendOrderPayUserCountByHour($start, $end, $hour, $first_pay_type);
@@ -379,11 +381,26 @@ class OrderService
      * @param int $first_pay_type 首充类型 -1全部 0非首充  1首充
      * @return array
      */
-    public function getSendOrderPayUserCountByIdAndHour($send_order_id, $end, $hour, $first_pay_type =-1): array
+    public function getSendOrderPayUserCountByIdAndHour($send_order_id, $end, $hour, $first_pay_type = -1): array
     {
         $order  = new Order();
         $result = $order->getSendOrderPayUserCountByIdAndHour($send_order_id, $end, $hour, $first_pay_type);
         return $result;
     }
     #endregion
+
+    public function saveReportUserChargeRecord(array $data)
+    {
+        ReportUserChargeRecord::updateOrCreate([
+            'order_no' => $data['order_no'],
+            'uid' => $data['uid'],
+        ], $data);
+    }
+
+    public function saveReportUserRecord(array $data)
+    {
+        ReportUserBindRecord::updateOrCreate([
+            'uid' => $data['uid'],
+        ], $data);
+    }
 }