PhOrders.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. $config = getPhConfig($this->orgId,1);
  52. $notify = getPhNotify($this->orgId,config("app.app_host"),1);
  53. try{
  54. $openid = Db::name('wxuser')->where('id',$this->userId)->where('type',1)->value('openid');
  55. $app = Factory::payment($config);
  56. $title = "预付款";
  57. if($info['bus_type'] == 1){
  58. $title = "服务费";
  59. }
  60. $result = $app->order->unify([
  61. 'body' => $title,
  62. 'out_trade_no' => $info['sn'],
  63. 'total_fee' => $info['money']*100,
  64. 'notify_url' => $notify, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  65. 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
  66. 'openid' => $openid,
  67. ]);
  68. if($result['return_code'] != 'SUCCESS' || $result['result_code'] != 'SUCCESS'){
  69. \exception(json_encode($result));
  70. }
  71. $jssdk = $app->jssdk;
  72. $ret = $jssdk->sdkConfig($result['prepay_id']); // 返回数组
  73. trace($ret);
  74. }catch (\Exception $e){
  75. trace($e->getMessage());
  76. HelpHander::error($e->getMessage());
  77. }
  78. HelpHander::success($ret,'成功');
  79. }
  80. public function pay2(){
  81. $payId = input('payId/d',0);
  82. $info = Db::name('ph_order_pay')->where('id',$payId)->where('status',0)->find();
  83. if(!$info){
  84. HelpHander::error('订单不存在');
  85. }
  86. $config = getPhConfig($this->orgId,2);
  87. $notify = getPhNotify($this->orgId,config("app.app_host"),2);
  88. try{
  89. $openid = Db::name('wxuser')->where('id',$this->userId)->where('type',3)->value('openid');
  90. $app = Factory::payment($config);
  91. $title = "预付款";
  92. if($info['bus_type'] == 1){
  93. $title = "服务费";
  94. }
  95. $result = $app->order->unify([
  96. 'body' => $title,
  97. 'out_trade_no' => $info['sn'],
  98. 'total_fee' => $info['money']*100,
  99. 'notify_url' => $notify, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  100. 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
  101. 'openid' => $openid,
  102. ]);
  103. if($result['return_code'] != 'SUCCESS' || $result['result_code'] != 'SUCCESS'){
  104. \exception(json_encode($result));
  105. }
  106. $jssdk = $app->jssdk;
  107. $ret = $jssdk->sdkConfig($result['prepay_id']); // 返回数组
  108. $ret['sn'] = $info['sn'];
  109. $ret['money'] = $info['money'];
  110. trace($ret);
  111. }catch (\Exception $e){
  112. trace($e->getMessage());
  113. HelpHander::error($e->getMessage());
  114. }
  115. HelpHander::success($ret,'成功');
  116. }
  117. public function temps(){
  118. $temps = [
  119. // 'COP22f3d6KAFhCHpZQQC9xx8y4GJcxunfbjfiHKlRAY',
  120. // 'j6ZzH3cgDUU57mKEpcJzVNa3VbwR0mrznuOmkBoPwd0',
  121. // 'wfDNG2rNhVcdOd5L3XHMT-mcbrwLAN8IUBBeCvpdTrw'
  122. ];
  123. $data = [
  124. 'tips' => '为更好地服务您,小程序需要在订单变化时向您发送消息',
  125. 'temps' => $temps
  126. ];
  127. HelpHander::success($data);
  128. }
  129. }