Notify.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\mainapp\controller;
  3. use think\facade\Session;
  4. use think\facade\Log;
  5. use app\mainapp\BaseController;
  6. use app\common\model\User as UserModel;
  7. use app\common\model\MallOrder as MallOrderModel;
  8. use app\common\model\UserIntegral as UserIntegralModel;
  9. use echowx\WxPay;
  10. class Notify extends BaseController
  11. {
  12. // 订单处理
  13. public function setOrder($ordersn, $payinfo)
  14. {
  15. $snfirst = substr($ordersn , 0 , 1);
  16. if ($snfirst==="M"){
  17. // 积分商城订单
  18. $order = MallOrderModel::where('ordersn','=',$ordersn)->findOrEmpty();
  19. if ($order->isEmpty()){
  20. return false;
  21. }elseif ($order->status>2){
  22. return true;
  23. }
  24. $order->save([
  25. 'status' => 3,
  26. 'payinfo' => $payinfo
  27. ]);
  28. return true;
  29. }elseif($snfirst==="R") {
  30. // 积分充值
  31. $order = UserIntegralModel::where('remark','=',$ordersn)->findOrEmpty();
  32. if ($order->isEmpty()){
  33. return false;
  34. }elseif ($order->itype!=2 || $order->status!=1){
  35. return true;
  36. }
  37. $order->save([
  38. 'status' => 2
  39. ]);
  40. $user = UserModel::findOrEmpty($order->userid);
  41. $integral = intval($user->integral) + $order->intvalue;
  42. $inttotal = intval($user->inttotal) + $order->intvalue;
  43. $user->save([
  44. 'integral' => $integral,
  45. 'inttotal' => $inttotal
  46. ]);
  47. return true;
  48. }else{
  49. return false;
  50. }
  51. }
  52. //微信支付
  53. public function orderWechat()
  54. {
  55. $wxpay = new WxPay();
  56. $verify = $wxpay->notify();
  57. if ($verify['status']!=1){
  58. Log::pay($verify['data']);
  59. }else{
  60. $ordersn = $verify['data']['out_trade_no'];
  61. $log = $ordersn.':::::::'.mb_convert_encoding(json_encode(gbk2utf8($verify['data'])), 'UTF-8', 'auto');
  62. Log::pay($log);
  63. if ($verify['data']['return_code'] == 'SUCCESS' && $verify['data']['result_code'] == 'SUCCESS') {
  64. $payinfo = array(
  65. 'cash_fee' => $verify['data']['cash_fee'],
  66. 'openid' => $verify['data']['openid'],
  67. 'out_trade_no' => $verify['data']['out_trade_no'],
  68. 'transaction_id' => $verify['data']['transaction_id']
  69. );
  70. $result = $this->setOrder($ordersn, $payinfo);
  71. if ($result == true){
  72. $wxpay->reply_notify();
  73. }
  74. }
  75. }
  76. }
  77. }