Cat.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ChangeLog;
  5. use app\BaseController;
  6. use think\App;
  7. use think\facade\Db;
  8. class Cat extends BaseController
  9. {
  10. public $post="";
  11. public function __construct(App $app)
  12. {
  13. parent::__construct($app);
  14. $this->post=$this->request->post();
  15. }
  16. public function list(){
  17. $where=[["is_del","=",0]];
  18. $pid = isset($this->post['pid']) &&$this->post['pid']!=="" ?intval($this->post['pid']): "0";
  19. $where[]=["pid","=",$pid];
  20. $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? intval($this->post['cat_name']) :"";
  21. if($cat_name!==""){
  22. $where[]=['cat_name',"like","%$cat_name%"];
  23. }
  24. $data = Db::name("cat")->where($where)->select();
  25. $vmp = [];
  26. foreach ($data as $sts){
  27. $vmp[]=stro($sts);
  28. }
  29. return app_show(0,"获取成功",$vmp);
  30. }
  31. public function plist(){
  32. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
  33. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  34. $where =[["is_del","=",0]];
  35. $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
  36. if($cat_name!==""){
  37. $where[]=['cat_name',"like","%$cat_name%"];
  38. }
  39. $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
  40. if($pid!==""){
  41. $where[]=['pid',"=",$pid];
  42. }
  43. $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
  44. if($status!==""){
  45. $where[]=['status',"=",$status];
  46. }
  47. $count = Db::name("cat")->where($where)->count();
  48. $total = ceil($count / $size);
  49. $page = $page >= $total ? $total : $page;
  50. $list = Db::name('cat')->where($where)->page($page, $size)->select();
  51. $var =[];
  52. foreach ($list as $value){
  53. $info = Db::name('cat_specs')->where(['cat_id'=>$value['id'],'is_del'=>0])->column('specs_id');
  54. $temp = Db::name('specs')->where(['id'=>$info,'is_del'=>0])->field("id as specid,spec_name")->select()->toArray();
  55. if(empty($temp)){
  56. $temp=[];
  57. }
  58. $value['im']=$temp;
  59. $var[]=$value;
  60. }
  61. return app_show(0, "获取成功", ['list' =>$var, 'count' => $count]);
  62. }
  63. public function wlist(){
  64. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
  65. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  66. $where =[["is_del","=",0],['level',"=",3]];
  67. $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
  68. if($cat_name!==""){
  69. $where[]=['cat_name',"like","%$cat_name%"];
  70. }
  71. $search=isset($this->post['search']) && $this->post['search'] !==""? trim($this->post['search']) :"";
  72. if($search!==""){
  73. $where[]=['search',"like","%$search%"];
  74. }
  75. $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
  76. if($pid!==""){
  77. $where[]=['pid',"=",$pid];
  78. }
  79. $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
  80. if($status!==""){
  81. $where[]=['status',"=",$status];
  82. }
  83. $count = Db::name("cat")->where($where)->count();
  84. $total = ceil($count / $size);
  85. $page = $page >= $total ? $total : $page;
  86. $list = Db::name('cat')->where($where)->page($page, $size)->select();
  87. $data=[];
  88. foreach ($list as $value){
  89. $temp= isset($value['id']) && $value['id'] !=0 ? made($value['id']):[];
  90. $value['item'] = array_column($temp,'id');
  91. $data[]=$value;
  92. }
  93. return app_show(0, "获取成功", ['list' =>$data, 'count' => $count]);
  94. }
  95. public function title(){
  96. $where =[["is_del","=",0]];
  97. $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
  98. if($cat_name!==""){
  99. $where[]=['cat_name',"like","%$cat_name%"];
  100. }
  101. $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
  102. if($pid!==""){
  103. $where[]=["pid","=",$pid];
  104. }
  105. $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
  106. if($status!==""){
  107. $where[]=['status',"=",$status];
  108. }
  109. $list = Db::name('cat')->where($where)->select();
  110. return app_show(0, "获取成功",$list);
  111. }
  112. public function tlist(){
  113. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  114. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  115. $where =[['is_del',"=",0]];
  116. $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
  117. if($cat_name!==""){
  118. $where[]=['cat_name',"like","%$cat_name%"];
  119. }
  120. $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
  121. if($status!==""){
  122. $where[]=['status',"=",$status];
  123. }
  124. $creater=isset($this->post['creater']) && $this->post['creater'] !==""? trim($this->post['creater']) :"";
  125. if($creater!==""){
  126. $where[]=['creater',"like","%$creater%"];
  127. }
  128. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  129. if($start!==""){
  130. $where[]=['addtime',">=",$start];
  131. }
  132. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  133. if($end !==""){
  134. $where[]=['addtime',"<=",$end];
  135. }
  136. $count = Db::name('cat')->where($where)->count();
  137. $total = ceil($count / $size);
  138. $page = $page >= $total ? $total : $page;
  139. $list = Db::name('cat')->where($where)->page($page, $size)->select();
  140. $var =[];
  141. foreach ($list as $value){
  142. $info = Db::name('cat_specs')->where(['cat_id'=>$value['id'],'is_del'=>0])->column('specs_id');
  143. $temp = Db::name('specs')->where(['id'=>$info,'is_del'=>0])->field("id as specid,spec_name")->select()->toArray();
  144. if(empty($temp)){
  145. $temp=[];
  146. }
  147. $value['im']=$temp;
  148. $var[]=$value;
  149. }
  150. return app_show(0, "获取成功", ['list' => $var, 'count' => $count]);
  151. }
  152. public function create()
  153. {
  154. $cat_name = isset($this->post['cat_name']) && $this->post['cat_name'] !== "" ? trim($this->post['cat_name']) : "";
  155. if ($cat_name == "") {
  156. return error_show(1002, "参数cat_name不能为空");
  157. }
  158. $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? intval($this->post['pid']) : "0";
  159. if ($pid === "") {
  160. return error_show(1002, "参数pid不能为空");
  161. }
  162. $cat_desc = isset($this->post['cat_desc']) && $this->post['cat_desc'] !== "" ? trim($this->post['cat_desc']) : "";
  163. $fund_code = isset($this->post['fund_code']) && $this->post['fund_code'] !== "" ? trim($this->post['fund_code']) : "";
  164. $level =1;
  165. if ($pid !== 0) {
  166. $levl=Db::name('cat')->where(['id'=>$pid])->find();
  167. if(empty($levl)){
  168. return error_show(1002,"未找到父级数据");
  169. }
  170. $level =$levl['level']+1;
  171. $temp = $levl['search'];
  172. }
  173. if($level==1){
  174. $search = $cat_name;
  175. }else{
  176. $search= $temp."-".$cat_name;
  177. }
  178. $repeat_name = Db::name("cat")->where(["is_del"=>0,"cat_name"=>$cat_name])->find();
  179. $int =isset($repeat_name['id']) && $repeat_name['id'] != 0 ? made($repeat_name['id']) : [];
  180. $im = array_column($int,'name');
  181. $in=implode('/',$im);
  182. if(!empty($repeat_name)){
  183. return error_show(1004,"分类名称已在{$in}存在");
  184. }
  185. $specs_id = isset($this->post['specs_id']) && $this->post['specs_id'] !== "" ? $this->post['specs_id'] : [];
  186. if (empty($specs_id)) {
  187. return error_show(1002, "参数specs_id不能为空");
  188. }
  189. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  190. if($token==''){
  191. return error_show(105,"参数token不能为空");
  192. }
  193. $user =GetUserInfo($token);
  194. if(empty($user)||$user['code']!=0){
  195. return error_show(102,"创建人数据不存在");
  196. }
  197. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  198. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  199. // $rate = isset($this->post['rate']) && $this->post['rate'] !== "" ? intval($this->post['rate']) : "";
  200. // $order_rate = isset($this->post['order_rate']) && $this->post['order_rate'] !== "" ? intval($this->post['order_rate']) : "";
  201. // $sale_rate = isset($this->post['sale_rate ']) && $this->post['sale_rate '] !== "" ? intval($this->post['sale_rate ']) : "";
  202. // $lower_rate = isset($this->post['lower_rate']) && $this->post['lower_rate'] !== "" ? intval($this->post['lower_rate']) : "";
  203. $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? intval($this->post['weight']) : "0";
  204. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
  205. Db::startTrans();
  206. try{
  207. $data = [
  208. "cat_name" => $cat_name,
  209. "pid" => $pid,
  210. "level" => $level,
  211. "search" => $search,
  212. // "rate" => $rate,
  213. // "lower_rate"=>$lower_rate,
  214. // "order_rate"=>$order_rate,
  215. // "sale_rate"=>$sale_rate,
  216. "weight" => $weight,
  217. "status" => $status,
  218. "cat_desc"=>$cat_desc,
  219. "fund_code"=>$fund_code,
  220. "creater"=>$creater,
  221. "createrid"=>$createrid,
  222. "is_del"=>0,
  223. "addtime" => date("Y-m-d H:i:s"),
  224. "updatetime" => date("Y-m-d H:i:s"),
  225. ];
  226. $datainfo = Db::name('cat')->insert($data,true);
  227. $vat =[];
  228. if ($datainfo>0) {
  229. $stx = ["order_code"=>$pid,"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
  230. ActionLog::logAdd($this->post['token'],$stx,"sxd",$status,$stx);
  231. $spc =[];
  232. $spc['cat_id']=$datainfo;
  233. $spc['exam_status']=0;
  234. $spc['status']=0;
  235. $spc['creater']=$creater;
  236. $spc['createrid']=$createrid;
  237. $spc['is_del']=0;
  238. $spc['addtime']=date("Y-m-d H:i:d");
  239. $spc['updatetime']=date("Y-m_d H:i:s");
  240. $vpn = Db::name('cat_spec')->insert($spc,true);
  241. if ($vpn == "") {
  242. Db::rollback();
  243. return error_show(1002, "新建失败");
  244. }
  245. foreach ($specs_id as $value){
  246. $item =[];
  247. $item['cat_id']=$datainfo;
  248. $item['specs_id']=$value;
  249. $item['is_del']=0;
  250. $item['addtime']=date("Y-m-d H:i:s");
  251. $vat[] = $item;
  252. }
  253. $vp = Db::name('cat_specs')->insertAll($vat);
  254. if ($vp==0) {
  255. Db::rollback();
  256. return error_show(1005, "新建失败");
  257. }
  258. Db::commit();
  259. return error_show(0, "新建成功");
  260. } else {
  261. Db::rollback();
  262. return error_show(1002, "新建失败");
  263. }
  264. }catch (\Exception $e){
  265. Db::rollback();
  266. return error_show(1005,$e->getMessage());
  267. }
  268. }
  269. public function edit(){
  270. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  271. $idinfo = Db::name('cat')->where(['id'=>$id])->find();
  272. if($idinfo==""){
  273. return error_show(1002,"未找到商品数据");
  274. }
  275. $cat_name= isset($this->post['cat_name']) && $this->post['cat_name'] !=="" ? trim($this->post['cat_name']) :"";
  276. if($cat_name==""){
  277. return error_show(1002,"参数cat_name不能为空");
  278. }
  279. $pid = isset($this->post['pid']) && $this->post['pid'] !=="" ? intval($this->post['pid']) :"";
  280. if($pid===""){
  281. return error_show(1002,"参数pid不能为空");
  282. }
  283. $cat_desc = isset($this->post['cat_desc']) && $this->post['cat_desc'] !=="" ? trim($this->post['cat_desc']) :"";
  284. $fund_code = isset($this->post['fund_code']) && $this->post['fund_code'] !== "" ? trim($this->post['fund_code']) : "";
  285. $specs_id = isset($this->post['specs_id']) && $this->post['specs_id'] !== "" ? $this->post['specs_id'] : [];
  286. if (empty($specs_id)) {
  287. return error_show(1002, "参数specs_id不能为空");
  288. }
  289. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  290. if($token==''){
  291. return error_show(105,"参数token不能为空");
  292. }
  293. $user =GetUserInfo($token);
  294. if(empty($user)||$user['code']!=0){
  295. return error_show(102,"创建人数据不存在");
  296. }
  297. $level =1;
  298. if ($pid !== 0) {
  299. $levl=Db::name('cat')->where(['id'=>$pid])->find();
  300. if(empty($levl)){
  301. return error_show(1002,"未找到父级数据");
  302. }
  303. $level =$levl['level']+1;
  304. $temp = $levl['search'];
  305. }
  306. if($level==1){
  307. $search = $cat_name;
  308. }else{
  309. $search= $temp."_".$cat_name;
  310. }
  311. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  312. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  313. //$level = isset($this->post['level']) && $this->post['level'] !=="" ? intval($this->post['level']) :"";
  314. $weight = isset($this->post['weight']) && $this->post['weight']!==""? intval($this->post['weight']):"0";
  315. $status = isset($this->post['status']) && $this->post['status'] !==""?intval($this->post['status']) :"0";
  316. Db::startTrans();
  317. try{
  318. $str = [
  319. "id"=>$id,
  320. "cat_name"=>$cat_name,
  321. "pid"=>$pid,
  322. "level"=>$level,
  323. "weight"=>$weight,
  324. // "status"=>$status,
  325. "cat_desc"=>$cat_desc,
  326. "is_del"=>0,
  327. "fund_code"=>$fund_code,
  328. "updatetime"=>date("Y-m-d H:i:s"),
  329. "search"=>$search
  330. ];
  331. $strinfo = Db::name('cat')->where(['id'=>$id])->save($str);
  332. $temp = array_diff($str,$idinfo);
  333. $json = json_encode($temp,JSON_UNESCAPED_UNICODE);
  334. $jsp = json_encode($idinfo,JSON_UNESCAPED_UNICODE);
  335. if($strinfo){
  336. $order = ["order_code"=>$id,"status"=>$status,"action_remark"=>'',"action_type"=>"edit"];
  337. ActionLog::logAdd($this->post['token'],$order,"sxd",$status,$order);
  338. ChangeLog::logAdd(7,$idinfo['id'],$jsp,$json,$this->post['token'],$this->post);
  339. $spc =[];
  340. $vp = Db::name('cat_spec')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->find();
  341. $str ="";
  342. if($vp!=false){
  343. isset($vp['id']) && $vp['id'] !== "" ? $spc['id'] = $vp['id'] : '';
  344. $spc['cat_id']=$idinfo['id'];
  345. $spc['exam_status']=0;
  346. $spc['status']=0;
  347. $spc['is_del']=0;
  348. $spc['updatetime']=date("Y-m_d H:i:s");
  349. $str=$vp['id'];
  350. $vpn = Db::name('cat_spec')->save($spc);
  351. }else{
  352. $spc['cat_id']=$idinfo['id'];
  353. $spc['exam_status']=0;
  354. $spc['status']=0;
  355. $spc['creater']=$creater;
  356. $spc['createrid']=$createrid;
  357. $spc['is_del']=0;
  358. $spc['addtime']=date("Y-m-d H:i:d");
  359. $spc['updatetime']=date("Y-m_d H:i:s");
  360. $vpn = Db::name('cat_spec')->insert($spc,true);
  361. $str=$vpn;
  362. }
  363. if ($vpn == false) {
  364. Db::rollback();
  365. return error_show(1002, "更新失败");
  366. }
  367. $db = Db::name('cat_specs')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->column("specs_id");
  368. if(empty($db)){
  369. $db=[];
  370. }
  371. $sn = array_diff($specs_id,$db);
  372. $st = array_diff($db,$specs_id);
  373. if(!empty($st)){
  374. $int['is_del']=1;
  375. $dn = Db::name('cat_specs')->where(['specs_id'=>$st,'is_del'=>0])->save($int);
  376. if ($dn==false) {
  377. Db::rollback();
  378. return error_show(1002, "编辑失败");
  379. }
  380. }
  381. if(!empty($sn)){
  382. $vat=[];
  383. foreach ($sn as $value){
  384. $item=[];
  385. $item['cat_id']=$idinfo['id'];
  386. $item['specs_id']=$value;
  387. $item['is_del']=0;
  388. $item['addtime'] = date("Y-m-d H:i:s");
  389. $vat[] = $item;
  390. }
  391. $vp = Db::name('cat_specs')->insertAll($vat);
  392. if ($vp==0) {
  393. Db::rollback();
  394. return error_show(1002, "编辑失败");
  395. }
  396. }
  397. $itn =sear($id);
  398. Db::commit();
  399. return error_show(0,"编辑成功");
  400. }else{
  401. Db::rollback();
  402. return error_show(1002,"编辑失败");
  403. }
  404. }catch (\Exception $e){
  405. Db::rollback();
  406. return error_show(1005,$e->getMessage());
  407. }
  408. }
  409. public function ratedit(){
  410. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  411. $idinfo = Db::name('cat')->where(['id'=>$id])->find();
  412. if($idinfo==""){
  413. return error_show(1002,"未找到商品数据");
  414. }
  415. $rate = isset($this->post['rate']) && $this->post['rate'] !== "" ? floatval($this->post['rate']) : "";
  416. $order_rate = isset($this->post['order_rate']) && $this->post['order_rate'] !== "" ? floatval($this->post['order_rate']) : "";
  417. $sale_rate = isset($this->post['sale_rate']) && $this->post['sale_rate'] !== "" ? floatval($this->post['sale_rate']) : "";
  418. $lower_rate = isset($this->post['lower_rate']) && $this->post['lower_rate'] !== "" ? floatval($this->post['lower_rate']) :"";
  419. $money_rate = isset($this->post['money_rate']) && $this->post['money_rate'] !=="" ? floatval($this->post['money_rate']):"";
  420. $low_rate = isset($this->post['low_rate']) && $this->post['low_rate'] !=="" ? floatval($this->post['low_rate']):"";
  421. if($idinfo['pid']==0){
  422. if($rate===""){
  423. return error_show(1003,"参数rate不能为空");
  424. }
  425. if($order_rate===""){
  426. return error_show(1003,"参数order_rate不能为空");
  427. }
  428. if($sale_rate===""){
  429. return error_show(1003,"参数sale_rate不能为空");
  430. }
  431. if($lower_rate===""){
  432. return error_show(1003,"参数lower_rate不能为空");
  433. }
  434. if($money_rate==""){
  435. return error_show(1003,"参数money_rate不能为空");
  436. }
  437. if($low_rate==""){
  438. return error_show(1003,"参数low_rate不能为空");
  439. }
  440. }
  441. $data =[
  442. "id"=>$id,
  443. "rate" => $rate,
  444. "lower_rate"=>$lower_rate,
  445. "order_rate"=>$order_rate,
  446. "sale_rate"=>$sale_rate,
  447. "money_rate"=>$money_rate,
  448. "low_rate"=>$low_rate,
  449. "is_del"=>0,
  450. "updatetime"=>date("Y-m-d H:i:s"),
  451. ];
  452. $strinfo = Db::name('cat')->where(['id'=>$id])->save($data);
  453. if($strinfo){
  454. return error_show(0,"更新成功");
  455. }else{
  456. return error_show(1002,"更新失败");
  457. }
  458. }
  459. public function info(){
  460. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  461. if($id==""){
  462. return error_show(1002,"参数id不能为空");
  463. }
  464. $idinfo = Db::name('cat')->where(['id'=>$id])->find();
  465. if($idinfo==""){
  466. return error_show(1002,"未找到数据");
  467. }
  468. $info = Db::name('cat_specs')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->column('specs_id');
  469. $temp = Db::name('specs')->where(['id'=>$info,'is_del'=>0])->field("id,spec_name")->select();
  470. //$idinfo['cat_id']=$info['cat_id'];
  471. $idinfo['spec']=$temp;
  472. // $idinfo['specs_id']=$info;
  473. return app_show(0,"获取成功",$idinfo);
  474. }
  475. public function status(){
  476. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  477. if($id===""){
  478. return error_show(1002,"参数id不能为空");
  479. }
  480. $stn = Db::name('cat')->where(['id'=>$id])->find();
  481. if(empty($stn)){
  482. return error_show(1002,"未找到商品数据");
  483. }
  484. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  485. if($status===""){
  486. return error_show(1002,"参数status不能为空");
  487. }
  488. if ($stn['level']==3) {
  489. if($status==1){
  490. $can = made($stn['id']);
  491. $cat=array_column($can,'id');
  492. }else{
  493. $cat =$stn['id'];
  494. }
  495. // return error_show(1002, "所在级别不能启用");
  496. }
  497. if($stn['level']==2 || $stn['level']==1){
  498. if($status==1){
  499. return error_show(1002,"所在等级不能启用");
  500. }else{
  501. $db= Db::name('cat')->where(['pid'=>$stn['id'],'status'=>1,'is_del'=>0])->count();
  502. if($db==0){
  503. $cat = $stn['id'];
  504. }else{
  505. return error_show(1002,"子级分类未禁用");
  506. }
  507. }
  508. }
  509. // $pd= $stn['status'];
  510. $it=[];
  511. $it['status']=$status;
  512. $it['updatetime']=date("Y-m-d H:i:s");
  513. $str = Db::name('cat')->where(['id'=>$cat,'is_del'=>0])->save($it);
  514. if($str){
  515. // $order = ["order_code"=>$id,"status"=>$pd,"action_remark"=>'',"action_type"=>"edit"];
  516. // ActionLog::logAdd($this->post['token'],$order,"sxd",$stn['status'],$order);
  517. return error_show(0,"状态更新成功");
  518. }else{
  519. return error_show(1002,"状态更新失败");
  520. }
  521. }
  522. public function delete(){
  523. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  524. $info = Db::name('cat')->where(["is_del"=>0,'id'=>$id])->find();
  525. if($info==false){
  526. return error_show(1002,"未找到数据");
  527. }
  528. $supp= Db::name('cat')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  529. if($supp){
  530. return error_show(0,"删除成功");
  531. }else{
  532. return error_show(1002,"删除失败");
  533. }
  534. }
  535. }