吴广广 3 years ago
parent
commit
fb813ed6fe

+ 111 - 75
application/Admin/controller/System.php

@@ -2,88 +2,124 @@
 
 
 
 
 namespace app\Admin\controller;
 namespace app\Admin\controller;
+
 use think\Db;
 use think\Db;
 
 
 
 
 class System extends Base
 class System extends Base
 {
 {
-    protected $role = ["0"=>'系统',"1"=>"超级管理员","2"=>"管理员","3"=>"用户"];
-    protected  $menu=[];
-    protected  $action=[];
- public function __construct()
- {
-     parent::__construct();
-     $this->menu=[
-         "login"=>"后台登录模块",
-         "menu"=>"菜单管理模块",
-         "menuaction"=>"菜单功能模块",
-         "order"=>"订单管理模块",
-         "stock"=>"库存管理模块",
-         "account"=>"用户管理模块",
-         "version"=>"版本管理模块",
-     ];
-     $this->action=[
-         "add"=>"新建",
-         "edit"=>"编辑",
-         "status"=>"状态",
-         "del"=>"删除"
-     ];
- }
+    protected $role = ["0" => '系统', "1" => "超级管理员", "2" => "管理员", "3" => "用户"];
+    protected $menu = [];
+    protected $action = [];
+
+    public function __construct()
+    {
+        parent::__construct();
+        $this->menu = [
+            "login" => ["label" => "后台登录模块", "action" => []],
+            "menu" => ["label" => "菜单管理模块", "action" => [
+                ['value'=>"add","label"=>'新建'],
+                ['value'=>"edit","label"=>'编辑'],
+                ['value'=>"status","label"=>'状态'],
+                ['value'=>"del","label"=>'删除'],
+                ]],
+            "menuaction" => ["label" => "菜单功能模块", "action" => [
+                ['value'=>"add","label"=>'新建'],
+                ['value'=>"edit","label"=>'编辑'],
+                ['value'=>"status","label"=>'状态'],
+                ['value'=>"del","label"=>'删除']]],
+            "order" => ["label" => "订单管理模块", "action" => [
+                ['value'=>"edit","label"=>'编辑'],
+                ['value'=>"status","label"=>'状态']
+            ]],
+            "stock" => ["label" => "库存管理模块", "action" => [
+                ['value'=>"add","label"=>'新建'],
+                ['value'=>"edit","label"=>'编辑']
+            ]],
+            "account" => ["label" => "用户管理模块", "action" => [
+                ['value'=>"add","label"=>'新建'],
+                ['value'=>"edit","label"=>'编辑'],
+                ['value'=>"status","label"=>'状态'],
+                ['value'=>"del","label"=>'删除']
+            ]],
+            "version" => ["label" => "版本管理模块", "action" => [
+                ['value'=>"add","label"=>'新建'],
+                ['value'=>"edit","label"=>'编辑']
+            ]
+        ]];
+        $this->action = [
+            "add" => "新建",
+            "edit" => "编辑",
+            "status" => "状态",
+            "del" => "删除"
+        ];
+    }
+
+    public function list()
+    {
+        $page = isset($this->post['page']) && $this->post['page'] != "" ? intval($this->post['page']) : 1;
+        $size = isset($this->post['size']) && $this->post['size'] != "" ? intval($this->post['size']) : 10;
+        $where = [];
+        $role = isset($this->post['role']) && $this->post['role'] != "" ? $this->post['role'] : "";
+        if ($role != "") {
+            $where['role'] = $role;
+        }
+        $lowtime = isset($this->post['lowtime']) && $this->post['lowtime'] != "" ? $this->post['lowtime'] : "";
+        if ($lowtime != "") {
+            $where['addtime'] = [">=", $lowtime];
+        }
+        $uptime = isset($this->post['uptime']) && $this->post['uptime'] != "" ? $this->post['uptime'] : "";
+        if ($uptime != "") {
+            $where['addtime'] = ["<=", $uptime];
+        }
+        $username = isset($this->post['username']) && $this->post['username'] != "" ? $this->post['username'] : "";
+        if ($username != "") {
+            $where['username'] = ["like", "%{$username}%"];
+        }
+        $moudel = isset($this->post['moudel']) && $this->post['moudel'] != "" ? $this->post['moudel'] : "";
+        if ($moudel != "") {
+            $where['moudel|action'] = ["like", "%{$moudel}%"];
+        }
+        $count = Db::name("system_log")->where($where)->count();
+        $total = ceil($count / $size);
+        $page = $page >= $total ? $total : $page;
+        $list = Db::name("system_log")->where($where)->page($page, $size)->order("addtime desc")->select();
+        foreach ($list as $key => $value) {
+            $list[$key]['moudel'] = key_exists($value['moudel'], $this->menu) ?
+                $this->menu[$value['moudel']]['label'] :
+                $value['moudel'];
+            $list[$key]['action'] = key_exists($value['action'], $this->action) ? $this->action[$value['action']] : $value['action'];
+            $list[$key]['role'] = key_exists($value['role'], $this->role) ? $this->role[$value['role']] : $value['role'];
+        }
+        return app_show(0, "获取成功", ["list" => $list, "count" => $count]);
+    }
 
 
- public function list(){
-     $page = isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']) : 1;
-     $size = isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']) :10;
-     $where=[];
-     $role=isset($this->post['role'])&&$this->post['role']!=""?$this->post['role']:"";
-     if($role!=""){
-         $where['role']=$role;
-     }
-     $lowtime=isset($this->post['lowtime'])&&$this->post['lowtime']!=""?$this->post['lowtime']:"";
-     if($lowtime!=""){
-         $where['addtime']=[">=",$lowtime];
-     }
-     $uptime=isset($this->post['uptime'])&&$this->post['uptime']!=""?$this->post['uptime']:"";
-     if($uptime!=""){
-         $where['addtime']=["<=",$uptime];
-     }
-     $username=isset($this->post['username'])&&$this->post['username']!=""?$this->post['username']:"";
-     if($username!=""){
-         $where['username']=["like","%{$username}%"];
-     }
-     $moudel=isset($this->post['moudel'])&&$this->post['moudel']!=""?$this->post['moudel']:"";
-     if($moudel!=""){
-         $where['moudel|action']=["like","%{$username}%"];
-     }
-     $count= Db::name("system_log")->where($where)->count();
-     $total = ceil($count/$size);
-     $page = $page>=$total? $total:$page;
-     $list = Db::name("system_log")->where($where)->page($page,$size)->order("addtime desc")->select();
-     foreach ($list as $key=>$value){
-         $list[$key]['moudel'] = key_exists($value['moudel'],$this->menu)?$this->menu[ $value['moudel']] : $value['moudel'];
-         $list[$key]['action'] = key_exists($value['action'],$this->action)?$this->action[ $value['action']] : $value['action'];
-         $list[$key]['role'] = key_exists($value['role'],$this->role)?$this->role[ $value['role']] : $value['role'];
-     }
-     return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
- }
+    public function GetMenu()
+    {
+        $data = [];
+        foreach ($this->menu as $key => $value) {
+            $temp = [];
+            $temp["label"] = $value['label'];
+            $temp["value"] = $key;
+            $temp["children"] = $value['action'];
+            $data[] = $temp;
+        }
+        return app_show(0, "获取成功", $data);
+    }
 
 
- public function GetMenu(){
-     $data=[];
-     foreach ($this->menu as $key=>$value){
-         $temp=[];
-         $temp["value"]=$value;
-         $temp["lable"]=$key;
-         $data[]=$temp;
-     }
-     return app_show(0,"获取成功",$data);
- }
-    public function GetAction(){
-        $data=[];
-        foreach ($this->action as $key=>$value){
-            $temp=[];
-            $temp["value"]=$value;
-            $temp["lable"]=$key;
-            $data[]=$temp;
+    public function GetAction()
+    {
+        $data = [];
+        $moudel=isset($this->post['moudel'])&&$this->post['moudel']!="" ?  trim($this->post['moudel']):"";
+        if($moudel!=""){
+            $this->action = key_exists($moudel, $this->menu) ? $this->menu[$moudel]['action'] :[];
+        }
+        foreach ($this->action as $key => $value) {
+            $temp = [];
+            $temp["value"] = $value;
+            $temp["lable"] = $key;
+            $data[] = $temp;
         }
         }
-        return app_show(0,"获取成功",$data);
+        return app_show(0, "获取成功", $data);
     }
     }
 }
 }

+ 2 - 2
application/Home/common.php

@@ -41,9 +41,9 @@ function verifyToken($token){
         return ["code"=>104,"msg"=>"账户已失效"];
         return ["code"=>104,"msg"=>"账户已失效"];
     }
     }
     $token_str = base64_decode($token);
     $token_str = base64_decode($token);
-    $account_str= stristr($token_str,-10);
+    $account_str= substr($token_str,0,-10);
     if($account_str==$account['username'].$account['salt']){
     if($account_str==$account['username'].$account['salt']){
-        Db::name("account_token")->where(["token"=>$token])->update(["expiretime"=>$account['expiretime']+1800]);
+        Db::name("account_token")->where(["token"=>$token])->update(["expiretime"=>date("Y-m-d H:i:s",time()+1800)]);
         return ["code"=>0,"msg"=>"账户有效"];
         return ["code"=>0,"msg"=>"账户有效"];
     }else{
     }else{
         return ["code"=>105,"msg"=>"账户token无效"];
         return ["code"=>105,"msg"=>"账户token无效"];

+ 220 - 0
application/Home/controller/Addr.php

@@ -0,0 +1,220 @@
+<?php
+
+
+namespace app\Home\controller;
+use think\Db;
+
+class Addr extends Base
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * @param id 地址id
+     */
+    public function Info(){
+        $addrid = isset($this->post['id'])&&$this->post['id']!==""?$this->post['id']:"";
+        if($addrid==""){
+            return error_show(1005,"参数id 不能为空");
+        }
+        $list = Db::name("rela_addr")->alias('a')->join("addr as b","a.addrid=b.id","left")->where(["a
+        .accountid"=>$this->userinfo['id'],"b.is_del"=>0,"b.id"=>$addrid])->field("b.id,b.provice,b.provice_name,b.city,
+        b.city_name,b.area,b.area_name,b.addr,b.contector,b.mobile,b.addtime")->find();
+        if(empty($list)){
+            return error_show(1004,"未找到数据");
+        }
+        return app_show(0,"获取数据成功",$list);
+    }
+
+    /**
+     * @param
+     */
+    public function list(){
+        $list = Db::name("rela_addr")->alias('a')->join("addr as b","a.addrid=b.id","left")->where(["
+        a.accountid"=>$this->userinfo['id'],"b.is_del"=>0])->field("b.id,b.provice,b.provice_name,b.city,
+        b.city_name,b.area,b.area_name,b.addr,b.contector,b.mobile,b.addtime")->select();
+        return  app_show(0,"获取成功", $list);
+    }
+
+    /**
+     * @param contector
+     * @param mobile
+     * @param provice
+     * @param city
+     * @param area
+     */
+    public function Add(){
+        $contector = isset($this->post['contector'])&&$this->post['contector']!=""? trim($this->post['contector']):"";
+        if($contector==""){
+            return error_show(1004,"参数contector 不能为空");
+        }
+        $mobile = isset($this->post['mobile'])&&$this->post['mobile']!="" ? trim($this->post['mobile']):"";
+        if($mobile==""){
+            return error_show(1005,"参数mobile 不能为空");
+        }
+        $province =  isset($this->post['provice'])&&$this->post['provice']!=""? trim($this->post['provice']):"";
+        $city =  isset($this->post['city'])&&$this->post['city']!=""? trim($this->post['city']):"";
+        $area =  isset($this->post['area'])&&$this->post['area']!=""? trim($this->post['area']):"";
+        if($province==""){
+            return error_show(1005,"参数provice 不能为空");
+        }
+        if($city==""){
+            return error_show(1005,"参数city 不能为空");
+        }
+        if($area==""){
+            return error_show(1005,"参数area 不能为空");
+        }
+        $province_info = Db::name("province")->where(['province_code'=>$province])->find();
+        if(empty($province_info)){
+            return error_show(1005,"省级数据未找到");
+        }
+       $cityinfo = Db::name("city")->where(['province_code'=>$province,"city_code"=>$city])->find();
+        if(empty($cityinfo)){
+            return error_show(1005,"市级数据未找到");
+        }
+        $areainfo = Db::name("area")->where(['area_code'=>$area,"city_code"=>$city])->find();
+        if(empty($areainfo)){
+            return error_show(1005,"区县级数据未找到");
+        }
+        $addr = isset($this->post['addr'])&&$this->post['addr']!=""?$this->post['addr']:"";
+        if($addr==""){
+            return error_show(1005,"参数addr 不能为空");
+        }
+        Db::startTrans();
+        try{
+            $data=[
+                "addr"=>$addr,
+                "provice"=>$province,
+                "provice_name"=>$province_info['name'],
+                "city"=>$city,
+                "city_name"=>$cityinfo['name'],
+                "area"=>$area,
+                "area_name"=>$areainfo['name'],
+                "contector"=>$contector,
+                "mobile"=>$mobile,
+                'status'=>1,
+                "is_del"=>0,
+                "addtime"=>date("Y-m-d H:i:s"),
+                "updatetime"=>date("Y-m-d H:i:s")
+            ];
+            $addrid =Db::name("addr")->insert($data,false,true);
+            if($addrid>0){
+                $rela = Db::name("rela_addr")->insert(['accountid'=>$this->userinfo['id'],"addrid"=>$addrid]);
+                if($rela){
+                    Db::commit();
+                    return app_show(0,"地址新建成功");
+                }
+            }
+            Db::rollback();
+            return error_show(1008,"地址新建失败");
+        }catch (\Exception $e){
+            Db::rollback();
+            return error_show(1008,$e->getMessage());
+        }
+    }
+    /**
+     * @param contector
+     * @param mobile
+     * @param provice
+     * @param city
+     * @param area
+     * @param id
+     */
+    public function Edit(){
+        $addrid = isset($this->post['id'])&&$this->post['id']!==""?$this->post['id']:"";
+        if($addrid==""){
+            return error_show(1005,"参数id 不能为空");
+        }
+        $list = Db::name("rela_addr")->alias('a')->join("addr as b","a.addrid=b.id","left")->where(["a
+        .accountid"=>$this->userinfo['id'],"b.is_del"=>0,"b.id"=>$addrid])->field("b.id,b.provice,b.provice_name,b.city,
+        b.city_name,b.area,b.area_name,b.addr,b.contector,b.mobile,b.addtime")->find();
+        if(empty($list)){
+            return error_show(1004,"未找到数据");
+        }
+        $contector = isset($this->post['contector'])&&$this->post['contector']!=""? trim($this->post['contector']):"";
+        if($contector!=""){
+            return error_show(1004,"参数contector 不能为空");
+        }
+        $mobile = isset($this->post['mobile'])&&$this->post['mobile']!="" ? trim($this->post['mobile']):"";
+        if($mobile==""){
+            return error_show(1005,"参数mobile 不能为空");
+        }
+        $province =  isset($this->post['provice'])&&$this->post['provice']!=""? trim($this->post['provice']):"";
+        $city =  isset($this->post['city'])&&$this->post['city']!=""? trim($this->post['city']):"";
+        $area =  isset($this->post['area'])&&$this->post['area']!=""? trim($this->post['area']):"";
+        if($province==""){
+            return error_show(1005,"参数provice 不能为空");
+        }
+        if($city==""){
+            return error_show(1005,"参数city 不能为空");
+        }
+        if($area==""){
+            return error_show(1005,"参数area 不能为空");
+        }
+        $province_info = Db::name("province")->where(['province_code'=>$province])->find();
+        if(empty($province_info)){
+            return error_show(1005,"省级数据未找到");
+        }
+        $cityinfo = Db::name("city")->where(['province_code'=>$province,"city_code"=>$city])->find();
+        if(empty($cityinfo)){
+            return error_show(1005,"市级数据未找到");
+        }
+        $areainfo = Db::name("area")->where(['area_code'=>$area,"city_code"=>$city])->find();
+        if(empty($areainfo)){
+            return error_show(1005,"区县级数据未找到");
+        }
+        $addr = isset($this->post['addr'])&&$this->post['addr']!=""?$this->post['addr']:"";
+        if($addr==""){
+            return error_show(1005,"参数addr 不能为空");
+        }
+        Db::startTrans();
+        try{
+            $data=[
+                "id"=>$addrid,
+                "addr"=>$addr,
+                "provice"=>$province,
+                "provice_name"=>$province_info['name'],
+                "city"=>$city,
+                "city_name"=>$cityinfo['name'],
+                "area"=>$area,
+                "area_name"=>$area['name'],
+                "contector"=>$contector,
+                "mobile"=>$mobile,
+                "updatetime"=>date("Y-m-d H:i:s")
+            ];
+            $addrup =Db::name("addr")->update($data);
+            if($addrup){
+                    Db::commit();
+                    return app_show(0,"地址修改成功");
+            }
+            Db::rollback();
+            return error_show(1008,"地址修改失败");
+        }catch (\Exception $e){
+            Db::rollback();
+            return error_show(1008,$e->getMessage());
+        }
+    }
+
+    /**
+     * @param id 地址id
+     */
+    public function Delete(){
+        $addrid = isset($this->post['id'])&&$this->post['id']!==""?$this->post['id']:"";
+        if($addrid==""){
+            return error_show(1005,"参数id 不能为空");
+        }
+        $list = Db::name("rela_addr")->alias('a')->join("addr as b","a.addrid=b.id","left")->where(["a
+        .accountid"=>$this->userinfo['id'],"b.is_del"=>0,"b.id"=>$addrid])->field("b.id,b.provice,b.provice_name,b.city,
+        b.city_name,b.area,b.area_name,b.addr,b.contector,b.mobile,b.addtime")->find();
+        if(empty($list)){
+            return error_show(1004,"未找到数据");
+        }
+        $del= Db::name("addr")->where(['id'=>$addrid])->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
+        if($del){
+            return app_show(0,"d地址删除成功");
+        }
+        return error_show(1005,"地址删除失败");
+    }
+}

+ 34 - 0
application/Home/controller/Base.php

@@ -0,0 +1,34 @@
+<?php
+
+
+namespace app\Home\controller;
+use think\Db;
+
+
+class Base
+{
+    public $post="";
+    public $userinfo="";
+    public function __construct()
+    {
+        $this->post=request()->post();
+        $token = isset($this->post['token'])&&$this->post['token']!="" ? trim($this->post['token']):"";
+        if($token==""){
+            return error_show(102,"token不能为空");
+        }
+        $verify = verifyToken($token);
+        if($verify['code']!=0){
+            return error_show($verify['code'],$verify['msg']);
+        }
+        $tokeninfo = Db::name("account_token")->where(["token"=>$token])->find();
+        if(!isset($tokeninfo['accountid'])){
+            return error_show(1004,"未找到账户id");
+        }
+        $userinfo = Db::name("account_list")->where(["id"=>$tokeninfo['accountid']])->field("id,username,status,starttime,expiretime,activetime,addtime,nickname,avatar,mobile,remark")->find();
+        if(empty($userinfo)){
+            return error_show(1004,"未找到账户数据");
+        }
+        $this->userinfo=$userinfo;
+    }
+
+}

+ 25 - 1
application/Home/controller/Login.php

@@ -38,10 +38,34 @@ class Login
         if($now>$expire){
         if($now>$expire){
             return error_show(1005,"账户已过有效期");
             return error_show(1005,"账户已过有效期");
         }
         }
+        if($account['status']==0){
+            $account['status']=1;
+            $account['activetime']=date("Y-m-d H:i:s");
+            $account['updatetime']=date("Y-m-d H:i:s");
+            Db::name("account")->update($account);
+        }
         $token = makeToken($account);
         $token = makeToken($account);
         $userinfo = Db::name("account_info")->alias("a")->join("fc_rela_account b","b.account_info=a.id")->where(["b.accountid"=>$account['id']])->field("a.*")->find();
         $userinfo = Db::name("account_info")->alias("a")->join("fc_rela_account b","b.account_info=a.id")->where(["b.accountid"=>$account['id']])->field("a.*")->find();
         $userinfo['token'] = $token;
         $userinfo['token'] = $token;
-        write_log("账户{$account['username']}登录系统","0");
+        write_log("账户{$account['username']}登录系统","login","","",1);
         return app_show(0,"登录成功",$userinfo);
         return app_show(0,"登录成功",$userinfo);
     }
     }
+
+    public function  logout(){
+        $post=request()->post();
+        $token =  isset($post['token'])&&$post['token']!="" ? trim($post['token']) :"";
+        if($token==""){
+            return error_show(101,"参数token 不能为空");
+        }
+        $verify = verifyToken($token);
+        if($verify['code']!=0){
+            return error_show($verify['code'],$verify['msg']);
+        }
+        $info = Db::name("account_token")->where(["token"=>$token])->update(['token'=>""]);
+        if($info){
+            return app_show(0,"退出成功");
+        }else{
+            return error_show(1004,"退出失败");
+        }
+    }
 }
 }

+ 131 - 0
application/Home/controller/Order.php

@@ -0,0 +1,131 @@
+<?php
+
+
+namespace app\Home\controller;
+use think\Db;
+
+class Order extends Base
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * @param status 0/1/2
+     * @param page
+     * @param size
+     */
+    public function list(){
+        $page = isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']):1;
+        $size = isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']):10;
+        $status = isset($this->post['status'])&&$this->post['status']!="" ? intval($this->post['status']):0;
+        $where=["is_del"=>0,"accountid"=>$this->userinfo['id']];
+        if($status!=0 && in_array($status,[1,2])){
+            $where['status']=$status;
+        }
+        $count =Db::name("order_info")->where($where)->count();
+        $total = ceil($count/$size);
+        $page = $page>$total?$total:$page;
+        $list = Db::name("order_info")->where($where)->page($page,$size)->field("id,order_sn,order_num,order_time,delivery_time")
+            ->select();
+        return app_show(0,"获取成功",["list"=>$list,"count"=>$total]);
+    }
+
+    /**
+     * @param id 订单id
+     */
+    public function info(){
+        $id = isset($this->post['id'])&&$this->post['id']!="" ? intval($this->post['id']):"";
+        if($id==""){
+            return error_show(1004,"参数id 不能为空");
+        }
+        $order = Db::name("order_info")->where(["is_del"=>0,"accountid"=>$this->userinfo['id'],"id"=>$id])->field("id,
+        order_sn,order_num,order_time,delivery_time,post_code,post_name,provice_name,city_name,area_name,addr,contector,contector_mobile,nickname")->find();
+        if(empty($order)){
+            return error_show(1005,"未找到订单数据");
+        }
+        return app_show(0,"获取成功",$order);
+    }
+
+    /**
+     * @param  num
+     * @param  addrid
+     */
+    public function add(){
+        $num = isset($this->post['num'])&&$this->post['num']!="" ? intval($this->post['num']):"";
+        if($num==""){
+            return error_show(1004,"参数num 不能为空或0");
+        }
+        $addrid = isset($this->post['addrid'])&&$this->post['addrid']!="" ? intval($this->post['addrid']):"";
+        if($addrid==""){
+            return error_show(1004,"参数addrid 不能为空");
+        }
+        $stock = Db::name("account_stock")->where(['is_del'=>0,"accountid"=>$this->userinfo['id']])->find();
+        if(empty($stock) || $stock['stock_balance']<$num){
+            return error_show(1004,"库存数量不足");
+        }
+        $addr =Db::name("rela_addr")->alias('a')->join("addr as b","a.addrid=b.id","left")->where(["a
+        .accountid"=>$this->userinfo['id'],"b.is_del"=>0,"b.id"=>$addrid])->field("b.id,b.provice,b.provice_name,b.city,
+        b.city_name,b.area,b.area_name,b.addr,b.contector,b.mobile,b.addtime")->find();
+        if(empty($addr)){
+            return error_show(1004,"地址数据未找到");
+        }
+        Db::startTrans();
+        try{
+            $ordersn =makeNo("FC");
+            $data=[
+                "order_sn"=>$ordersn,
+                "accountid"=>$this->userinfo['id'],
+                "order_num"=>$num,
+                "is_del"=>0,
+                "status"=>1,
+                "addtime"=>date("Y-m-d H:i:s"),
+                "updatetime"=>date("Y-m-d H:i:s"),
+                "order_time"=>date("Y-m-d H:i:s"),
+            ];
+            $ordercreate= Db::name("order")->insert($data);
+            if($ordercreate){
+                $post =[
+                    "order_sn"=>$ordersn,
+                    "addrid"=>$addrid,
+                    "order_num"=>$num,
+                    'post_code'=>"",
+                    'post_name'=>"",
+                    "status"=>1,
+                    "is_del"=>0,
+                    "addtime"=>date("Y-m-d H:i:s"),
+                    "updatetime"=>date("Y-m-d H:i:s")
+                ];
+                $orderpost=Db::name("order_post")->insert($post);
+                if($orderpost){
+                   $updatestock= Db::name("account_stock")->where($stock)->update
+                    (['stock_balance'=>$stock['stock_balance']-$num,
+                        "stock_delivery"=>$stock['stock_delivery']+$num,"updatetime"=>date("Y-m-d H:i:s")]);
+                   if($updatestock){
+                       $log=[
+                           "accountid"=>$this->userinfo['id'],
+                           "run_stock"=>$num,
+                           "type"=>3,
+                           "after_stock"=>$stock['stock_balance']-$num,
+                           "before_stock"=>$stock['stock_balance'],
+                           "action_uid"=>$this->userinfo['id'],
+                           "action_name"=>$this->userinfo['nickname'],
+                           "addtime"=>date("Y-m-d H:i:s")
+                       ];
+                       $stocklog =Db::name("stock_log")->insert($log);
+                       if($stocklog){
+                           Db::commit();
+                           return app_show(0,"下单成功");
+                       }
+                   }
+                }
+            }
+            Db::rollback();
+            return error_show(1006,"下单失败");
+        }catch (\Exception $e){
+            Db::rollback();
+            return error_show(1005,$e->getMessage());
+        }
+    }
+}

+ 26 - 0
application/Home/controller/User.php

@@ -0,0 +1,26 @@
+<?php
+
+
+namespace app\Home\controller;
+use think\Db;
+
+class User extends Base
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    public function Info(){
+        return app_show(0,"获取成功",$this->userinfo);
+    }
+
+    /**
+     * @param 地址列表
+     */
+    public function AddrList(){
+        $list = Db::name("rela_addr")->alias('a')->join("addr as b","a.addrid=b.id","left")->where(["a
+        .accountid"=>$this->userinfo['id'],"b.is_del"=>0])->select();
+        return  app_show(0,"获取成功", $list);
+    }
+}

+ 3 - 3
application/database.php

@@ -13,15 +13,15 @@ return [
     // 数据库类型
     // 数据库类型
     'type'            => 'mysql',
     'type'            => 'mysql',
     // 服务器地址
     // 服务器地址
-    'hostname'        => '124.70.80.31',
+    'hostname'        => '192.168.1.210',
     // 数据库名
     // 数据库名
     'database'        => 'fivechang',
     'database'        => 'fivechang',
     // 用户名
     // 用户名
     'username'        => 'root',
     'username'        => 'root',
     // 密码
     // 密码
-    'password'        => 'wyht123',
+    'password'        => '123456',
     // 端口
     // 端口
-    'hostport'        => '3306',
+    'hostport'        => '3307',
     // 连接dsn
     // 连接dsn
     'dsn'             => '',
     'dsn'             => '',
     // 数据库连接参数
     // 数据库连接参数

+ 11 - 0
application/route.php

@@ -50,6 +50,17 @@ Route::rule('admin/systemlist','Admin/System/list');
 Route::rule('admin/getmoudel','Admin/System/GetMenu');
 Route::rule('admin/getmoudel','Admin/System/GetMenu');
 Route::rule('admin/getaction','Admin/System/GetAction');
 Route::rule('admin/getaction','Admin/System/GetAction');
 
 
+Route::rule("home/login","home/Login/index");
+
+Route::rule("home/userinfo","home/User/info");
+
+Route::rule("home/addrlist","home/Addr/list");
+Route::rule("home/addrinfo","home/Addr/Info");
+Route::rule("home/addradd","home/Addr/Add");
+Route::rule("home/addredit","home/Addr/Edit");
+Route::rule("home/addrdel","home/Addr/Delete");
+
+