123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- namespace app\controller\api;
- use app\service\api\UserServiceFacade;
- use app\service\ConfServiceFacade;
- use laytp\controller\Api;
- use laytp\library\Random;
- use think\facade\Db;
- class Order extends Api
- {
- protected function _initialize()
- {
- $this->model = new \app\model\Order();
- }
- // 无需登录的接口,*表示全部
- public $noNeedLogin = [];
- public function create()
- {
- global $_GPC;
- $payPrice = 0;
- $post = $this->request->post();
- $linkId = $this->request->post('link_id',0);
- $mode = $this->request->post('mode','member');
- $type = $this->request->post('type',1);
- // $post['uniacid'] = $_GPC['uniacid'];
- $loginUserInfo = UserServiceFacade::getUserInfo();
- if($mode == 'direct'){
- if($type == 1){
- }else{
- $payPrice = ConfServiceFacade::get('system.plan.pic_price');
- }
- }else{
- if(!$linkId){
- return $this->error('请选择需要开通的会员卡');
- }
- // 获得信息
- $taskinfo = \app\model\Member::findOrEmpty($linkId)->toArray();
- if($taskinfo['price'] <= 0){
- return $this->error('金额需要大于0');
- }
- $payPrice = $taskinfo['price'];
- }
- //生成订单
- $ordernumber = Random::numeric(20);
- //拼接订单信息
- $post['uid'] = $loginUserInfo['id'];
- $post['pay_price'] = $payPrice;
- $post['order_number'] = $ordernumber;
- $post['uniacid'] = $_GPC['uniacid'];
- $post['pay_type'] ='wechat';
- Db::startTrans();
- try{
- $saveRes = $this->model->save($post);
- if (!$saveRes) throw new \Exception('保存基础信息失败');
- Db::commit();
- $post['id'] = $this->model->id;
- return $this->success('操作成功',$post);
- }catch (\Exception $e) {
- Db::rollback();
- return $this->error('数据库异常,操作失败');
- }
- }
- public function createSettle()
- {
- global $_GPC;
- $modelSettle = new \app\model\commission\Settle();
- $modelUser = new \app\model\commission\User();
- $payPrice = 0;
- $realName = $this->request->post('real_name','');
- $telnum = $this->request->post('telnum','');
- if(!$realName || !$telnum){
- return $this->error('请上传姓名或手机号');
- }
- // $post['uniacid'] = $_GPC['uniacid'];
- $loginUserInfo = UserServiceFacade::getUserInfo();
- // print_r($loginUserInfo);
- $payPrice = ConfServiceFacade::get('system.commission.commission_price');
- if(!$payPrice || $payPrice==0){
- return $this->error('订单金额错误');
- }
- $res = $modelUser::where('uid','=',$loginUserInfo['id'])->find();
- if(!empty($res) && $res['status'] == 1){
- return $this->error('已经入驻过');
- }
- //生成订单
- $ordernumber = Random::numeric(20);
- //拼接订单信息
- $post['uid'] = $loginUserInfo['id'];
- $post['pay_price'] = $payPrice;
- $post['order_number'] = $ordernumber;
- $post['uniacid'] = $_GPC['uniacid'];
- $post['real_name'] = $realName;
- $post['telnum'] = $telnum;
- $post['pay_type'] ='wechat';
- Db::startTrans();
- try{
- $saveRes = $modelSettle->save($post);
- if (!$saveRes) throw new \Exception('保存基础信息失败');
- Db::commit();
- $post['id'] = $modelSettle->id;
- return $this->success('操作成功',$post);
- }catch (\Exception $e) {
- Db::rollback();
- return $this->error('数据库异常,操作失败');
- }
- }
- public function detail()
- {
- global $_GPC;
- $order_id = $this->request->param('id');
- if(!$order_id){
- return $this->error('请上传订单编号');
- }
- $order_info = $this->model->where('id','=',$order_id)->find();
- if(!$order_info){
- return $this->error('无数据');
- }
- return $this->success('返回成功',$order_info);
- }
- public function detailSettle()
- {
- global $_GPC;
- $modelSettle = new \app\model\commission\Settle();
- $order_id = $this->request->param('id');
- if(!$order_id){
- return $this->error('请上传订单编号');
- }
- $order_info = $modelSettle->where('id','=',$order_id)->find();
- if(!$order_info){
- return $this->error('无数据');
- }
- return $this->success('返回成功',$order_info);
- }
- public function my(){
- global $_GPC;
- $order = ['id' => 'desc'];
- $loginUserInfo = UserServiceFacade::getUserInfo();
- $where = ['uid'=>$loginUserInfo['id'],'paid'=>1,'uniacid'=>$_GPC['uniacid']];
- $limit = $this->request->param('limit', 10);
- $data = $this->model->order($order)->where($where)->with('memberInfo')->paginate($limit)->toArray();
- if(!$data){
- return $this->error('数据获取失败',2);
- }
- return $this->success('数据获取成功', $data);
- }
- }
|