Order.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace app\controller\api;
  3. use app\service\api\UserServiceFacade;
  4. use app\service\ConfServiceFacade;
  5. use laytp\controller\Api;
  6. use laytp\library\Random;
  7. use think\facade\Db;
  8. class Order extends Api
  9. {
  10. protected function _initialize()
  11. {
  12. $this->model = new \app\model\Order();
  13. }
  14. // 无需登录的接口,*表示全部
  15. public $noNeedLogin = [];
  16. public function create()
  17. {
  18. global $_GPC;
  19. $payPrice = 0;
  20. $post = $this->request->post();
  21. $linkId = $this->request->post('link_id',0);
  22. $mode = $this->request->post('mode','member');
  23. $type = $this->request->post('type',1);
  24. // $post['uniacid'] = $_GPC['uniacid'];
  25. $loginUserInfo = UserServiceFacade::getUserInfo();
  26. if($mode == 'direct'){
  27. if($type == 1){
  28. }else{
  29. $payPrice = ConfServiceFacade::get('system.plan.pic_price');
  30. }
  31. }else{
  32. if(!$linkId){
  33. return $this->error('请选择需要开通的会员卡');
  34. }
  35. // 获得信息
  36. $taskinfo = \app\model\Member::findOrEmpty($linkId)->toArray();
  37. if($taskinfo['price'] <= 0){
  38. return $this->error('金额需要大于0');
  39. }
  40. $payPrice = $taskinfo['price'];
  41. }
  42. //生成订单
  43. $ordernumber = Random::numeric(20);
  44. //拼接订单信息
  45. $post['uid'] = $loginUserInfo['id'];
  46. $post['pay_price'] = $payPrice;
  47. $post['order_number'] = $ordernumber;
  48. $post['uniacid'] = $_GPC['uniacid'];
  49. $post['pay_type'] ='wechat';
  50. Db::startTrans();
  51. try{
  52. $saveRes = $this->model->save($post);
  53. if (!$saveRes) throw new \Exception('保存基础信息失败');
  54. Db::commit();
  55. $post['id'] = $this->model->id;
  56. return $this->success('操作成功',$post);
  57. }catch (\Exception $e) {
  58. Db::rollback();
  59. return $this->error('数据库异常,操作失败');
  60. }
  61. }
  62. public function createSettle()
  63. {
  64. global $_GPC;
  65. $modelSettle = new \app\model\commission\Settle();
  66. $modelUser = new \app\model\commission\User();
  67. $payPrice = 0;
  68. $realName = $this->request->post('real_name','');
  69. $telnum = $this->request->post('telnum','');
  70. if(!$realName || !$telnum){
  71. return $this->error('请上传姓名或手机号');
  72. }
  73. // $post['uniacid'] = $_GPC['uniacid'];
  74. $loginUserInfo = UserServiceFacade::getUserInfo();
  75. // print_r($loginUserInfo);
  76. $payPrice = ConfServiceFacade::get('system.commission.commission_price');
  77. if(!$payPrice || $payPrice==0){
  78. return $this->error('订单金额错误');
  79. }
  80. $res = $modelUser::where('uid','=',$loginUserInfo['id'])->find();
  81. if(!empty($res) && $res['status'] == 1){
  82. return $this->error('已经入驻过');
  83. }
  84. //生成订单
  85. $ordernumber = Random::numeric(20);
  86. //拼接订单信息
  87. $post['uid'] = $loginUserInfo['id'];
  88. $post['pay_price'] = $payPrice;
  89. $post['order_number'] = $ordernumber;
  90. $post['uniacid'] = $_GPC['uniacid'];
  91. $post['real_name'] = $realName;
  92. $post['telnum'] = $telnum;
  93. $post['pay_type'] ='wechat';
  94. Db::startTrans();
  95. try{
  96. $saveRes = $modelSettle->save($post);
  97. if (!$saveRes) throw new \Exception('保存基础信息失败');
  98. Db::commit();
  99. $post['id'] = $modelSettle->id;
  100. return $this->success('操作成功',$post);
  101. }catch (\Exception $e) {
  102. Db::rollback();
  103. return $this->error('数据库异常,操作失败');
  104. }
  105. }
  106. public function detail()
  107. {
  108. global $_GPC;
  109. $order_id = $this->request->param('id');
  110. if(!$order_id){
  111. return $this->error('请上传订单编号');
  112. }
  113. $order_info = $this->model->where('id','=',$order_id)->find();
  114. if(!$order_info){
  115. return $this->error('无数据');
  116. }
  117. return $this->success('返回成功',$order_info);
  118. }
  119. public function detailSettle()
  120. {
  121. global $_GPC;
  122. $modelSettle = new \app\model\commission\Settle();
  123. $order_id = $this->request->param('id');
  124. if(!$order_id){
  125. return $this->error('请上传订单编号');
  126. }
  127. $order_info = $modelSettle->where('id','=',$order_id)->find();
  128. if(!$order_info){
  129. return $this->error('无数据');
  130. }
  131. return $this->success('返回成功',$order_info);
  132. }
  133. public function my(){
  134. global $_GPC;
  135. $order = ['id' => 'desc'];
  136. $loginUserInfo = UserServiceFacade::getUserInfo();
  137. $where = ['uid'=>$loginUserInfo['id'],'paid'=>1,'uniacid'=>$_GPC['uniacid']];
  138. $limit = $this->request->param('limit', 10);
  139. $data = $this->model->order($order)->where($where)->with('memberInfo')->paginate($limit)->toArray();
  140. if(!$data){
  141. return $this->error('数据获取失败',2);
  142. }
  143. return $this->success('数据获取成功', $data);
  144. }
  145. }