Cat.php 25 KB

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