123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- /**
- * Created by PhpStorm.
- * User: z-yang
- * Date: 2019/7/27
- * Time: 18:01
- */
- namespace App\Modules\User\Services;
- use App\Modules\User\Models\UserMonthOrder;
- use App\Modules\User\Models\UserMonthSign;
- use GuzzleHttp\Client;
- class UserMonthService
- {
- public static function createSign(int $uid, int $plan_id, string $change_type,string $openid,string $type)
- {
- $model = new UserMonthSign();
- $info = $model->where('uid', $uid)->where('plan_id', $plan_id)->first();
- if ($info) {
- $info->change_type = $change_type;
- $info->save();
- } else {
- $model->uid = $uid;
- $model->plan_id = $plan_id;
- $model->change_type = $change_type;
- $model->openid = $openid;
- $model->type = $type;
- $model->save();
- }
- return;
- }
- public static function isSignMonth($openid){
- $model = new UserMonthSign();
- return $model->where('openid',$openid)->where('change_type','ADD')->select('id')->first();
- }
- public static function getLastOrder(int $uid){
- $model = new UserMonthOrder();
- return $model->where('uid',$uid)->orderBy('id','desc')->first();
- }
- public static function createLOrder(int $uid, int $plan_id, int $total_fee, string $trade_no,string $out_trade_no,string $type)
- {
- $model = new UserMonthOrder();
- $model->uid = $uid;
- $model->plan_id = $plan_id;
- $model->total_fee = $total_fee;
- $model->trade_no = $trade_no;
- $model->out_trade_no = $out_trade_no;
- $model->type = $type;
- $model->save();
- return;
- }
- public static function getOrderByOrder($trade_no,$out_trade_no){
- $model = new UserMonthOrder();
- $info = $model->where('trade_no',$trade_no)->first();
- return $info;
- }
- public static function getOrderAndSignStatusByUid($uid){
- $result = UserMonthOrder::join('user_month_sign','user_month_sign.uid','=','user_month_order.uid')
- ->select('user_month_order.type','user_month_sign.change_type')
- ->where('user_month_order.uid',$uid)
- ->where('user_month_sign.change_type','DELETE')
- ->get();
- if($result->isEmpty()) return [];
- $return_result = [];
- foreach ($result as $item){
- $return_result[] = $item->type;
- }
- return $return_result;
- }
- public static function checkOrderStatus(int $user_id,int $plan_id,string $app_id,string $key,string $app_secret){
- $pay_year = date('Y');
- $pay_month = date('m');
- $sign = strtoupper(_sign(compact('app_id','app_secret','user_id','plan_id','pay_year','pay_month'),$key.$key));
- $client = new Client();
- $url = 'http://pap.manyuedu.org/checkpay.php?';
- $url .= http_build_query(compact('user_id','app_secret','app_id','plan_id','pay_year','pay_month','sign'));
- $result = $client->request('post',$url)->getBody()->getContents();
- return json_decode($result,true);
- }
- public static function isMonthOrderUser($uid){
- $info = UserMonthOrder::where('uid',$uid)
- ->where('type','MONTH')
- ->orderBy('id','desc')
- ->select('created_at')
- ->first();
- if($info && strtotime($info->created_at)+365*86400 >time() ){
- return true;
- }
- return false;
- }
- }
|