123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\ActionLog;
- use app\admin\model\ChangeLog;
- use app\BaseController;
- use think\App;
- use think\facade\Db;
- //分类
- class Cat extends Base
- {
- public function __construct(App $app)
- {
- parent::__construct($app);
- }
- public function list(){
- $where=[["is_del","=",0]];
- $pid = isset($this->post['pid']) &&$this->post['pid']!=="" ?intval($this->post['pid']): "0";
- $where[]=["pid","=",$pid];
- $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? intval($this->post['cat_name']) :"";
- if($cat_name!==""){
- $where[]=['cat_name',"like","%$cat_name%"];
- }
- $data = Db::name("cat")->where($where)->select();
- $vmp = [];
- foreach ($data as $sts){
- $vmp[]=stro($sts);
- }
- return app_show(0,"获取成功",$vmp);
- }
- public function plist(){
- $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 =[["c.is_del","=",0]];
- $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
- if($cat_name!==""){
- $where[]=['c.cat_name',"like","%$cat_name%"];
- }
- $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
- if($pid!==""){
- $where[]=['c.pid',"=",$pid];
- }
- $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
- if($status!==""){
- $where[]=['c.status',"=",$status];
- }
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
- if ($company_name !== "") $where[] = ["c.createrid", 'in', get_company_item_user_by_name($company_name)];
- $count = Db::name("cat")->alias('c')->where($where)->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('cat')
- ->alias('c')
- ->field('c.*,u.itemid')
- ->leftJoin("depart_user u", "u.uid=c.createrid AND u.is_del=0")
- ->where($where)
- ->page($page, $size)
- ->cursor();
- $var =[];
- foreach ($list as $value){
- $info = Db::name('cat_specs')->where(['cat_id'=>$value['id'],'is_del'=>0])->column('specs_id');
- $temp = Db::name('specs')->where(['id'=>$info,'is_del'=>0])->field("id as specid,spec_name")->select()->toArray();
- if(empty($temp)){
- $temp=[];
- }
- $value['im']=$temp;
- $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
- $var[]=$value;
- }
- return app_show(0, "获取成功", ['list' =>$var, 'count' => $count]);
- }
- public function wlist(){
- $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 =[["is_del","=",0],['level',"=",3]];
- $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
- if($cat_name!==""){
- $where[]=['cat_name',"like","%$cat_name%"];
- }
- $search=isset($this->post['search']) && $this->post['search'] !==""? trim($this->post['search']) :"";
- if($search!==""){
- $where[]=['search',"like","%$search%"];
- }
- $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
- if($pid!==""){
- $where[]=['pid',"=",$pid];
- }
- $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
- if($status!==""){
- $where[]=['status',"=",$status];
- }
- $count = Db::name("cat")->where($where)->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('cat')->where($where)->page($page, $size)->select();
- $data=[];
- foreach ($list as $value){
- $temp= isset($value['id']) && $value['id'] !=0 ? made($value['id']):[];
- $value['item'] = array_column($temp,'id');
- $data[]=$value;
- }
- return app_show(0, "获取成功", ['list' =>$data, 'count' => $count]);
- }
- public function title(){
- $where =[["is_del","=",0]];
- $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
- if($cat_name!==""){
- $where[]=['cat_name',"like","%$cat_name%"];
- }
- $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
- if($pid!==""){
- $where[]=["pid","=",$pid];
- }
- $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
- if($status!==""){
- $where[]=['status',"=",$status];
- }
- $list = Db::name('cat')->where($where)->select();
- return app_show(0, "获取成功",$list);
- }
- public function tlist(){
- $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 =[['c.is_del',"=",0]];
- $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
- if($cat_name!==""){
- $where[]=['c.cat_name',"like","%$cat_name%"];
- }
- $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
- if($status!==""){
- $where[]=['c.status',"=",$status];
- }
- $creater=isset($this->post['creater']) && $this->post['creater'] !==""? trim($this->post['creater']) :"";
- if($creater!==""){
- $where[]=['c.creater',"like","%$creater%"];
- }
- $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
- if($start!==""){
- $where[]=['c.addtime',">=",$start];
- }
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
- if($end !==""){
- $where[]=['c.addtime',"<=",$end];
- }
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
- if ($company_name !== "") $where[] = ["c.createrid", 'in', get_company_item_user_by_name($company_name)];
- $count = Db::name('cat')->alias('c')->where($where)->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('cat')
- ->alias('c')
- ->field('c.*,u.itemid')
- ->leftJoin("depart_user u", "u.uid=c.createrid AND u.is_del=0")
- ->where($where)
- ->page($page, $size)
- ->cursor();
- $var =[];
- foreach ($list as $value){
- $info = Db::name('cat_specs')->where(['cat_id'=>$value['id'],'is_del'=>0])->column('specs_id');
- $temp = Db::name('specs')->where(['id'=>$info,'is_del'=>0])->field("id as specid,spec_name")->select()->toArray();
- if(empty($temp)){
- $temp=[];
- }
- $value['im']=$temp;
- $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
- $var[]=$value;
- }
- return app_show(0, "获取成功", ['list' => $var, 'count' => $count]);
- }
- public function create()
- {
- $cat_name = isset($this->post['cat_name']) && $this->post['cat_name'] !== "" ? trim($this->post['cat_name']) : "";
- if ($cat_name == "") {
- return error_show(1002, "参数cat_name不能为空");
- }
- $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? intval($this->post['pid']) : "0";
- if ($pid === "") {
- return error_show(1002, "参数pid不能为空");
- }
- $cat_desc = isset($this->post['cat_desc']) && $this->post['cat_desc'] !== "" ? trim($this->post['cat_desc']) : "";
- $fund_code = isset($this->post['fund_code']) && $this->post['fund_code'] !== "" ? trim($this->post['fund_code']) : "";
- $level =1;
- if ($pid !== 0) {
- $levl=Db::name('cat')->where(['id'=>$pid])->find();
- if(empty($levl)){
- return error_show(1002,"未找到父级数据");
- }
- $level =$levl['level']+1;
- $temp = $levl['search'];
- }
- if($level==1){
- $search = $cat_name;
- }else{
- $search= $temp."-".$cat_name;
- }
- $repeat_name = Db::name("cat")->where(["is_del"=>0,"cat_name"=>$cat_name])->find();
- $int =isset($repeat_name['id']) && $repeat_name['id'] != 0 ? made($repeat_name['id']) : [];
- $im = array_column($int,'name');
- $in=implode('/',$im);
- if(!empty($repeat_name)){
- return error_show(1004,"分类名称已在{$in}存在");
- }
- $specs_id = isset($this->post['specs_id']) && $this->post['specs_id'] !== "" ? $this->post['specs_id'] : [];
- if (empty($specs_id)) {
- return error_show(1002, "参数specs_id不能为空");
- }
- $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(105,"参数token不能为空");
- }
- $user =GetUserInfo($token);
- if(empty($user)||$user['code']!=0){
- return error_show(102,"创建人数据不存在");
- }
- $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? intval($this->post['weight']) : "0";
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
- Db::startTrans();
- try{
- $data = [
- "cat_name" => $cat_name,
- "pid" => $pid,
- "level" => $level,
- "search" => $search,
- "weight" => $weight,
- "status" => $status,
- "cat_desc"=>$cat_desc,
- "fund_code"=>$fund_code,
- "creater"=>$creater,
- "createrid"=>$createrid,
- "is_del"=>0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- ];
- $datainfo = Db::name('cat')->insert($data,true);
- $vat =[];
- if ($datainfo>0) {
- $stx = ["order_code"=>$pid,"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$stx,"sxd",$status,$stx);
- $spc =[];
- $spc['cat_id']=$datainfo;
- $spc['exam_status']=0;
- $spc['status']=0;
- $spc['creater']=$creater;
- $spc['createrid']=$createrid;
- $spc['is_del']=0;
- $spc['addtime']=date("Y-m-d H:i:d");
- $spc['updatetime']=date("Y-m_d H:i:s");
- $vpn = Db::name('cat_spec')->insert($spc,true);
- if ($vpn == "") {
- Db::rollback();
- return error_show(1002, "新建失败");
- }
- foreach ($specs_id as $value){
- $item =[];
- $item['cat_id']=$datainfo;
- $item['specs_id']=$value;
- $item['is_del']=0;
- $item['addtime']=date("Y-m-d H:i:s");
- $vat[] = $item;
- }
- $vp = Db::name('cat_specs')->insertAll($vat);
- if ($vp==0) {
- Db::rollback();
- return error_show(1005, "新建失败");
- }
- $catinfo=['cat_id'=>$datainfo,'apply_name'=>$creater,"apply_id"=>$createrid,"fund_code"=>$fund_code,"status"=>0];
- $this->addPlat($catinfo);
- Db::commit();
- return error_show(0, "新建成功");
- } else {
- Db::rollback();
- return error_show(1002, "新建失败");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- }
- public function edit(){
- $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
- $idinfo = Db::name('cat')->where(['id'=>$id])->find();
- if($idinfo==""){
- return error_show(1002,"未找到商品数据");
- }
- $cat_name= isset($this->post['cat_name']) && $this->post['cat_name'] !=="" ? trim($this->post['cat_name']) :"";
- if($cat_name==""){
- return error_show(1002,"参数cat_name不能为空");
- }
- $pid = isset($this->post['pid']) && $this->post['pid'] !=="" ? intval($this->post['pid']) :"";
- if($pid===""){
- return error_show(1002,"参数pid不能为空");
- }
- $cat_desc = isset($this->post['cat_desc']) && $this->post['cat_desc'] !=="" ? trim($this->post['cat_desc']) :"";
- $fund_code = isset($this->post['fund_code']) && $this->post['fund_code'] !== "" ? trim($this->post['fund_code']) : "";
- $specs_id = isset($this->post['specs_id']) && $this->post['specs_id'] !== "" ? $this->post['specs_id'] : [];
- if (empty($specs_id)) {
- return error_show(1002, "参数specs_id不能为空");
- }
- $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(105,"参数token不能为空");
- }
- $user =GetUserInfo($token);
- if(empty($user)||$user['code']!=0){
- return error_show(102,"创建人数据不存在");
- }
- $level =1;
- if ($pid !== 0) {
- $levl=Db::name('cat')->where(['id'=>$pid])->find();
- if(empty($levl)){
- return error_show(1002,"未找到父级数据");
- }
- $level =$levl['level']+1;
- $temp = $levl['search'];
- }
- if($level==1){
- $search = $cat_name;
- }else{
- $search= $temp."_".$cat_name;
- }
- $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- //$level = isset($this->post['level']) && $this->post['level'] !=="" ? intval($this->post['level']) :"";
- $weight = isset($this->post['weight']) && $this->post['weight']!==""? intval($this->post['weight']):"0";
- $status = isset($this->post['status']) && $this->post['status'] !==""?intval($this->post['status']) :"0";
- Db::startTrans();
- try{
- $str = [
- "id"=>$id,
- "cat_name"=>$cat_name,
- "pid"=>$pid,
- "level"=>$level,
- "weight"=>$weight,
- // "status"=>$status,
- "cat_desc"=>$cat_desc,
- "is_del"=>0,
- "fund_code"=>$fund_code,
- "updatetime"=>date("Y-m-d H:i:s"),
- "search"=>$search
- ];
- $strinfo = Db::name('cat')->where(['id'=>$id])->save($str);
- $temp = array_diff($str,$idinfo);
- $json = json_encode($temp,JSON_UNESCAPED_UNICODE);
- $jsp = json_encode($idinfo,JSON_UNESCAPED_UNICODE);
- if($strinfo){
- $order = ["order_code"=>$id,"status"=>$status,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$order,"sxd",$status,$order);
- ChangeLog::logAdd(7,$idinfo['id'],$jsp,$json,$this->post['token'],$this->post);
- $spc =[];
- $vp = Db::name('cat_spec')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->find();
- $str ="";
- if($vp!=false){
- isset($vp['id']) && $vp['id'] !== "" ? $spc['id'] = $vp['id'] : '';
- $spc['cat_id']=$idinfo['id'];
- $spc['exam_status']=0;
- $spc['status']=0;
- $spc['is_del']=0;
- $spc['updatetime']=date("Y-m_d H:i:s");
- $str=$vp['id'];
- $vpn = Db::name('cat_spec')->save($spc);
- }else{
- $spc['cat_id']=$idinfo['id'];
- $spc['exam_status']=0;
- $spc['status']=0;
- $spc['creater']=$creater;
- $spc['createrid']=$createrid;
- $spc['is_del']=0;
- $spc['addtime']=date("Y-m-d H:i:d");
- $spc['updatetime']=date("Y-m_d H:i:s");
- $vpn = Db::name('cat_spec')->insert($spc,true);
- $str=$vpn;
- }
- if ($vpn == false) {
- Db::rollback();
- return error_show(1002, "更新失败");
- }
- $db = Db::name('cat_specs')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->column("specs_id");
- if(empty($db)){
- $db=[];
- }
- $sn = array_diff($specs_id,$db);
- $st = array_diff($db,$specs_id);
- if(!empty($st)){
- $int['is_del']=1;
- $dn = Db::name('cat_specs')->where(['specs_id'=>$st,'is_del'=>0])->save($int);
- if ($dn==false) {
- Db::rollback();
- return error_show(1002, "编辑失败");
- }
- }
- if(!empty($sn)){
- $vat=[];
- foreach ($sn as $value){
- $item=[];
- $item['cat_id']=$idinfo['id'];
- $item['specs_id']=$value;
- $item['is_del']=0;
- $item['addtime'] = date("Y-m-d H:i:s");
- $vat[] = $item;
- }
- $vp = Db::name('cat_specs')->insertAll($vat);
- if ($vp==0) {
- Db::rollback();
- return error_show(1002, "编辑失败");
- }
- }
- $itn =sear($id);
- Db::commit();
- return error_show(0,"编辑成功");
- }else{
- Db::rollback();
- return error_show(1002,"编辑失败");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- }
- public function ratedit(){
- $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
- $idinfo = Db::name('cat')->where(['id'=>$id])->find();
- if($idinfo==""){
- return error_show(1002,"未找到商品数据");
- }
- $rate = isset($this->post['rate']) && $this->post['rate'] !== "" ? floatval($this->post['rate']) : "";
- $order_rate = isset($this->post['order_rate']) && $this->post['order_rate'] !== "" ? floatval($this->post['order_rate']) : "";
- $sale_rate = isset($this->post['sale_rate']) && $this->post['sale_rate'] !== "" ? floatval($this->post['sale_rate']) : "";
- $lower_rate = isset($this->post['lower_rate']) && $this->post['lower_rate'] !== "" ? floatval($this->post['lower_rate']) :"";
- $money_rate = isset($this->post['money_rate']) && $this->post['money_rate'] !=="" ? floatval($this->post['money_rate']):"";
- $low_rate = isset($this->post['low_rate']) && $this->post['low_rate'] !=="" ? floatval($this->post['low_rate']):"";
- if($idinfo['pid']==0){
- if($rate===""){
- return error_show(1003,"参数rate不能为空");
- }
- if($order_rate===""){
- return error_show(1003,"参数order_rate不能为空");
- }
- if($sale_rate===""){
- return error_show(1003,"参数sale_rate不能为空");
- }
- if($lower_rate===""){
- return error_show(1003,"参数lower_rate不能为空");
- }
- if($money_rate==""){
- return error_show(1003,"参数money_rate不能为空");
- }
- if($low_rate==""){
- return error_show(1003,"参数low_rate不能为空");
- }
- }
- $data =[
- "id"=>$id,
- "rate" => $rate,
- "lower_rate"=>$lower_rate,
- "order_rate"=>$order_rate,
- "sale_rate"=>$sale_rate,
- "money_rate"=>$money_rate,
- "low_rate"=>$low_rate,
- "is_del"=>0,
- "updatetime"=>date("Y-m-d H:i:s"),
- ];
- $strinfo = Db::name('cat')->where(['id'=>$id])->save($data);
- if($strinfo){
- return error_show(0,"更新成功");
- }else{
- return error_show(1002,"更新失败");
- }
- }
- public function info(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"参数id不能为空");
- }
- $idinfo = Db::name('cat')->where(['id'=>$id])->find();
- if($idinfo==""){
- return error_show(1002,"未找到数据");
- }
- $info = Db::name('cat_specs')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->column('specs_id');
- $temp = Db::name('specs')->where(['id'=>$info,'is_del'=>0])->field("id,spec_name")->select();
- //$idinfo['cat_id']=$info['cat_id'];
- $idinfo['spec']=$temp;
- // $idinfo['specs_id']=$info;
- return app_show(0,"获取成功",$idinfo);
- }
- public function status(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
- if($id===""){
- return error_show(1002,"参数id不能为空");
- }
- $stn = Db::name('cat')->where(['id'=>$id])->find();
- if(empty($stn)){
- return error_show(1002,"未找到商品数据");
- }
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
- if($status===""){
- return error_show(1002,"参数status不能为空");
- }
- if($status==1){
- if($stn['rate']===""){
- return error_show(1003,"单品修改下限未设置");
- }
- if($stn['order_rate']===""){
- return error_show(1003,"预算成本利率未设置");
- }
- if($stn['sale_rate']===""){
- return error_show(1003,"分类成本售价利率未设置");
- }
- if($stn['lower_rate']===""){
- return error_show(1003,"分类最低毛利率未设置");
- }
- // if($stn['money_rate']==""){
- // return error_show(1003,"分类财务利率未设置");
- // }
- // if($stn['low_rate']==""){
- // return error_show(1003,"分类最低毛利未设置");
- // }
- // if($stn['fund_code']==""){
- // return error_show(1003,"分类核算码未设置");
- // }
- }
- if ($stn['level']==3) {
- if($status==1){
- $can = made($stn['id']);
- $cat=array_column($can,'id');
- }else{
- $cat =$stn['id'];
- }
- // return error_show(1002, "所在级别不能启用");
- }
- if($stn['level']==2 || $stn['level']==1){
- if($status==1){
- return error_show(1002,"所在等级不能启用");
- }else{
- $db= Db::name('cat')->where(['pid'=>$stn['id'],'status'=>1,'is_del'=>0])->count();
- if($db==0){
- $cat = $stn['id'];
- }else{
- return error_show(1002,"子级分类未禁用");
- }
- }
- }
- // $pd= $stn['status'];
- $it=[];
- $it['status']=$status;
- $it['updatetime']=date("Y-m-d H:i:s");
- $str = Db::name('cat')->where(['id'=>$cat,'is_del'=>0])->save($it);
- if($str){
- $catinfo=['cat_id'=>$id,"status"=>$status];
- $this->addPlat($catinfo);
- if (!empty($cat)){
- $catinfo=['cat_id'=> $cat,"status"=>$status];
- $this->addPlat($catinfo);
- }
- return error_show(0,"状态更新成功");
- }else{
- return error_show(1002,"状态更新失败");
- }
- }
- public function delete(){
- $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
- $info = Db::name('cat')->where(["is_del"=>0,'id'=>$id])->find();
- if($info==false){
- return error_show(1002,"未找到数据");
- }
- $supp= Db::name('cat')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
- if($supp){
- return error_show(0,"删除成功");
- }else{
- return error_show(1002,"删除失败");
- }
- }
- /** 平台添加分类 **/
- private function addPlat($cat){
- $plat =Db::name("platform")->where(["platform_type"=>1,"is_del"=>0])->select()->toArray();
- if (empty($plat)){
- return '';
- }
- foreach ($plat as $value){
- $cat['platform_id']=$value['id'];
- $cat['addtime']=date("Y-m-d H:i:s");
- $cat['updatetime']=date("Y-m-d H:i:s");
- $isT = Db::name("cat_plat")->where(["cat_id"=>$cat['cat_id'],"platform_id"=>$cat['platform_id'],"is_del"=>0])->column("cat_id");
- if($isT){
- $data=$cat;
- unset($data['cat_id']);
- unset($data['addtime']);
- Db::name("cat_plat")->where(["cat_id"=>$cat['cat_id'],"platform_id"=>$cat['platform_id'],"is_del"=>0])->update($data);
- }else{
- Db::name("cat_plat")->save($cat);
- }
- }
- }
- }
|