|
@@ -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)]);
|
|
|
+
|
|
|
+ }
|
|
|
+}
|