UserMonthService.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: z-yang
  5. * Date: 2019/7/27
  6. * Time: 18:01
  7. */
  8. namespace App\Modules\User\Services;
  9. use App\Modules\User\Models\UserMonthOrder;
  10. use App\Modules\User\Models\UserMonthSign;
  11. use GuzzleHttp\Client;
  12. class UserMonthService
  13. {
  14. public static function createSign(int $uid, int $plan_id, string $change_type,string $openid)
  15. {
  16. $model = new UserMonthSign();
  17. $info = $model->where('uid', $uid)->where('plan_id', $plan_id)->first();
  18. if ($info) {
  19. $info->change_type = $change_type;
  20. $info->save();
  21. } else {
  22. $model->uid = $uid;
  23. $model->plan_id = $plan_id;
  24. $model->change_type = $change_type;
  25. $model->openid = $openid;
  26. $model->save();
  27. }
  28. return;
  29. }
  30. public static function isSignMonth($openid){
  31. $model = new UserMonthSign();
  32. return $model->where('openid',$openid)->where('change_type','ADD')->select('id')->first();
  33. }
  34. public static function getLastOrder(int $uid){
  35. $model = new UserMonthOrder();
  36. return $model->where('uid',$uid)->orderBy('id','desc')->first();
  37. }
  38. public static function createLOrder(int $uid, int $plan_id, int $total_fee, string $trade_no,string $out_trade_no)
  39. {
  40. $model = new UserMonthOrder();
  41. $model->uid = $uid;
  42. $model->plan_id = $plan_id;
  43. $model->total_fee = $total_fee;
  44. $model->trade_no = $trade_no;
  45. $model->out_trade_no = $out_trade_no;
  46. $model->save();
  47. return;
  48. }
  49. public static function getOrderByOrder($trade_no,$out_trade_no){
  50. $model = new UserMonthOrder();
  51. $info = $model->where('trade_no',$trade_no)->first();
  52. return $info;
  53. }
  54. public static function checkOrderStatus(int $user_id,int $plan_id,string $app_id,string $key,string $app_secret){
  55. $pay_year = date('Y');
  56. $pay_month = date('m');
  57. $sign = strtoupper(_sign(compact('app_id','app_secret','user_id','plan_id','pay_year','pay_month'),$key.$key));
  58. $client = new Client();
  59. $url = 'http://pap.manyuedu.org/checkpay.php?';
  60. $url .= http_build_query(compact('user_id','app_secret','app_id','plan_id','pay_year','pay_month','sign'));
  61. $result = $client->request('post',$url)->getBody()->getContents();
  62. return json_decode($result,true);
  63. }
  64. }