Browse Source

商家端

lizhen_gitee 1 năm trước cách đây
mục cha
commit
3191eed2a1

+ 378 - 0
application/api/controller/company/Order.php

@@ -0,0 +1,378 @@
+<?php
+
+namespace app\api\controller\company;
+
+use app\common\controller\Apic;
+use think\Db;
+
+use alipaysdkphpallmaster\aop\AopClient;
+use alipaysdkphpallmaster\aop\request\AlipayTradePayRequest;
+/**
+ * 订单管理
+ */
+class Order extends Apic
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = '*';
+
+    public function _initialize()
+    {
+        parent::_initialize();
+    }
+
+    //
+    public function lists(){
+        $keyword = input('keyword','');
+        $status  = input('status','all');
+
+        $where = [
+            'company_id' => $this->auth->id,
+        ];
+        if($status !== 'all'){
+            $where['status'] = $status;
+        }
+        if($status == 20){ //待还车
+            $where['status'] = 20;
+            $where['endtime'] = ['gt',time()];
+        }
+        if($status == 200){ //逾期
+            $where['status'] = 20;
+            $where['endtime'] = ['elt',time()];
+        }
+        if($status == 30){
+            $where['status'] = ['IN',[-1,-2,30]];
+        }
+        if(!empty($keyword))
+        {
+            $where['user_truename|user_mobile|orderno'] = ['LIKE','%'.$keyword.'%'];
+        }
+        $list = Db::name('order')->where($where)->order('id desc')->autopage()->select();
+
+        $list = list_domain_image($list,['car_image','idcard_images','driver_images','get_yibiao_images','get_carvideo','back_yibiao_images','back_carvideo']);
+
+        foreach($list as $key => &$val){
+            $val['status_text'] = $this->status_text($val['status'],$val['endtime']);
+
+            if($val['status'] == 20 && time() >= $val['endtime']){
+                $val['status'] = 200; //強制改掉
+            }
+
+            //追加取消
+            $val['cancel_info'] = (object)[];
+            if($val['status'] == -1 || $val['status'] == -2){
+                //取消订单追加取消原因
+                $val['cancel_info'] = Db::name('order_cancel')->where('order_id',$val['id'])->find();
+            }
+
+            //追加评价
+            $val['comment_info'] = (object)[];
+            if($val['status'] == 30){
+                //完成订单追加评价
+                $comment_info = Db::name('order_comment')->where('order_id',$val['id'])->find();
+                if($comment_info){
+                    $val['comment_info'] = $comment_info;
+                }
+            }
+        }
+        $this->success(1,$list);
+    }
+
+    //各个状态的订单数量
+    public function status_each_number(){
+        //全部
+        $where = [
+            'company_id' => $this->auth->id,
+        ];
+        $all = Db::name('order')->where($where)->count();
+        //待取车
+        $where = [
+            'company_id' => $this->auth->id,
+            'status' => 10
+        ];
+        $daiquche = Db::name('order')->where($where)->count();
+
+        //待还车
+        $where = [
+            'company_id' => $this->auth->id,
+            'status' => 20,
+            'endtime' => ['gt',time()],
+        ];
+        $daihuanche = Db::name('order')->where($where)->count();
+
+        //逾期
+        $where = [
+            'company_id' => $this->auth->id,
+            'status' => 20,
+            'endtime' => ['elt',time()],
+        ];
+        $yuqi = Db::name('order')->where($where)->count();
+
+        //完成/取消
+        $where = [
+            'company_id' => $this->auth->id,
+            'status' => ['IN',[-1,-2,30]],
+        ];
+        $wancheng = Db::name('order')->where($where)->count();
+
+        $result = [
+            'all' => $all,
+            'daiquche'   => $daiquche,
+            'daihuanche' => $daihuanche,
+            'yuqi'       => $yuqi,
+            'wancheng'   => $wancheng,
+        ];
+
+        $this->success(1,$result);
+    }
+
+    //状态
+    private function status_text($status,$endtime){
+        $arr = [
+            -1 => '未付款被取消',
+            -2 => '已付款被取消',
+             0 => '待付款',
+            10 => '已付款',
+            20 => '已取车',
+            30 => '完成',
+        ];
+        $status_text =  isset($arr[$status]) ? $arr[$status] : $status;
+
+        //取走了车没还,时间却超过了还车时间
+        if($status == 20 && time() >= $endtime){
+            $status_text = '已逾期';
+        }
+
+        return $status_text;
+    }
+
+    //详情
+    public function info(){
+        $id = input('id',0);
+        $info = Db::name('order')->where('id',$id)->find();
+        $info = info_domain_image($info,['car_image','idcard_images','driver_images','get_yibiao_images','get_carvideo','back_yibiao_images','back_carvideo']);
+
+        $info['status_text'] = $this->status_text($info['status'],$info['endtime']);
+        if($info['status'] == 20 && time() >= $info['endtime']){
+            $info['status'] = 200; //強制改掉
+        }
+
+        //完成订单追加评价
+        $comment_info = Db::name('order_comment')->alias('c')
+            ->field('c.*,user.avatar,user.mobile')
+            ->join('user','c.user_id = user.id','LEFT')
+            ->where('c.order_id',$id)->find();
+        $comment_info = info_domain_image($comment_info,['avatar']);
+        if(!empty($comment_info)){
+            $comment_info['mobile'] = str_replace(substr($comment_info['mobile'],3,5),'****',$comment_info['mobile']);
+        }
+        $info['comment_info'] = $comment_info;
+
+        //取消订单追加取消原因
+        $info['cancel_info'] = Db::name('order_cancel')->where('order_id',$id)->find();
+
+        $this->success(1,$info);
+    }
+    //取消理由
+    public function cancel_config(){
+        $list = Db::name('company_cancel_config')->order('id asc')->select();
+        $this->success(1,$list);
+    }
+    //取消
+    public function cancel(){
+        $id = input('id',0);
+        $reason = input('reason','');
+
+        Db::startTrans();
+        $info = Db::name('order')->where('id',$id)->where('company_id',$this->auth->id)->lock(true)->find();
+        if($info['status'] == -2){
+            Db::rollback();
+            $this->error('当前订单已经申请取消,已付款订单审核后可退款');
+        }
+        if($info['status'] != 0 && $info['status'] != 10){
+            Db::rollback();
+            $this->error('当前订单状态不能取消');
+        }
+
+        //未付款取消
+        if($info['status'] == 0){
+            $rs = Db::name('order')->where('id',$id)->update(['status'=>-1]);
+        }
+
+        //已付款取消
+        if($info['status'] == 10){
+            $rs = Db::name('order')->where('id',$id)->update(['status'=>-2]);
+            //扣除车行收益
+            //从计划任务里走
+        }
+
+        if($rs === false){
+            Db::rollback();
+            $this->error('申请取消失败');
+        }
+
+        $data = [
+            'user_id'  => $info['user_id'],
+            'company_id'  => $info['company_id'],
+            'order_id' => $info['id'],
+            'reason'   => '商家取消:'.$reason,
+            'refund_price' => 0,
+            'type' => $info['status'],               //分类:0=未付款,10=已付款
+            'createtime' => time(),
+            'status' => $info['status'] == 0 ? 2 : 0, //状态:0=未处理,1=已处理,2=无需处理
+            'from' => 2,  //取消方:1=用户取消,2=商户取消
+        ];
+
+        $rs_cancle = Db::name('order_cancel')->insertGetId($data);
+        if(!$rs_cancle){
+            Db::rollback();
+            $this->error('申请取消失败');
+        }
+
+        //解除汽车占用
+        $rs_car = Db::name('car')->where('id',$info['car_id'])->update(['status'=>1]);
+        if(!$rs_car){
+            Db::rollback();
+            $this->error('申请取消失败');
+        }
+
+        Db::commit();
+        $this->success('取消成功');
+
+    }
+    //确认取车
+    public function get_car(){
+        $id = input('id',0);
+
+        Db::startTrans();
+        $info = Db::name('order')->where('id',$id)->where('company_id',$this->auth->id)->lock(true)->find();
+        if($info['status'] != 10){
+            Db::rollback();
+            $this->error('当前订单状态不能取车');
+        }
+
+        //
+        $data = [
+            'idcard_images' => input('idcard_images',''),
+            'driver_images' => input('driver_images',''),
+            'get_yibiao_images' => input('get_yibiao_images',''),
+            'get_carvideo'  => input('get_carvideo',''),
+            'status' => 20,
+            'getcartime' => time(),
+        ];
+        Db::name('order')->where('id',$id)->update($data);
+        Db::commit();
+
+        $this->success('取车完成');
+    }
+    //还车车伤确认,配置
+    public function back_config(){
+        $list = Db::name('order_back_config')->order('id asc')->select();
+        $this->success(1,$list);
+    }
+    //还车
+    public function back_car(){
+        $id = input('id',0);
+
+        Db::startTrans();
+        $info = Db::name('order')->where('id',$id)->where('company_id',$this->auth->id)->lock(true)->find();
+        if($info['status'] != 20){
+            Db::rollback();
+            $this->error('当前订单状态不能还车');
+        }
+
+        //还车
+        $data = [
+            'back_yibiao_images' => input('back_yibiao_images',''),
+            'back_carvideo' => input('back_carvideo',''),
+            'back_remark' => input('back_remark',''),
+            'status' => 30,
+            'backcartime' => input('backcartime',''),
+            'back_oilfee' => input('back_oilfee',0),
+            'back_damage' => input('back_damage',''),
+        ];
+        $rs_update = Db::name('order')->where('id',$id)->update($data);
+        if($rs_update === false){
+            Db::rollback();
+            $this->error('还车失败');
+        }
+
+        //汽车解除占用
+        $rs_car = Db::name('car')->where('id',$info['car_id'])->update(['status'=>1]);
+        if($rs_car === false){
+            Db::rollback();
+            $this->error('还车失败');
+        }
+
+        //给上一级用户赠送一张满100减100的券
+        $intro_user = Db::name('user')->where('id',$info['user_id'])->value('intro_uid');
+        if($intro_user){
+            //检查送过没有
+            $where = [
+                'user_id' => $info['user_id'],
+                'status'  => 30,
+                'id' => ['neq',$info['id']],
+            ];
+            $check = Db::name('order')->where($where)->find();
+            if(!$check){
+                //赠送一个
+                $only_coupon = Db::name('coupons')->where('id',1)->lock(true)->find();
+                if($only_coupon['stock'] > 1){
+                    //送到
+                    $data = [
+                        'user_id' => $intro_user,
+                        'company_id' => $only_coupon['company_id'],
+                        'enough' => $only_coupon['enough'],
+                        'amount' => $only_coupon['amount'],
+                        'type' => $only_coupon['type'],
+                        'coupons_id' => $only_coupon['id'],
+
+                        'createtime' => time(),
+                        'usetimestart' => $only_coupon['usetimestart'],
+                        'usetimeend' => $only_coupon['usetimeend'],
+                    ];
+                    $rs_user_coupon = Db::name('user_coupons')->insertGetId($data);
+                    //减库存
+                    $rs_only_coupon = Db::name('coupons')->where('id',1)->update(['stock'=>$only_coupon['stock']-1]);
+                    if(!$rs_user_coupon || $rs_only_coupon === false){
+                        Db::rollback();
+                        $this->error('还车失败了');
+                    }
+                }
+
+                //给上级奖励money
+                $intro_money = config('site.yaoqing_user_backcar_money');
+                if($intro_money > 0){
+                    $wallet = new \app\common\model\Wallet;
+                    $wallet_rs = $wallet->lockChangeAccountRemain($intro_user,'money',$intro_money,3,'邀请新用户下单('.$info['user_id'].')','order',$info['id']);
+                    if($wallet_rs['status'] === false){
+                        Db::rollback();
+                        $this->error($wallet_rs['msg']);
+                    }
+                }
+
+
+            }
+        }
+
+
+        Db::commit();
+
+        $this->success('还车完成');
+    }
+
+
+
+    //回复评价
+    public function comment_reply(){
+        $comment_id = input('comment_id',0);
+        $reply = input('reply','');
+
+        $data = [
+            'reply' => $reply,
+            'replytime' => time(),
+        ];
+        Db::name('order_comment')->where('id',$comment_id)->update($data);
+
+        $this->success('回复完成');
+    }
+}

+ 74 - 0
application/api/controller/company/Staff.php

@@ -0,0 +1,74 @@
+<?php
+
+namespace app\api\controller\company;
+
+use app\common\controller\Apic;
+use think\Db;
+
+/**
+ * 员工管理
+ */
+class Staff extends Apic
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = '*';
+
+    public function _initialize()
+    {
+        parent::_initialize();
+    }
+
+
+    //列表
+    public function lists(){
+        $list = Db::name('company_staff')->where('company_id',$this->auth->id)->autopage()->select();
+
+        $this->success('success',$list);
+    }
+
+    //新增
+    public function add(){
+        $data = [
+            'truename' => input('truename',''),
+            'mobile' => input('mobile',''),
+            'company_id' => $this->auth->id,
+        ];
+
+        //检查
+        $check1 = Db::name('company')->where('mobile',$data['mobile'])->find();
+        $check2 = Db::name('company_staff')->where('mobile',$data['mobile'])->find();
+        if($check1 || $check2){
+            $this->error('该手机已经被注册为员工或商户管理员');
+        }
+
+        Db::name('company_staff')->insertGetId($data);
+        $this->success('添加成功');
+    }
+
+    //详情
+    public function info(){
+        $id = input('id',0);
+        $info = Db::name('company_staff')->where('id',$id)->find();
+        $this->success(1,$info);
+    }
+
+    //编辑
+    public function edit(){
+        $id = input('id',0);
+        $data = [
+            'truename' => input('truename',''),
+            'mobile' => input('mobile',''),
+        ];
+
+        //检查
+        $check1 = Db::name('company')->where('mobile',$data['mobile'])->find();
+        $check2 = Db::name('company_staff')->where('id','neq',$id)->where('mobile',$data['mobile'])->find();
+        if($check1 || $check2){
+            $this->error('该手机已经被注册为员工或商户管理员');
+        }
+
+        Db::name('company_staff')->where('id',$id)->update($data);
+
+        $this->success('编辑成功');
+    }
+}

+ 183 - 0
application/api/controller/company/User.php

@@ -0,0 +1,183 @@
+<?php
+
+namespace app\api\controller\company;
+
+use app\common\controller\Apic;
+use app\common\library\Sms;
+use fast\Random;
+use think\Config;
+use think\Validate;
+
+use think\Db;
+
+/**
+ * 会员接口
+ */
+class User extends Apic
+{
+    protected $noNeedLogin = ['mobilelogin'];
+    protected $noNeedRight = '*';
+
+    public function _initialize()
+    {
+        parent::_initialize();
+
+    }
+
+    /**
+     * 手机验证码登录
+     *
+     * @ApiMethod (POST)
+     * @param string $mobile  手机号
+     * @param string $captcha 验证码
+     */
+    public function mobilelogin()
+    {
+        $mobile = $this->request->post('mobile');
+        $captcha = $this->request->post('captcha');
+
+        if (!$mobile || !$captcha) {
+            $this->error(__('Invalid parameters'));
+        }
+        if (!Validate::regex($mobile, "^1\d{10}$")) {
+            $this->error('请填写正确的手机号');
+        }
+        if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
+            $this->error(__('Captcha is incorrect'));
+        }
+
+        //登录与注册
+        $ret = false;
+        $user = \app\common\model\Company::getByMobile($mobile);
+        if ($user) {
+            /*if ($user->status == 0) {
+                $this->error(__('Account is locked'));
+            }
+            if ($user->status == 2) {
+                $this->error('该用户已注销');
+            }*/
+
+            //如果已经有账号则直接登录
+            $ret = $this->auth->direct($user->id);
+        } else {
+
+            //找员工
+            $userstaff = Db::name('company_staff')->where('mobile',$mobile)->find();
+            if($userstaff)
+            {
+                $user = \app\common\model\Company::get($userstaff['company_id']);
+                if($user)
+                {
+                    $ret = $this->auth->direct($user->id);
+                }
+            }
+
+            if($ret === false){
+                // 用户信息不存在时使用
+                $extend = [];
+                $ret = $this->auth->register_mobile($mobile, Random::alnum(), '', $mobile, $extend);
+            }
+        }
+        if ($ret) {
+            Sms::flush($mobile, 'mobilelogin');
+            $data = ['userinfo' => $this->getUserinfo('return')];
+            $this->success('登录成功', $data);
+        } else {
+            $this->error($this->auth->getError());
+        }
+    }
+
+
+
+    /**
+     * 退出登录
+     * @ApiMethod (POST)
+     */
+    public function logout()
+    {
+        if (!$this->request->isPost()) {
+            $this->error(__('Invalid parameters'));
+        }
+        $this->auth->logout();
+        $this->success(__('Logout successful'));
+    }
+
+
+    //用户详细资料
+    public function getUserinfo($type = 1){
+        $info = $this->auth->getUserinfo();
+        if($type == 'return'){
+            return $info;
+        }
+        $this->success(__('success'),$info);
+    }
+
+    //用户申请资料
+    public function getUserapplyinfo(){
+        $field = [
+            'company_name',
+            'company_code',
+            'company_registerdate',
+            'company_address',
+            'company_image',
+
+            'truename',
+            'idcard',
+            'idcard_images',
+
+            'bank_name',
+            'bank_branchname',
+            'bank_account',
+            'bank_card',
+        ];
+
+        $info = Db::name('company')->field($field)->where('id',$this->auth->id)->find();
+        $info = info_domain_image($info,['company_image','idcard_images']);
+        $this->success(1,$info);
+    }
+
+
+    /**
+     * 修改会员个人信息
+     *
+     * @ApiMethod (POST)
+     * @param string $avatar   头像地址
+     * @param string $username 用户名
+     * @param string $nickname 昵称
+     * @param string $bio      个人简介
+     */
+    public function profile()
+    {
+        //检查
+        $check = Db::name('company')->where('id',$this->auth->id)->find();
+        if($check['status'] == 1){
+            $this->success('资料审核通过后需联系客服修改');
+        }
+
+        $field = [
+            'company_name',
+            'company_code',
+            'company_registerdate',
+            'company_address',
+            'company_image',
+
+            'truename',
+            'idcard',
+            'idcard_images',
+
+            'bank_name',
+            'bank_branchname',
+            'bank_account',
+            'bank_card',
+        ];
+
+        $data = request_post_hub($field);
+        $data['status'] = 0;
+
+        $update_rs = Db::name('company')->where('id',$this->auth->id)->update($data);
+
+        $this->success('资料更新完成');
+    }
+
+
+}

+ 110 - 0
application/api/controller/company/Userbank.php

@@ -0,0 +1,110 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+
+/**
+ * 会员银行卡
+ */
+class Usercenter extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = '*';
+
+
+    //提现账号添加
+    public function bankadd() {
+        $bank_account    = input('bank_account', '', 'trim'); //账户真实姓名
+        $bank_card       = input('bank_card', '', 'trim'); //卡号或账号
+        $bank_name       = input('bank_name', '', 'trim'); //银行名称
+        $bank_branchname = input('bank_branchname', '', 'trim'); //支行名称
+
+        if ($bank_account === '' || iconv_strlen($bank_account, 'utf-8') > 30) {
+            $this->error('账号姓名1-30位');
+        }
+        if ($bank_card === '' || iconv_strlen($bank_card, 'utf-8') > 50) {
+            $this->error('账号1-50位');
+        }
+        if ($bank_name === '' || iconv_strlen($bank_name, 'utf-8') > 50) {
+            $this->error('银行名称1-50位');
+        }
+        if ($bank_branchname === '' || iconv_strlen($bank_branchname, 'utf-8') > 50) {
+            $this->error('支行名称1-50位');
+        }
+
+        //添加
+        $count = Db::name('user_bank')->where(['user_id' => $this->auth->id])->count('id');
+        if ($count) {
+            $this->error('您已经拥有该类型账号,不能再添加');
+        }
+
+        $data['user_id'] = $this->auth->id;
+        $data['bank_account'] = $bank_account;
+        $data['bank_card'] = $bank_card;
+        $data['bank_name'] = $bank_name;
+        $data['bank_branchname'] = $bank_branchname;
+        $data['createtime'] = time();
+
+        $rs = Db::name('user_bank')->insertGetId($data);
+        if (!$rs) {
+            $this->error('添加失败');
+        }
+
+        $this->success('添加成功');
+    }
+
+    //提现账号编辑
+    public function bankedit(){
+        $id = input('id', 0, 'intval'); //账号id
+        $bank_account    = input('bank_account', '', 'trim'); //账户真实姓名
+        $bank_card       = input('bank_card', '', 'trim'); //卡号或账号
+        $bank_name       = input('bank_name', '', 'trim'); //银行名称
+        $bank_branchname = input('bank_branchname', '', 'trim'); //支行名称
+
+        if ($bank_account === '' || iconv_strlen($bank_account, 'utf-8') > 30) {
+            $this->error('账号姓名1-30位');
+        }
+        if ($bank_card === '' || iconv_strlen($bank_card, 'utf-8') > 50) {
+            $this->error('账号1-50位');
+        }
+        if ($bank_name === '' || iconv_strlen($bank_name, 'utf-8') > 50) {
+            $this->error('银行名称1-50位');
+        }
+        if ($bank_branchname === '' || iconv_strlen($bank_branchname, 'utf-8') > 50) {
+            $this->error('支行名称1-50位');
+        }
+
+        //查询账号是否存在
+        $info = Db::name('user_bank')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
+        if (!$info) {
+            $this->error('账号不存在');
+        }
+
+        $data['bank_account'] = $bank_account;
+        $data['bank_card'] = $bank_card;
+        $data['bank_name'] = $bank_name;
+        $data['bank_branchname'] = $bank_branchname;
+        $data['updatetime'] = time();
+
+        $rs = Db::name('user_bank')->where(['id' => $id])->update($data);
+        if ($rs === false) {
+            $this->error('修改失败');
+        }
+
+        $this->success('修改成功');
+    }
+
+    //提现账号信息
+    public function bankinfo() {
+
+        $info = Db::name('user_bank')->where(['user_id' => $this->auth->id])->find();
+        if (!$info) {
+            $info = (object)[];
+        }
+
+        $this->success('账户信息', $info);
+    }
+
+}

+ 4 - 0
gitpull.sh

@@ -0,0 +1,4 @@
+sudo -uroot git reset --hard;
+sudo -uroot git pull;
+sudo -uroot chown -R www:www /www/wwwroot/lanjingling.huxiukeji.com;
+sudo -uroot chmod -R 777 *;