Project.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\facade\Db;
  5. class Project extends \app\BaseController
  6. {
  7. private $post=[];
  8. public function __construct(App $app)
  9. {
  10. parent::__construct($app);
  11. $this->post=$this->request->post();
  12. }
  13. public function create(){
  14. $name = isset($this->post['name'])&&$this->post['name']!=""? trim($this->post['name']):"";
  15. if($name==""){
  16. return error_show(1004,"参数name不能为空");
  17. }
  18. $platform = isset($this->post['platform'])&&$this->post['platform']!=""? trim($this->post['platform']):"";
  19. if($platform==""){
  20. return error_show(1004,"参数platform不能为空");
  21. }
  22. $khNo = isset($this->post['khNo'])&&$this->post['khNo']!=""?trim($this->post['khNo']):"";
  23. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""?trim($this->post['supplierNo']):"";
  24. if($khNo==""){
  25. return error_show(1004,"参数khNo不能为空");
  26. }
  27. if($supplierNo==""){
  28. return error_show(1004,"参数supplierNo不能为空");
  29. }
  30. $use_desc = isset($this->post['use_desc'])&&$this->post['use_desc']!=""?trim($this->post['use_desc']):"";
  31. $budget_total = isset($this->post['budget_total'])&&$this->post['budget_total']!=""?floatval($this->post['budget_total']):"";
  32. $arrtime = isset($this->post['arrtime'])&&$this->post['arrtime']!=""?$this->post['arrtime']:"";
  33. if($use_desc==""){
  34. return error_show(1004,"参数use_desc不能为空");
  35. }
  36. if($budget_total==""){
  37. return error_show(1004,"参数budget_total不能为空");
  38. }
  39. if($arrtime==""){
  40. return error_show(1004,"参数arrtime不能为空");
  41. }
  42. $low_rate = isset($this->post['low_rate'])&&$this->post['low_rate']!=""?floatval($this->post['low_rate']):"";
  43. if($low_rate==""){
  44. return error_show(1004,"参数low_rate不能为空");
  45. }
  46. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder'])? $this->post['ladder']:"";
  47. if($ladder==""){
  48. return error_show(1004,"参数ladder不能为空");
  49. }
  50. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  51. if($token==''){
  52. return error_show(1005,"参数token不能为空");
  53. }
  54. $user =GetUserInfo($token);
  55. if(empty($user)||$user['code']!=0){
  56. return error_show(1002,"用户数据不存在");
  57. }
  58. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  59. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  60. Db::startTrans();
  61. try {
  62. $projectNo = makeNo("PRO");
  63. $data=[
  64. "projectNo"=>$projectNo,
  65. "platform_id"=>$platform,
  66. "khNo"=>$khNo,
  67. "project_name"=>$name,
  68. "budget_total"=>$budget_total,
  69. "use_desc"=>$use_desc,
  70. "low_rate"=>$low_rate,
  71. "creater"=>$creater,
  72. "createrid"=>$createrid,
  73. "status"=>1,
  74. "is_del"=>0,
  75. "addtime"=>date("Y-m-d H:i:s"),
  76. "updatetime"=>date("Y-m-d H:i:s")
  77. ];
  78. $pro=Db::name("good_project")->insert($data);
  79. if($pro){
  80. if(!empty($ladder)){
  81. $la=[];
  82. foreach ($ladder as $value){
  83. $pgNo = makeNo("PRI");
  84. $temp=[];
  85. $temp['pgNo']=$pgNo;
  86. $temp['projectNo']=$projectNo;
  87. $temp['good_type']=$value['good_type'];
  88. $temp['good_name']=$value['good_name'];
  89. $temp['good_img']=$value['good_img'];
  90. $temp['cat_id']=$value['cat_id'];
  91. $temp['budget_price']=$value['budget_price'];
  92. $temp['num']=$value['num'];
  93. $temp['creater']=$creater;
  94. $temp['createrid']=$createrid;
  95. $temp['status']=1;
  96. $temp['is_del']=0;
  97. $temp['addtime']=date("Y-m-d H:i:s");
  98. $temp['updatetime']=date("Y-m-d H:i:s");
  99. $la[]=$temp;
  100. }
  101. $in = Db::name("project_info")->insertAll($la);
  102. if($in>0){
  103. Db::commit();
  104. return app_show(0,"项目新建成功",['projectNo'=>$projectNo]);
  105. }
  106. }
  107. }
  108. Db::rollback();
  109. return error_show(1004,"项目新建失败");
  110. }catch (\Exception $e){
  111. Db::rollback();
  112. return error_show(1004,$e->getMessage());
  113. }
  114. }
  115. public function addfeed(){
  116. $pgNo =isset($this->post['pgNo']) && $this->post['pgNo']!=""? trim($this->post['pgNo']):"";
  117. if($pgNo==""){
  118. return error_show(1004,"参数pgNo不能为空");
  119. }
  120. $projectinfo = Db::name("project_info")->where(["pgNo"=>$pgNo,"is_del"=>0])->find();
  121. if($projectinfo==false){
  122. return error_show(1004,"未找到项目阶梯信息");
  123. }
  124. $spuCode =isset($this->post['spuCode'])&&!empty($this->post['spuCode']) ?$this->post['spuCode']:"";
  125. if($spuCode==""){
  126. return error_show(1004,"参数spuCode不能为空");
  127. }
  128. $source =isset($this->post['source'])&&$this->post['source']!=="" ?intval($this->post['source']):"";
  129. if($source==""){
  130. return error_show(1004,"参数source不能为空");
  131. }
  132. $good=[];
  133. if($source==1){
  134. $good=Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->select()->toArray();
  135. if(empty($good)){
  136. return error_show(1004,"未找到商品信息");
  137. }
  138. }
  139. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  140. if($token==''){
  141. return error_show(1005,"参数token不能为空");
  142. }
  143. $user =GetUserInfo($token);
  144. if(empty($user)||$user['code']!=0){
  145. return error_show(1002,"用户数据不存在");
  146. }
  147. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  148. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  149. Db::startTrans();
  150. try{
  151. $data=[];
  152. foreach ($good as $value){
  153. $temp=[];
  154. $temp['spuCode']=$value['spuCode'];
  155. $temp['pgNo']=$projectinfo['pgNo'];
  156. $temp['projectNo']=$projectinfo['projectNo'];
  157. $temp['good_name']=$value['good_name'];
  158. $temp['good_type']=$projectinfo['good_type'];
  159. $temp['data_source']=$source;
  160. $temp['cat_id']=$value['cat_id'];
  161. $temp['budget_price']=$projectinfo['budget_price'];
  162. $temp['sale_price']=$value['sale_price'];
  163. $temp['num']=$projectinfo['num'];
  164. $temp['status']=0;
  165. $temp['is_del']=0;
  166. $temp['creater']=$creater;
  167. $temp['createrid']=$createrid;
  168. $temp['addtime']=date("Y-m-d H:i:s");
  169. $temp['updatetime']=date("Y-m-d H:i:s");
  170. $data[]=$temp;
  171. }
  172. $nu = Db::name("project_feeback")->insertAll($data);
  173. if($nu>0){
  174. Db::commit();
  175. return app_show(0,"添加成功");
  176. }else{
  177. Db::rollback();
  178. return app_show(0,"添加成功");
  179. }
  180. }catch (\Exception $e){
  181. Db::rollback();
  182. return error_show(1004,$e->getMessage());
  183. }
  184. }
  185. public function list(){
  186. $page =isset($this->post['page'])&&$this->post['page']!=="" ? intval($this->post['page']):1;
  187. $size =isset($this->post['size'])&&$this->post['size']!==""? intval($this->post['size']):10;
  188. $where=[["is_del","=",0]];
  189. $khNo = isset($this->post['khNo']) &&$this->post['khNo']!==""? trim($this->post['khNo']):"";
  190. if($khNo!==""){
  191. $where[]=["khNo","=",$khNo];
  192. }
  193. $project_name = isset($this->post['project_name']) &&$this->post['project_name']!==""? trim($this->post['project_name']):"";
  194. if($project_name!==""){
  195. $where[]=["project_name","like","%$project_name%"];
  196. }
  197. $status = isset($this->post['status']) &&$this->post['status']!==""? intval($this->post['status']):"";
  198. if($status!==""){
  199. $where[]=["status","=",$status];
  200. }
  201. $start = isset($this->post['start'])&&$this->post['start']!=="" ? $this->post['start']:"";
  202. if($start!==''){
  203. $where[]=["addtime",">=",$start];
  204. }
  205. $end = isset($this->post['end'])&&$this->post['end']!=="" ? $this->post['end']:"";
  206. if($end!==''){
  207. $where[]=["addtime","<=",$end];
  208. }
  209. $low = isset($this->post['low'])&&$this->post['low']!=="" ? floatval($this->post['low']):"";
  210. if($low!==''){
  211. $where[]=["budget_total",">=",$low];
  212. }
  213. $up = isset($this->post['up'])&&$this->post['up']!=="" ? floatval($this->post['up']):"";
  214. if($up!==''){
  215. $where[]=["budget_total","<=",$up];
  216. }
  217. $count = Db::name('project')->where($where)->count();
  218. $total = ceil($count / $size);
  219. $page = $page >= $total ? $total : $page;
  220. $list = Db::name('project')->where($where)->page($page,$size)->order("addtime desc")->select();
  221. $data=[];
  222. foreach ($list as $value){
  223. $info = Db::name("platform")->where(['id'=>$value['platform_id']])->find();
  224. $value['platform_name']=isset($info['platform_name'])?$info['platform_name']:"";
  225. $value['platform_code']=isset($info['platform_code'])?$info['platform_code']:"";
  226. $khinfo = Db::name("customer_info")->where(["companyNo"=>$value['khNo']])->find();
  227. $value['khName'] = isset($khinfo['CompanyName'])?$khinfo['CompanyName']:"";
  228. $data[]=$value;
  229. }
  230. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  231. }
  232. public function feedlist(){
  233. $page =isset($this->post['page'])&&$this->post['page']!=="" ? intval($this->post['page']):1;
  234. $size =isset($this->post['size'])&&$this->post['size']!==""? intval($this->post['size']):10;
  235. $where=[["is_del","=",0]];
  236. $pgNo =isset($this->post['pgNo'])&&$this->post['pgNo']!==""?trim($this->post['pgNo']):"";
  237. if($pgNo!==""){
  238. $where[]=["pgNo","=",$pgNo];
  239. }
  240. $source =isset($this->post['source'])&&$this->post['source']!==""?intval($this->post['source']):"";
  241. if($source!==""){
  242. $where[]=["data_source","=",$source];
  243. }
  244. $cat_id =isset($this->post['cat_id'])&&$this->post['cat_id']!==""?intval($this->post['cat_id']):"";
  245. if($cat_id!==""){
  246. $where[]=["cat_id","=",$cat_id];
  247. }
  248. $count = Db::name('project_feedback')->where($where)->count();
  249. $total = ceil($count / $size);
  250. $page = $page >= $total ? $total : $page;
  251. $list = Db::name('project_feedback')->where($where)->page($page,$size)->order("addtime desc")->select();
  252. return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
  253. }
  254. public function info(){
  255. $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  256. if($projectNo==""){
  257. return error_show(1004,"参数projectNo不能为空");
  258. }
  259. $type = isset($this->post['type'])&&$this->post['type']!=="" ? intval($this->post['type']) :0;
  260. $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
  261. if($info==false){
  262. return error_show(1004,"未找到项目信息");
  263. }
  264. $plat = Db::name("platform")->where(['id'=>$info['platform_id']])->find();
  265. $info['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  266. $info['platform_code']=isset($plat['platform_code'])?$plat['platform_code']:"";
  267. $khinfo = Db::name("customer_info")->where(["companyNo"=>$plat['khNo']])->find();
  268. $info['khName'] = isset($khinfo['CompanyName'])?$khinfo['CompanyName']:"";
  269. $ladder = Db::name("project_info")->where(['projectNo'=>$projectNo,"is_del"=>0])->select()->toArray();
  270. $info['ladder']=[];
  271. if(!empty($ladder)){
  272. foreach ($ladder as $value){
  273. $value["cat_info"]=isset($value['cat_id'])? made($value['cat_id'],[]):[];
  274. $condition = $type==0?['pgNo'=>$value['pgNo'],"is_del"=>0] : ['pgNo'=>$value['pgNo'],"is_del"=>0,"status"=>1];
  275. $feedback = Db::name("project_info")->where($condition)->select()->toArray();
  276. array_walk($feedback,function (&$v){
  277. $v["cat_info"]=isset($v['cat_id'])? made($v['cat_id'],[]):[];
  278. });
  279. $value['feedback']=$feedback;
  280. $info['ladder'][]=$value;
  281. }
  282. }
  283. return app_show(0,"获取成功",$info);
  284. }
  285. public function plan_create(){
  286. $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  287. if($projectNo==""){
  288. return error_show(1004,"参数projectNo不能为空");
  289. }
  290. $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
  291. if($info==false){
  292. return error_show(1004,"未找到项目信息");
  293. }
  294. $feedback =isset($this->post['feedback'])&&!empty($this->post['feedback'])?$this->post['feedback']:"";
  295. if($feedback==""){
  296. return error_show(1004,"参数feedback不能为空");
  297. }
  298. $feedinfo = Db::name("project_feedback")->where(['id'=>$feedback,"projectNo"=>$projectNo,"is_del"=>0])
  299. ->select()->toArray();
  300. if(empty($feedinfo)){
  301. return error_show(1004,"反馈数据未找到");
  302. }
  303. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  304. if($token==''){
  305. return error_show(1005,"参数token不能为空");
  306. }
  307. $user =GetUserInfo($token);
  308. if(empty($user)||$user['code']!=0){
  309. return error_show(1002,"用户数据不存在");
  310. }
  311. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  312. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  313. Db::startTrans();
  314. try {
  315. $planNo=makeNo("PLA");
  316. $total=0;
  317. $dl=[];
  318. foreach ($feedinfo as $value){
  319. $temp=[];
  320. $temp['planNo']=$planNo;
  321. $temp['feedback_id']=$value['id'];
  322. $temp['status']=1;
  323. $temp['is_del']=0;
  324. $temp['addtime']=date("Y-m-d H:i:s");
  325. $temp['updatetime']=date("Y-m-d H:i:s");
  326. $total+=$value['num']*$value['sale_price'];
  327. $dl[]=$temp;
  328. }
  329. $inn=Db::name("project_plan_rela")->insertAll($dl);
  330. if($inn>0){
  331. $data=[
  332. "planNo"=>$planNo,
  333. "projectNo"=>$projectNo,
  334. "createrid"=>$createrid,
  335. "creater"=>$creater,
  336. "sale_total"=>round($total,2),
  337. "status"=>0,
  338. "is_del"=>1,
  339. "addtime"=>date("Y-m-d H:i:s"),
  340. "updatetime"=>date("Y-m-d H:i:s")
  341. ];
  342. $up =Db::name("project_plan")->insert($data);
  343. if($up){
  344. Db::commit();
  345. return app_show(0,"方案制作成功",["planNo"=>$planNo]);
  346. }
  347. }
  348. Db::rollback();
  349. return error_show(1004,"方案制作失败");
  350. }catch (\Exception $e){
  351. Db::rollback();
  352. return error_show(1004,$e->getMessage());
  353. }
  354. }
  355. public function planinfo(){
  356. $planNo = isset($this->post['planNo'])&& $this->post['planNo']!==""?trim($this->post["planNo"]):"";
  357. if($planNo==""){
  358. return error_show(1004,"参数planNo不能为空");
  359. }
  360. $plan = Db::name("project_plan")->where(["planNo"=>$planNo,"is_del"=>0])->find();
  361. if($plan==false){
  362. return error_show(1004,"未找到项目方案信息");
  363. }
  364. $plan['feedback']=[];
  365. $feedback =Db::name("preject_plan_rela")->where(["planNo"=>$planNo,"is_del"=>0])->column("feedback_id");
  366. if(!empty($feedback)){
  367. $feedlist = Db::name("project_feedback")->where(["id"=>$feedback,"is_del"=>0])->select();
  368. if(!empty($feedlist)){
  369. foreach ($feedlist as $value){
  370. $value["cat_info"]=isset($value['cat_id'])? made($value['cat_id'],[]):[];
  371. $plan['feedback'][]=$value;
  372. }
  373. }
  374. }
  375. return app_show(0,"获取成功",$plan);
  376. }
  377. public function project_plan(){
  378. $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  379. if($projectNo==""){
  380. return error_show(1004,"参数projectNo不能为空");
  381. }
  382. $type = isset($this->post['type'])&&$this->post['type']!=="" ? intval($this->post['type']) :0;
  383. $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
  384. if($info==false){
  385. return error_show(1004,"未找到项目信息");
  386. }
  387. $plat = Db::name("platform")->where(['id'=>$info['platform_id']])->find();
  388. $info['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  389. $info['platform_code']=isset($plat['platform_code'])?$plat['platform_code']:"";
  390. $khinfo = Db::name("customer_info")->where(["companyNo"=>$plat['khNo']])->find();
  391. $info['khName'] = isset($khinfo['CompanyName'])?$khinfo['CompanyName']:"";
  392. $ladder = Db::name("project_plan")->where(['projectNo'=>$projectNo,"is_del"=>0])->select()->toArray();
  393. $info['plan']=[];
  394. if(!empty($ladder)){
  395. foreach ($ladder as $value){
  396. $value['feedback']=[];
  397. $feedback =Db::name("preject_plan_rela")->where(["planNo"=>$value['planNo'],"is_del"=>0])->column("feedback_id");
  398. if(!empty($feedback)){
  399. $feedlist = Db::name("project_feedback")->where(["id"=>$feedback,"is_del"=>0])->select();
  400. if(!empty($feedlist)){
  401. foreach ($feedlist as $value){
  402. $value["cat_info"]=isset($value['cat_id'])? made($value['cat_id'],[]):[];
  403. $plan['feedback'][]=$value;
  404. }
  405. }
  406. }
  407. $info['ladder'][]=$value;
  408. }
  409. }
  410. return app_show(0,"获取成功",$info);
  411. }
  412. public function feedCheck(){
  413. $feedid = isset($this->post['feedid'])&&!empty($this->post['feedid']) ? $this->post['feedid'] :[];
  414. if(empty($feedid)){
  415. return error_show(1004,"参数feedid不能为空");
  416. }
  417. $selec = Db::name("project_feedback")->where(["id"=>$feedid,'is_del'=>0,"status"=>0])->select();
  418. if(empty($selec)){
  419. return error_show(1004,"反馈数据信息未找到");
  420. }
  421. $up = Db::name("project_feedback")->where(["id"=>$feedid,'is_del'=>0,"status"=>0])->save(["stauts"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  422. if($up){
  423. return app_show(0,"反馈数据选择成功");
  424. }else{
  425. return error_show(1004,"反馈数据选择失败");
  426. }
  427. }
  428. public function planCheck(){
  429. $planNos = isset($this->post['planNos'])&&$this->post['planNos']!==""? trim($this->post['planNos']) :[];
  430. if($planNos==""){
  431. return error_show(1004,"参数planNos不能为空");
  432. }
  433. $status=isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  434. if($status==""){
  435. return error_show(1004,"参数status不能为空");
  436. }
  437. $selec = Db::name("project_plan")->where(["planNo"=>$planNos,'is_del'=>0,"status"=>0])->select();
  438. if(empty($selec)){
  439. return error_show(1004,"项目方案数据信息未找到");
  440. }
  441. $up = Db::name("project_plan")->where(["planNo"=>$planNos,'is_del'=>0,"status"=>0])->save(["stauts"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  442. if($up){
  443. return app_show(0,"方案数据修改成功");
  444. }else{
  445. return error_show(1004,"方案数据修改失败");
  446. }
  447. }
  448. public function changeRate(){
  449. $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  450. if($projectNo==""){
  451. return error_show(1004,"参数projectNo不能为空");
  452. }
  453. $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
  454. if($info==false){
  455. return error_show(1004,"未找到项目信息");
  456. }
  457. $rate = isset($this->post['rate'])&&$this->post['rate']!=="" ?floatval($this->post['rate']):"";
  458. if($rate===""){
  459. return error_show(1004,"参数rate不能为空");
  460. }
  461. $info['low_rate']=$rate;
  462. $info['updatetime']=date("Y-m-d H:i:s");
  463. $up =Db::name("project")->save($info);
  464. if($up){
  465. return app_show(0,"利润率修改成功");
  466. }else{
  467. return app_show(0,"利润率修改失败");
  468. }
  469. }
  470. }