wugg пре 3 година
родитељ
комит
b4d71be891

+ 7 - 1
application/Admin/controller/Account.php

@@ -124,6 +124,7 @@ class Account extends Base
 //            return error_show(1004,"参数nickname 不能为空");
 //        }
         $mobile = isset($this->post['mobile']) && $this->post['mobile'] !== "" ? trim($this->post['mobile']) : "";
+        $type = isset($this->post['type']) && $this->post['type'] !== "" ? intval($this->post['type']) : "0";
 //        if($mobile==""){
 //            return error_show(1004,"参数mobile 不能为空");
 //        }
@@ -141,6 +142,7 @@ class Account extends Base
                 "password" => $pas,
                 "pwd" => $pasword,
                 "salt" => $salt,
+                "account_type" => $type,
                 "status" => 0,
                 "is_del" => 0,
                 "starttime" => $starttime,
@@ -216,6 +218,7 @@ class Account extends Base
 	                      `a`.`password` AS `password`,
 	                      `a`.`salt` AS `salt`,
 	                      `a`.`status` AS `status`,
+	                      `a`.`account_type` AS `account_type`,
                           `a`.`is_del` AS `is_del`,
                           `a`.`starttime` AS `starttime`,
                           `a`.`expiretime` AS `expiretime`,
@@ -303,7 +306,10 @@ class Account extends Base
         if ($mobile != "") {
             $rela['mobile'] = $mobile;
         }
-
+        $type = isset($this->post['type']) && $this->post['type'] !== "" ? intval($this->post['type']) : "";
+        if($type!==""){
+            $info['account_type']=$type;
+        }
         $rela['remark'] = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
         $video = isset($this->post['video']) && $this->post['video'] !== "" ? $this->post['video'] : "";
         if ($video == "") {

+ 197 - 0
application/Admin/controller/Good.php

@@ -0,0 +1,197 @@
+<?php
+
+
+namespace app\Admin\controller;
+use think\facade\Db;
+
+class Good extends Base
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    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']) : "";
+        $where = ["is_del"=>0];
+        if ($status !== "") {
+            $where['status'] = $status;
+        }
+       $good_name =  isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name'])
+           : "";
+        if ($good_name !== "") {
+            $where['good_name'] = array("like","%$good_name%");
+        }
+
+        $group_id =  isset($this->post['group_id']) && $this->post['group_id'] !== "" ? intval($this->post['group_id'])
+            : "";
+        if ($group_id !== "") {
+            $where['group_id'] =$group_id;
+        }
+        $start = isset($this->post['start']) &&$this->post['start']!=""? $this->post['start'] :"";
+        if($start!==""){
+            $where['addtime'] =array(">=",date("Y-m-d H:i:s",strtotime($start)));
+        }
+        $end = isset($this->post['end']) &&$this->post['end']!=""? $this->post['end'] :"";
+        if($end!==""){
+            $where['addtime'] =array("<=",date("Y-m-d H:i:s",strtotime($end)+24*3600));
+        }
+        $count =Db::name("good")->where($where)->count();
+        $total = ceil($count/$size);
+        $page = $page>$total?$total:$page;
+        $list = Db::name("good")->where($where)->page($page,$size)->select();
+        return  app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
+    }
+
+    public function  create(){
+        $good_name = isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
+        if($good_name==""){
+            return error_show(1004,"参数good_name不能为空");
+        }
+        $good_desc = isset($this->post['good_desc'])&&$this->post['good_desc']!=""?trim($this->post['good_desc']):"";
+        $good_unit = isset($this->post['good_unit'])&&$this->post['good_unit']!=""?trim($this->post['good_unit']):"";
+        if($good_unit==""){
+            return error_show(1004,"参数good_unit不能为空");
+        }
+
+        $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
+        if($good_img==""){
+            return error_show(1004,"参数good_img不能为空");
+        }
+        $origin_place =  isset($this->post['origin_place'])&&$this->post['origin_place']!=""?trim($this->post['origin_place']):"";
+        $group_id =  isset($this->post['group_id'])&&$this->post['group_id']!==""?intval($this->post['group_id']):"";
+        if($group_id===""){
+            return error_show(1004,"参数group_id不能为空");
+        }
+        $isT = Db::name("good")->where(["good_name"=>$good_name,"is_del"=>0,"group_id"=>$group_id])->find();
+        if($isT){
+            return error_show(1004,"商品名称已存在");
+        }
+        $data=[
+            "good_name"=>$good_name,
+            "good_desc"=>$good_desc,
+            "good_unit"=>$good_unit,
+            "good_img"=>$good_img,
+            "origin_place"=>$origin_place,
+            "group_id"=>$group_id,
+            "createrid"=>$this->userinfo['id'],
+            "addtime"=>date("Y-m-d H:i:s"),
+            "updatetime"=>date("Y-m-d H:i:s")
+        ];
+        $in = Db::name("good")->insert($data);
+        if($in){
+            return app_show(0,"新建成功");
+        }else{
+            return app_show(1004,"新建失败");
+        }
+    }
+
+    public function edit(){
+        $id = isset($this->post['id'])&&$this->post['id']!=""? intval($this->post['id']):"";
+        if($id===""){
+            return error_show(1004,"参数id不能为空");
+        }
+        $data = Db::name("good")->where(["id"=>$id,"is_del"=>0])->find();
+        if($data==false){
+            return error_show(1004,"未找到商品数据");
+        }
+        $good_name = isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
+        if($good_name==""){
+            return error_show(1004,"参数good_name不能为空");
+        }
+        $group_id = isset($this->post['group_id'])&&$this->post['group_id']!=""?intval($this->post['group_id']):"";
+        if($group_id==""){
+            return error_show(1004,"参数group_id不能为空");
+        }
+
+        $isT = Db::name("good")->where(["good_name"=>$good_name,"is_del"=>0,"group_id"=>$group_id])->find();
+        if($isT &&  $isT['id']!=$data['id']){
+            return error_show(1004,"商品名称已存在");
+        }
+        $good_desc = isset($this->post['good_desc'])&&$this->post['good_desc']!=""?trim($this->post['good_desc']):"";
+        $good_unit = isset($this->post['good_unit'])&&$this->post['good_unit']!=""?trim($this->post['good_unit']):"";
+        if($good_unit==""){
+            return error_show(1004,"参数good_unit不能为空");
+        }
+
+        $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
+        if($good_img==""){
+            return error_show(1004,"参数good_img不能为空");
+        }
+        $origin_place =  isset($this->post['origin_place'])&&$this->post['origin_place']!=""?trim($this->post['origin_place']):"";
+        $datas=[
+            "good_name"=>$good_name,
+            "good_desc"=>$good_desc,
+            "good_unit"=>$good_unit,
+            "good_img"=>$good_img,
+            "origin_place"=>$origin_place,
+            "group_id"=>$group_id,
+            "updatetime"=>date("Y-m-d H:i:s")
+        ];
+        $in = Db::name("good")->where($data)->save($datas);
+        if($in){
+            return app_show(0,"编辑成功");
+        }else{
+            return error_show(1004,"编辑失败");
+        }
+    }
+
+    public function delete(){
+        $id = isset($this->post['id'])&&$this->post['id']!=""? intval($this->post['id']):"";
+        if($id===""){
+            return error_show(1004,"参数id不能为空");
+        }
+        $data = Db::name("good")->where(["id"=>$id,"is_del"=>0])->find();
+        if($data==false){
+            return error_show(1004,"未找到商品数据");
+        }
+        $data['is_del']=1;
+        $data['updatetime']=date("Y-m-d H:i:s");
+        $del = Db::name("good")->save($data);
+        if($del){
+            return app_show(0,"删除成功");
+        }else{
+            return error_show(1004,"删除失败");
+        }
+    }
+
+    public function status(){
+        $id = isset($this->post['id'])&&$this->post['id']!=""? intval($this->post['id']):"";
+        if($id===""){
+            return error_show(1004,"参数id不能为空");
+        }
+        $data = Db::name("good")->where(["id"=>$id,"is_del"=>0])->find();
+        if($data==false){
+            return error_show(1004,"未找到商品数据");
+        }
+        $status = isset($this->post['status'])&&$this->post['status']!=""? intval($this->post['status']):"";
+        if($status===""){
+            return error_show(1004,"参数status不能为空");
+        }
+        $msg = $status==1?"启用":"禁用";
+        $data['status']=$status;
+        $data['updatetime']=date("Y-m-d H:i:s");
+        $del = Db::name("good")->save($data);
+        if($del){
+            return app_show(0,"{$msg}成功");
+        }else{
+            return error_show(1004,"{$msg}失败");
+        }
+    }
+
+    public function info(){
+        $id = isset($this->post['id'])&&$this->post['id']!=""? intval($this->post['id']):"";
+        if($id===""){
+            return error_show(1004,"参数id不能为空");
+        }
+        $data = Db::name("good")->where(["id"=>$id,"is_del"=>0])->find();
+        if($data==false){
+            return error_show(1004,"未找到商品数据");
+        }
+        $creater =  Db::name("admin")->where(["id"=>$data['createrid']])->find();
+        $data['creater'] = isset($creater['username']) ? $creater['username']:"";
+        return app_show(0,"获取成功",$data);
+    }
+}

+ 6 - 0
application/Admin/controller/Order.php

@@ -21,6 +21,10 @@ class Order extends Base
         if ($status !== "") {
             $where['a.status'] = $status;
         }
+        $type = isset($this->post['type']) && $this->post['type'] !== "" ? intval($this->post['type']) : "";
+        if ($type !== "") {
+            $where['e.account_type'] = $type;
+        }
         $username = isset($this->post['username']) && $this->post['username'] !== "" ? trim($this->post['username']) : "";
         if ($username != "") {
             $where['e.username'] = ["like", "%{$username}%"];
@@ -82,6 +86,7 @@ class Order extends Base
 	`c`.`contector` AS `contector`,
 	`c`.`mobile` AS `contector_mobile`,
 	`e`.`username` AS `username`,
+	`e`.`account_type` AS `account_type`,
 	`g`.`nickname` AS `nickname`,
 	`g`.`mobile` AS `mobile`,
 	`a`.`unit_weight` AS `unit_weight`,
@@ -170,6 +175,7 @@ class Order extends Base
 	c.contector '收货人',
 	c.mobile '收货电话',
 	v.nickname '用户名',
+	k.account_type '账户类型',
 	v.mobile AS '用户电话'
 FROM
 	fc_order a

+ 28 - 50
application/Home/controller/Order.php

@@ -128,36 +128,36 @@ class Order extends Base
         if($num==""){
             return error_show(1004,"参数num 不能为空或0");
         }
-        $id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']): "";
-        if($id==""){
-            return error_show(1004,"unit_id不能为空");
-        }
-        $kg= Db::name('unit')->where(["is_del" => 0,"id"=>$id,"status"=>1])->field("id,name,weight,limit_num")->find();
-       // var_dump(Db::name('unit')->where(["is_del" => 0,"id"=>$id,"status"=>1])->getLastSql());
-        if(empty($kg)){
-            return error_show(1004,"单位不能为空");
-        }
-        $count=$num*$kg['weight'];
-        if($count==""){
-            return error_show(1004,"购买数量不能为空");
-        }
-        if($kg['limit_num']>0){
-            $zl = Db::name('order_log')->where(["unit_id"=>$id,"accountid"=>$this->userinfo['id']])->sum('num');
-          // var_dump(Db::name('order_log')->getLastSql());
-
-            if($zl+$num>$kg['limit_num']){
-                $jf = $kg['limit_num']>=$zl ?$kg['limit_num']-$zl :0;
-                return error_show(1004,"购买数量超过限额,可购数量{$jf}{$kg['name']}");
-            }
-
-        }
+//        $id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']): "";
+//        if($id==""){
+//            return error_show(1004,"unit_id不能为空");
+//        }
+//        $kg= Db::name('unit')->where(["is_del" => 0,"id"=>$id,"status"=>1])->field("id,name,weight,limit_num")->find();
+//       // var_dump(Db::name('unit')->where(["is_del" => 0,"id"=>$id,"status"=>1])->getLastSql());
+//        if(empty($kg)){
+//            return error_show(1004,"单位不能为空");
+//        }
+//        $count=$num*$kg['weight'];
+//        if($count==""){
+//            return error_show(1004,"购买数量不能为空");
+//        }
+//        if($kg['limit_num']>0){
+//            $zl = Db::name('order_log')->where(["unit_id"=>$id,"accountid"=>$this->userinfo['id']])->sum('num');
+//          // var_dump(Db::name('order_log')->getLastSql());
+//
+//            if($zl+$num>$kg['limit_num']){
+//                $jf = $kg['limit_num']>=$zl ?$kg['limit_num']-$zl :0;
+//                return error_show(1004,"购买数量超过限额,可购数量{$jf}{$kg['name']}");
+//            }
+//
+//        }
 
         $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']<$count){
+        if(empty($stock) || $stock['stock_balance']<$num){
             return error_show(1004,"库存数量不足");
         }
         $addr =Db::name("rela_addr")->alias('a')->join("addr b","a.addrid=b.id","left")->where(["a.accountid"=>$this->userinfo['id'],
@@ -172,8 +172,6 @@ class Order extends Base
                 "order_sn"=>$ordersn,
                 "accountid"=>$this->userinfo['id'],
                 "order_num"=>$num,
-                "unit"=>$kg['name'],
-                "unit_weight"=>$kg['weight'],
                 "is_del"=>0,
                 "status"=>1,
                 "addtime"=>date("Y-m-d H:i:s"),
@@ -196,29 +194,24 @@ class Order extends Base
                 $orderpost=Db::name("order_post")->insert($post);
                 if($orderpost){
                    $updatestock= Db::name("account_stock")->where($stock)->update
-                    (['stock_balance'=>$stock['stock_balance']-$count,
-                        "stock_delivery"=>$stock['stock_delivery']+$count,"updatetime"=>date("Y-m-d H:i:s")]);
+                    (['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"=>$count,
+                           "run_stock"=>$num,
                            "type"=>3,
-                           "after_stock"=>$stock['stock_balance']-$count,
+                           "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);
                        $log=[
                            "accountid"=>$this->userinfo['id'],
                            "addtime"=>date("Y-m-d H:i:s"),
-                            "unit"=>$kg['name'],
-                           "unit_weight"=>$kg['weight'],
                            "num"=>$num,
-                           "total_weight"=>$num*$kg['weight'],
-                           "unit_id"=>$kg['id']
                        ];
                        $st =Db::name("order_log")->insert($log);
                        if($stocklog && $st){
@@ -240,21 +233,6 @@ class Order extends Base
         $stock = Db::name("account_stock")->where(["accountid"=>$this->userinfo['id'],'is_del'=>0])->find();
         $data=[];
         $data['stock'] = isset($stock['stock_balance']) ? $stock['stock_balance']:0;
-        $unit = Db::name('unit')->where(['is_del'=>0,'status'=>1])->field("id,name,weight,limit_num")->select();
-        $limit=[];
-        foreach ($unit as $value){
-            $zl =0;
-            $num = intval($data['stock']/$value['weight']);
-            if($value['limit_num']>0){
-                $zl = Db::name('order_log')->where(["unit_id"=>$value['id'],"accountid"=>$this->userinfo['id']])->sum('num');
-                $value['limit_num']>$zl?$value['limit_num'] -= $zl:$value['limit_num']=0;
-                $value['limit_num'] = $value['limit_num']>$num  ? $num : $value['limit_num'];
-            }else{
-                $value['limit_num'] = $num ;
-            }
-            $limit[]=$value;
-        }
-        $data['limit']=$limit;
         return app_show(0,"获取成功",$data);
     }
 }