UserMonthService.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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,string $type)
  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->type = $type;
  27. $model->save();
  28. }
  29. return;
  30. }
  31. public static function isSignMonth($openid){
  32. $model = new UserMonthSign();
  33. return $model->where('openid',$openid)->where('change_type','ADD')->select('id')->first();
  34. }
  35. public static function getLastOrder(int $uid){
  36. $model = new UserMonthOrder();
  37. return $model->where('uid',$uid)->orderBy('id','desc')->first();
  38. }
  39. public static function createLOrder(int $uid, int $plan_id, int $total_fee, string $trade_no,string $out_trade_no,string $type)
  40. {
  41. $model = new UserMonthOrder();
  42. $model->uid = $uid;
  43. $model->plan_id = $plan_id;
  44. $model->total_fee = $total_fee;
  45. $model->trade_no = $trade_no;
  46. $model->out_trade_no = $out_trade_no;
  47. $model->type = $type;
  48. $model->save();
  49. return;
  50. }
  51. public static function getOrderByOrder($trade_no,$out_trade_no){
  52. $model = new UserMonthOrder();
  53. $info = $model->where('trade_no',$trade_no)->first();
  54. return $info;
  55. }
  56. public static function checkOrderStatus(int $user_id,int $plan_id,string $app_id,string $key,string $app_secret){
  57. $pay_year = date('Y');
  58. $pay_month = date('m');
  59. $sign = strtoupper(_sign(compact('app_id','app_secret','user_id','plan_id','pay_year','pay_month'),$key.$key));
  60. $client = new Client();
  61. $url = 'http://pap.manyuedu.org/checkpay.php?';
  62. $url .= http_build_query(compact('user_id','app_secret','app_id','plan_id','pay_year','pay_month','sign'));
  63. $result = $client->request('post',$url)->getBody()->getContents();
  64. return json_decode($result,true);
  65. }
  66. }