PhOrders.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace app\api\controller\h5;
  3. use app\hander\HelpHander;
  4. use EasyWeChat\Factory;
  5. use think\Controller;
  6. use think\Db;
  7. use think\Exception;
  8. class PhOrders extends Base
  9. {
  10. //订单列表
  11. public function orderList(){
  12. $page = input('page',1);
  13. $size = input('size',10);
  14. $status = input('status/d',-1);
  15. $model = new \app\common\model\PhOrders();
  16. $res = $model->orderList($this->orgId,$status,$page,$size,$this->userId);
  17. HelpHander::success($res,'操作成功');
  18. }
  19. //订单详情
  20. public function detail(){
  21. $id = input('id/d','');
  22. $model = new \app\common\model\PhOrders();
  23. $ret = $model->getInfo($id);
  24. HelpHander::success($ret,'操作成功');
  25. }
  26. public function getWorkerAll(){
  27. $model = new \app\common\model\Worker();
  28. $ret = $model->getAllByOrg($this->orgId);
  29. HelpHander::success($ret,'成功');
  30. }
  31. // 存入预付款
  32. public function payOrder(){
  33. $orderId = input('orderId/d',0);
  34. $money = input('money/f',0);
  35. if($money <= 0){
  36. HelpHander::error('输入金额错误');
  37. }
  38. $payId = model('PhOrderPay')->addSave($this->userId,$this->orgId,$orderId,$money);
  39. if(!$payId){
  40. HelpHander::error(model('PhOrderPay')->getError());
  41. }
  42. HelpHander::success(['pay_id' => $payId>0?$payId:0],'操作成功');
  43. }
  44. // 根据支付id获取支付参数
  45. public function pay(){
  46. $payId = input('payId/d',0);
  47. $info = Db::name('ph_order_pay')->where('id',$payId)->where('status',0)->find();
  48. if(!$info){
  49. HelpHander::error('订单不存在');
  50. }
  51. if ($this->orgId == 100){
  52. $config = config('app.wx_config_px');
  53. $notify = config("app.app_host").'/api/h5/notify/phOrderPx';
  54. }else{
  55. $config = config('app.wx_config');
  56. $notify = config("app.app_host").'/api/h5/notify/phorder';
  57. }
  58. try{
  59. $openid = Db::name('wxuser')->where('id',$this->userId)->where('type',1)->value('openid');
  60. $app = Factory::payment($config);
  61. $title = "预付款";
  62. if($info['bus_type'] == 1){
  63. $title = "服务费";
  64. }
  65. $result = $app->order->unify([
  66. 'body' => $title,
  67. 'out_trade_no' => $info['sn'],
  68. 'total_fee' => $info['money']*100,
  69. 'notify_url' => $notify, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  70. 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
  71. 'openid' => $openid,
  72. ]);
  73. if($result['return_code'] != 'SUCCESS' || $result['result_code'] != 'SUCCESS'){
  74. \exception(json_encode($result));
  75. }
  76. $jssdk = $app->jssdk;
  77. $ret = $jssdk->sdkConfig($result['prepay_id']); // 返回数组
  78. trace($ret);
  79. }catch (\Exception $e){
  80. trace($e->getMessage());
  81. HelpHander::error($e->getMessage());
  82. }
  83. HelpHander::success($ret,'成功');
  84. }
  85. public function pay2(){
  86. $payId = input('payId/d',0);
  87. $info = Db::name('ph_order_pay')->where('id',$payId)->where('status',0)->find();
  88. if(!$info){
  89. HelpHander::error('订单不存在');
  90. }
  91. if ($this->orgId == 100){
  92. $config = config('app.wx_mini_config_ph_px');
  93. $notify = config("app.app_host").'/api/h5/notify/phOrderPx2';
  94. }else{
  95. $config = config('app.wx_mini_config_ph');
  96. $notify = config("app.app_host").'/api/h5/notify/phorder2';
  97. }
  98. try{
  99. $openid = Db::name('wxuser')->where('id',$this->userId)->where('type',3)->value('openid');
  100. $app = Factory::payment($config);
  101. $title = "预付款";
  102. if($info['bus_type'] == 1){
  103. $title = "服务费";
  104. }
  105. $result = $app->order->unify([
  106. 'body' => $title,
  107. 'out_trade_no' => $info['sn'],
  108. 'total_fee' => $info['money']*100,
  109. 'notify_url' => $notify, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  110. 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
  111. 'openid' => $openid,
  112. ]);
  113. if($result['return_code'] != 'SUCCESS' || $result['result_code'] != 'SUCCESS'){
  114. \exception(json_encode($result));
  115. }
  116. $jssdk = $app->jssdk;
  117. $ret = $jssdk->sdkConfig($result['prepay_id']); // 返回数组
  118. $ret['sn'] = $info['sn'];
  119. $ret['money'] = $info['money'];
  120. trace($ret);
  121. }catch (\Exception $e){
  122. trace($e->getMessage());
  123. HelpHander::error($e->getMessage());
  124. }
  125. HelpHander::success($ret,'成功');
  126. }
  127. public function temps(){
  128. $temps = [
  129. // 'COP22f3d6KAFhCHpZQQC9xx8y4GJcxunfbjfiHKlRAY',
  130. // 'j6ZzH3cgDUU57mKEpcJzVNa3VbwR0mrznuOmkBoPwd0',
  131. // 'wfDNG2rNhVcdOd5L3XHMT-mcbrwLAN8IUBBeCvpdTrw'
  132. ];
  133. $data = [
  134. 'tips' => '为更好地服务您,小程序需要在订单变化时向您发送消息',
  135. 'temps' => $temps
  136. ];
  137. HelpHander::success($data);
  138. }
  139. }