wugg пре 2 година
родитељ
комит
3ac8cf5028
3 измењених фајлова са 222 додато и 0 уклоњено
  1. 2 0
      app/admin/controller/Base.php
  2. 214 0
      app/admin/controller/CatPlat.php
  3. 6 0
      app/admin/route/app.php

+ 2 - 0
app/admin/controller/Base.php

@@ -11,6 +11,7 @@ class Base extends \app\BaseController
 {
     public  $post=[];
     public  $uid='';
+    public  $uname='';
     public function __construct(App $app)
     {
         parent::__construct($app);
@@ -30,6 +31,7 @@ class Base extends \app\BaseController
         }
 
         $this->uid=isset($effetc['data']['user']['id']) ?$effetc['data']['user']['id']:"";
+        $this->uname=isset($effetc['data']['user']['nickname']) ?$effetc['data']['user']['nickname']:"";
         $uid = Db::name("user_role")->where(['uid'=>$this->uid,"is_del"=>0,"status"=>1])->find();
         if($uid==false || $uid['status']==0){
             return error_show(102,'账户已禁用');

+ 214 - 0
app/admin/controller/CatPlat.php

@@ -0,0 +1,214 @@
+<?php
+
+
+namespace app\admin\controller;
+
+use think\facade\Db;
+use think\App;class CatPlat extends Base{
+    public function __construct(App $app) {parent::__construct($app);}
+    /**@params  cat_id plat_id rate  分类 平台 税率
+    * @return \think\response\Json|void
+     */
+    public function add(){
+        $post =$this->post;
+        $catid =isset($post['cat_id'])&&$post['cat_id']!=="" ? intval($post['cat_id']):"";
+        if($catid==""){
+           return error_show(1004,"参数 cat_id 不能为空");
+        }
+        $catinfo = Db::name("cat")->where(["id"=>$catid,"is_del"=>0])->find();
+        if($catinfo==false){
+            return error_show(1004,"分类信息不存在");
+        }
+        $plat_id =isset($post['plat_id'])&&$post['plat_id']!=="" ? intval($post['plat_id']):"";
+        if($plat_id==""){
+           return error_show(1004,"参数 plat_id 不能为空");
+        }
+        $platform = Db::name("platform")->where(["id"=>$plat_id,"is_del"=>0])->find();
+        if($platform==false){
+            return error_show(1004,"平台信息不存在");
+        }
+         $rate =isset($post['rate'])&&$post['rate']!=="" ? floor($post['rate']):"";
+        if($rate==""){
+           return error_show(1004,"参数 rate 不能为空");
+        }
+        $data=[
+            "cat_id"=>$catid,
+            "platform_id"=>$plat_id,
+            "rate"=>$rate,
+            "status"=>1,
+            "is_del"=>0,
+            "apply_id"=>$this->uid,
+            "apply_name"=>$this->uname,
+            "addtime"=>date("Y-m-d H:i:s"),
+            "updatetime"=>date("Y-m-d H:i:s"),
+        ];
+        $int = Db::name("cat_plat")->insert($data);
+        return $int ? app_show(0,"新建成功"): error_show(1003,"新建失败");
+    }
+
+    public  function edit(){
+        $post = $this->post;
+         $catid =isset($post['cat_id'])&&$post['cat_id']!=="" ? intval($post['cat_id']):"";
+        if($catid==""){
+           return error_show(1004,"参数 cat_id 不能为空");
+        }
+        $catinfo = Db::name("cat")->where(["id"=>$catid,"is_del"=>0])->find();
+        if($catinfo==false){
+            return error_show(1004,"分类信息不存在");
+        }
+        $cat = Db::name("cat_plat")->where(["cat_id"=>$catid,"is_del"=>0])->find();
+        if($cat==false){
+          return error_show(1004,"分类未设置平台毛利率");
+        }
+
+        $plat_id =isset($post['plat_id'])&&$post['plat_id']!=="" ? intval($post['plat_id']):"";
+        if($plat_id==""){
+           return error_show(1004,"参数 plat_id 不能为空");
+        }
+        $platform = Db::name("platform")->where(["id"=>$plat_id,"is_del"=>0])->find();
+        if($platform==false){
+            return error_show(1004,"平台信息不存在");
+        }
+         $rate =isset($post['rate'])&&$post['rate']!=="" ? floor($post['rate']):"";
+        if($rate==""){
+           return error_show(1004,"参数 rate 不能为空");
+        }
+        $data=[
+            "cat_id"=>$catid,
+            "platform_id"=>$plat_id,
+            "rate"=>$rate,
+            "apply_id"=>$this->uid,
+            "apply_name"=>$this->uname,
+            "updatetime"=>date("Y-m-d H:i:s")
+        ];
+        $int = Db::name("cat_plat")->where($cat)->update($data);
+        return $int ? app_show(0,"更新成功"): error_show(1003,"更新失败");
+    }
+        /**列表
+        * @return \think\response\Json|void
+        * @throws \think\db\exception\DataNotFoundException
+        * @throws \think\db\exception\DbException
+        * @throws \think\db\exception\ModelNotFoundException
+         */
+    public function  list(){
+        $post=$this->post;
+        $page = isset($post['page'])&&$post['page']!=""?intval($post['page']) :"1";
+        $size = isset($post['size'])&&$post['size']!=""?intval($post['size']) :"15";
+        $condition = [["is_del","=",0]];
+        $catid=  isset($post['cat_id'])&&$post['cat_id']!=""?intval($post['cat_id']) :"";
+        if($catid!="") $condition[]=["cat_id","=",$catid];
+        $platid=  isset($post['plat_id'])&&$post['plat_id']!=""?intval($post['plat_id']) :"";
+        if($platid!="") $condition[]=["plat_id","=",$platid];
+
+        $count = Db::name("cat_plat")->where($condition)->count();
+        $total = ceil($count/$size);
+        $page = $total> $page ? $page: intval($total);
+        $list =Db::name("cat_plat")->where($condition)->page($page,$size)->select()->toArray();
+        $catKey=[];
+        if(!empty($list)){
+            $catArr = array_column("cat_id",$list);
+            $catKey= Db::name("cat")->where(["id"=>$catArr,"is_del"=>0])->column("cat_name","id");
+        }
+        $data=[];
+        foreach ($list as $key=>$value){
+            $value['cat_name'] = isset($catKey[$value['cat_id']]) ?$catKey[$value['cat_id']]:"";
+            $data[]=$value;
+        }
+        return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
+    }
+   //启禁用分类平台信息
+    public function  status(){
+         $post = $this->post;
+         $catid =isset($post['cat_id'])&&$post['cat_id']!=="" ? intval($post['cat_id']):"";
+        if($catid==""){
+           return error_show(1004,"参数 cat_id 不能为空");
+        }
+        $catinfo = Db::name("cat")->where(["id"=>$catid,"is_del"=>0])->find();
+        if($catinfo==false){
+            return error_show(1004,"分类信息不存在");
+        }
+        $cat = Db::name("cat_plat")->where(["cat_id"=>$catid,"is_del"=>0])->find();
+        if($cat==false){
+          return error_show(1004,"分类未设置平台毛利率");
+        }
+        $status = isset($post['status'])&&$post['status']!=="" ? intval($post['status']):"";
+        if($status===""){
+            return error_show(1004,"参数 status 不能为空");
+        }
+        if(!in_array($status,[0,1])){
+            return error_show(1004,"参数 status 无效值");
+        }
+        $cat['status']=$status;
+        $cat['updatetime']=date("Y-m-d H:i:s");
+         $int = Db::name("cat_plat")->save($cat);
+        return $int ? app_show(0,"更新成功"): error_show(1003,"更新失败");
+    }
+    //删除分类平台信息
+    public function delete(){
+        $post = $this->post;
+         $catid =isset($post['cat_id'])&&$post['cat_id']!=="" ? intval($post['cat_id']):"";
+        if($catid==""){
+           return error_show(1004,"参数 cat_id 不能为空");
+        }
+        $catinfo = Db::name("cat")->where(["id"=>$catid,"is_del"=>0])->find();
+        if($catinfo==false){
+            return error_show(1004,"分类信息不存在");
+        }
+        $cat = Db::name("cat_plat")->where(["cat_id"=>$catid,"is_del"=>0])->find();
+        if($cat==false){
+          return error_show(1004,"分类未设置平台毛利率");
+        }
+        $cat['is_del']=1;
+        $cat['updatetime']=date("Y-m-d H:i:s");
+         $int = Db::name("cat_plat")->save($cat);
+        return $int ? app_show(0,"删除成功"): error_show(1003,"删除失败");
+    }
+    //根据毛利率计算平台价格
+    public function  PlatPrice(){
+         $spuCode=isset($this->post['spuCode'])&&$this->post['spuCode']!=""? trim($this->post['spuCode']):"";
+        if($spuCode==""){
+            return error_show(1005,"参数spuCode不能为空");
+        }
+        $platid=  isset($post['plat_id'])&&$post['plat_id']!=""?intval($post['plat_id']) :"";
+        if($platid=="") return error_show(1005,"参数 plat_id 不能为空");
+        $good =Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->find();
+        if($good==false){
+            return error_show(1005,"商品数据未找到");
+        }
+        $nakelist = Db::name("good_nake")
+            ->where(['spuCode'=>$spuCode,"is_del"=>0])
+            ->order("min_num asc")
+            ->find();
+//        if($nakelist==false){
+//            $nakelist = Db::name("good_nake")->where(['spuCode'=>$spuCode,"is_del"=>0])->order("min_num asc")->find();
+//
+//            //非库存品的话,继续校验最小起订量
+//            //库存品的话,不足采购起订量的时候,取采购最小起订量
+//            if ($good['is_stock'] == 0) return error_show(1010, "起订量不足{$nakelist['min_num']}");
+//        }
+        $catinfo = Db::name("cat_plat")->where(["cat_id"=>$good['cat_id'],"is_del"=>0,"plat_id"=>$platid])->find();
+        if ($catinfo==false)  return error_show(1005,"分类未设置平台毛利率");
+        $budget = isset($catinfo['rate']) ? $catinfo['rate']/100:0;
+        $top_cat_id = made($catinfo['cat_id']);//获取所有分类
+        $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
+
+        $sale_cost_fee = 0;
+        if ($good['is_gold_price'] == 1 && $top_cat_id == 6) {
+//            $saleprice =  $good['noble_weight']*$good["cgd_gold_price"] + $nakelist['cost_fee']/(1-$budget)*$good['noble_weight']+$nakelist['mark_fee']+$nakelist['package_fee']+$nakelist['cert_fee']+$nakelist['nake_fee']+$nakelist['delivery_fee'];
+
+            //系统售价=(贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用)/(1-成本售价/100)
+            $saleprice = ($good['noble_weight'] * $good["cgd_gold_price"] + $nakelist['cost_fee'] * $good['noble_weight'] + $nakelist['mark_fee'] + $nakelist['package_fee'] + $nakelist['cert_fee'] + $nakelist['nake_fee'] + $nakelist['delivery_fee'] + $nakelist['other_fee']) / (1 - $budget);
+
+            //计算工艺费
+            //销售工艺费=(( 商品重量* 供应商采购金价 + 采购成本工艺费* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)/(1-成本售价/100)-(包装费+加标费+证书费+产品裸价0+运费+其他费用) )/商品重量-供应商采购金价
+            $sale_cost_fee = (($good['noble_weight'] * $good["cgd_gold_price"] + $nakelist['cost_fee'] * $good['noble_weight'] + $nakelist['package_fee'] + $nakelist['mark_fee'] + $nakelist['cert_fee'] + $nakelist['nake_fee'] + $nakelist['other_fee'] + $nakelist['delivery_fee']) / (1 - $budget) - ($nakelist['package_fee'] + $nakelist['mark_fee'] + $nakelist['cert_fee'] + $nakelist['nake_fee'] + $nakelist['delivery_fee'] + $nakelist['other_fee'])) / $good['noble_weight'] - $good["cgd_gold_price"];
+        }else{
+//            $saleprice = ($nakelist['mark_fee'] + $nakelist['package_fee'] + $nakelist['cert_fee'] + $nakelist['delivery_fee'] + $nakelist['nake_fee']) / (1 - $budget);
+//            (加标费+包装费+证书费+成本裸价+运费)/(1-成本售价/100)=系统售价
+//            $saleprice = (加标费 + 包装费 + 证书费 + 运费 + 成本裸价+其他费用) / (1 - $budget);
+            $saleprice = $nakelist['nake_total'] / (1 - $budget);
+        }
+        return app_show(0, "获取成功", ["sale_price" => round($saleprice, 2), 'new_cost_fee' => round($sale_cost_fee, 2)]);
+
+    }
+}

+ 6 - 0
app/admin/route/app.php

@@ -573,6 +573,12 @@ Route::rule('seoonae','admin/SaleReport/orderOutNotAddrExport');//无地址待
 Route::rule('seooa','admin/SaleReport/orderOutAddr');//有地址待发货单列表
 Route::rule('seooae','admin/SaleReport/orderOutAddrExport');//有地址待发货单列表-导出
 
+Route::rule("catplatadd","admin/CatPlat/add");
+Route::rule("catplatedit","admin/CatPlat/edit");
+Route::rule("catplatlist","admin/CatPlat/list");
+Route::rule("catplatstatus","admin/CatPlat/status");
+Route::rule("catplatdel","admin/CatPlat/delete");
+Route::rule("platprice","admin/CatPlat/PlatPrice");
 
 Route::rule('statlist','admin/Stat/list');//