OrderLib.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. declare (strict_types=1);
  3. // +----------------------------------------------------------------------
  4. // | [ WE CAN DO IT MORE SIMPLE ]
  5. // +----------------------------------------------------------------------
  6. // | Copyright (c) 2018-2020 rights reserved.
  7. // +----------------------------------------------------------------------
  8. // | 支付结算
  9. // +----------------------------------------------------------------------
  10. // | Date: 2020-08-25 17:23
  11. // +----------------------------------------------------------------------
  12. namespace app\lib;
  13. use app\model\api\PayTrade;
  14. use app\model\api\Order;
  15. use app\model\api\ShowTemplateOrder;
  16. use app\model\api\UserShowTemplate;
  17. use app\model\api\OrderInfo;
  18. use app\model\api\User as UserModel;
  19. use app\model\api\UserDetail as UserDetailModel;
  20. use app\model\api\Sys as SysModel;
  21. use think\facade\Db;
  22. class OrderLib
  23. {
  24. /**
  25. * 支付反馈
  26. * @param $orderId
  27. * @return bool|string
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\DbException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. */
  32. public function orderPay($payOn,$payDataInfo="")
  33. {
  34. $payTradeData = (new PayTrade)->where('pay_no', $payOn)->find();
  35. if (empty($payTradeData)) {
  36. return false;
  37. }
  38. //已支付
  39. if ($payTradeData['status'] == 1) {
  40. return false;
  41. }
  42. $userData = (new UserModel)->where('uid', $payTradeData['uid'])->find();
  43. if(empty($userData)){
  44. return false;
  45. }
  46. //处理支付成功
  47. PayTrade::beginTrans();
  48. try {
  49. (new PayTrade)->where('id', $payTradeData['id'])->update(['status' => 1, 'pay_time' => time(),'pay_json' => $payDataInfo]);
  50. //购买模板
  51. if($payTradeData["type"]=="temp"){
  52. $tempOrderData = (new ShowTemplateOrder)->where("id",$payTradeData['o_id'])->find();
  53. if(empty($tempOrderData)){
  54. PayTrade::rollbackTrans();
  55. return false;
  56. }
  57. (new ShowTemplateOrder)->where("id",$payTradeData['o_id'])->update(['status' => 1, 'pay_time' => time()]);
  58. //验证并绑定当前模板
  59. (new UserShowTemplate)->userBindTemp($tempOrderData["show_template_id"],$tempOrderData['uid']);
  60. //添加消费记录
  61. if(in_array($payTradeData["pay_type"],["alipay","wxpay"])){
  62. // (new UserDetailModel)->consumeLog($payTradeData['uid'],$payTradeData["money"],"show_temp_buy","购买名片模板");
  63. }
  64. PayTrade::commitTrans();
  65. return true;
  66. }
  67. //商城订单
  68. if($payTradeData["type"]=="shop"){
  69. (new Order)->where("id",$payTradeData['o_id'])->update(['status' => 1, 'pay_time' => time()]);
  70. PayTrade::commitTrans();
  71. return true;
  72. }
  73. PayTrade::commitTrans();
  74. } catch (DbException $dbException) {
  75. PayTrade::rollbackTrans();
  76. return false;
  77. }
  78. //后台管理人员支付直接返回
  79. if($payTradeData["pay_type"]=="system"){
  80. return true;
  81. }
  82. return true;
  83. }
  84. }