UserMonthService.php 2.3 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)
  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 = _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. $client->request('post',$url,['form_params'=>
  61. compact('user_id','app_secret','app_id','plan_id','pay_year','pay_month','sign')])
  62. ->getBody()->getContents();
  63. }
  64. }