PhOrders.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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],'操作成功');
  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. $result = $app->order->unify([
  57. 'body' => '预付款',
  58. 'out_trade_no' => $info['sn'],
  59. 'total_fee' => $info['money']*100,
  60. 'notify_url' => $notify, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  61. 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
  62. 'openid' => $openid,
  63. ]);
  64. if($result['return_code'] != 'SUCCESS' || $result['result_code'] != 'SUCCESS'){
  65. \exception(json_encode($result));
  66. }
  67. $jssdk = $app->jssdk;
  68. $ret = $jssdk->sdkConfig($result['prepay_id']); // 返回数组
  69. trace($ret);
  70. }catch (\Exception $e){
  71. trace($e->getMessage());
  72. HelpHander::error('获取参数失败');
  73. }
  74. HelpHander::success($ret,'成功');
  75. }
  76. }