PhOrders.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 = config('app.wx_config');
  52. $notify = config("app.app_host").'/api/h5/notify/phorder';
  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('获取参数失败');
  77. }
  78. HelpHander::success($ret,'成功');
  79. }
  80. }