Project.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\facade\Db;
  5. class Project extends Base
  6. {
  7. public function __construct(App $app)
  8. {
  9. parent::__construct($app);
  10. }
  11. public function create(){
  12. $name = isset($this->post['name'])&&$this->post['name']!=""? trim($this->post['name']):"";
  13. if($name==""){
  14. return error_show(1004,"参数name不能为空");
  15. }
  16. $platform = isset($this->post['platform'])&&$this->post['platform']!=""? trim($this->post['platform']):"";
  17. if($platform==""){
  18. return error_show(1004,"参数platform不能为空");
  19. }
  20. $khNo = isset($this->post['khNo'])&&$this->post['khNo']!=""?trim($this->post['khNo']):"";
  21. $companyNo = isset($this->post['companyNo'])&&$this->post['companyNo']!=""?trim($this->post['companyNo']):"";
  22. if($khNo==""){
  23. return error_show(1004,"参数khNo不能为空");
  24. }
  25. if($companyNo==""){
  26. return error_show(1004,"参数companyNo不能为空");
  27. }
  28. $use_desc = isset($this->post['use_desc'])&&$this->post['use_desc']!=""?trim($this->post['use_desc']):"";
  29. $budget_total = isset($this->post['budget_total'])&&$this->post['budget_total']!=""?floatval($this->post['budget_total']):"";
  30. $arrtime = isset($this->post['arrtime'])&&$this->post['arrtime']!=""?$this->post['arrtime']:"";
  31. $endtime = isset($this->post['endtime'])&&$this->post['endtime']!=""?$this->post['endtime']:"";
  32. if($use_desc==""){
  33. return error_show(1004,"参数use_desc不能为空");
  34. }
  35. if($budget_total==""){
  36. return error_show(1004,"参数budget_total不能为空");
  37. }
  38. if($arrtime==""){
  39. return error_show(1004,"参数arrtime不能为空");
  40. }
  41. if($endtime==""){
  42. return error_show(1004,"参数endtime不能为空");
  43. }
  44. $low_rate = isset($this->post['low_rate'])&&$this->post['low_rate']!=""?floatval($this->post['low_rate']):"0";
  45. // if($low_rate==""){
  46. // return error_show(1004,"参数low_rate不能为空");
  47. // }
  48. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder'])? $this->post['ladder']:"";
  49. if($ladder==""){
  50. return error_show(1004,"参数ladder不能为空");
  51. }
  52. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  53. if($token==''){
  54. return error_show(1005,"参数token不能为空");
  55. }
  56. $user =GetUserInfo($token);
  57. if(empty($user)||$user['code']!=0){
  58. return error_show(1002,"用户数据不存在");
  59. }
  60. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  61. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  62. Db::startTrans();
  63. try {
  64. $projectNo = makeNo("PRO");
  65. $data=[
  66. "projectNo"=>$projectNo,
  67. "platform_id"=>$platform,
  68. "khNo"=>$khNo,
  69. "companyNo"=>$companyNo,
  70. "project_name"=>$name,
  71. "budget_total"=>$budget_total,
  72. "use_desc"=>$use_desc,
  73. "low_rate"=>$low_rate,
  74. "creater"=>$creater,
  75. "createrid"=>$createrid,
  76. "arrtime"=>$arrtime,
  77. "endtime"=>$endtime,
  78. "status"=>1,
  79. "is_del"=>0,
  80. "addtime"=>date("Y-m-d H:i:s"),
  81. "updatetime"=>date("Y-m-d H:i:s")
  82. ];
  83. $pro=Db::name("project")->insert($data);
  84. if($pro){
  85. if(!empty($ladder)){
  86. $la=[];
  87. foreach ($ladder as $value){
  88. $pgNo = makeNo("PRI");
  89. $temp=[];
  90. $temp['pgNo']=$pgNo;
  91. $temp['projectNo']=$projectNo;
  92. $temp['good_type']=$value['good_type'];
  93. $temp['good_name']=$value['good_name'];
  94. $temp['good_img']=$value['good_img'];
  95. $temp['cat_id']=$value['cat_id'];
  96. $temp['budget_price']=$value['budget_price'];
  97. $temp['num']=$value['num'];
  98. $temp['creater']=$creater;
  99. $temp['createrid']=$createrid;
  100. $temp['status']=1;
  101. $temp['is_del']=0;
  102. $temp['addtime']=date("Y-m-d H:i:s");
  103. $temp['updatetime']=date("Y-m-d H:i:s");
  104. $la[]=$temp;
  105. }
  106. $in = Db::name("project_info")->insertAll($la);
  107. if($in>0){
  108. Db::commit();
  109. return app_show(0,"项目新建成功",['projectNo'=>$projectNo]);
  110. }
  111. }
  112. }
  113. Db::rollback();
  114. return error_show(1004,"项目新建失败");
  115. }catch (\Exception $e){
  116. Db::rollback();
  117. return error_show(1004,$e->getMessage());
  118. }
  119. }
  120. public function addfeed(){
  121. $pgNo =isset($this->post['pgNo']) && $this->post['pgNo']!=""? trim($this->post['pgNo']):"";
  122. if($pgNo==""){
  123. return error_show(1004,"参数pgNo不能为空");
  124. }
  125. $projectinfo = Db::name("project_info")->where(["pgNo"=>$pgNo,"is_del"=>0])->find();
  126. if($projectinfo==false){
  127. return error_show(1004,"未找到项目阶梯信息");
  128. }
  129. $spuCode =isset($this->post['spuCode'])&&!empty($this->post['spuCode']) ?$this->post['spuCode']:"";
  130. if($spuCode==""){
  131. return error_show(1004,"参数spuCode不能为空");
  132. }
  133. $source =isset($this->post['source'])&&$this->post['source']!=="" ?intval($this->post['source']):"1";
  134. if($source==""){
  135. return error_show(1004,"参数source不能为空");
  136. }
  137. $good=[];
  138. if($source==1){
  139. $good=Db::name("good_platform")->alias("a")->leftJoin("good b","a.spuCode=b.spuCode")->where
  140. (["a.skuCode"=>$spuCode,"a.is_del"=>0])->select()->toArray();
  141. if(empty($good)){
  142. return error_show(1004,"未找到商品信息");
  143. }
  144. }else{
  145. $good=Db::name("consult_bids")->where(["spuCode"=>$spuCode,"is_del"=>0])->select()->toArray();
  146. if(empty($good)){
  147. return error_show(1004,"未找到商品信息");
  148. }
  149. }
  150. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  151. if($token==''){
  152. return error_show(1005,"参数token不能为空");
  153. }
  154. $user =GetUserInfo($token);
  155. if(empty($user)||$user['code']!=0){
  156. return error_show($user['code'],"用户数据不存在");
  157. }
  158. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  159. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  160. Db::startTrans();
  161. try{
  162. $data=[];
  163. foreach ($good as $value){
  164. $temp=[];
  165. $temp['spuCode']=$value['spuCode'];
  166. $temp['skuCode']=isset($value['skuCode'])?$value['skuCode']:"";
  167. $temp['pgNo']=$projectinfo['pgNo'];
  168. $temp['projectNo']=$projectinfo['projectNo'];
  169. $temp['good_name']=$value['good_name'];
  170. $temp['good_type']=$projectinfo['good_type'];
  171. $temp['data_source']=$source;
  172. $temp['cat_id']=$value['cat_id'];
  173. $temp['budget_price']=$projectinfo['budget_price'];
  174. if($source==1){
  175. $ladd = Db::name("good_ladder")->where([["skuCode","=",$value['skuCode']],["min_num","<=",
  176. $projectinfo["num"]],["status","=",1],["is_del","=",0]])->order("min_num desc")->find();
  177. $sale_price = $ladd['sale_price'];
  178. }else{
  179. $sale_price =$value['sale_price'];
  180. }
  181. $temp['sale_price']=$sale_price;
  182. $temp['num']=$projectinfo['num'];
  183. $temp['status']=0;
  184. $temp['is_del']=0;
  185. $temp['creater']=$creater;
  186. $temp['createrid']=$createrid;
  187. $temp['addtime']=date("Y-m-d H:i:s");
  188. $temp['updatetime']=date("Y-m-d H:i:s");
  189. $data[]=$temp;
  190. }
  191. $nu = Db::name("project_feedback")->insertAll($data);
  192. if($nu>0){
  193. $projectinfo['status']=2;
  194. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  195. $up = Db::name("project_info")->save($projectinfo);
  196. if($up){
  197. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  198. ->count();
  199. if($count==0){
  200. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  201. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  202. if($proc){
  203. Db::commit();
  204. return app_show(0,"添加成功");
  205. }
  206. }
  207. }
  208. Db::commit();
  209. return app_show(0,"添加成功");
  210. }else{
  211. Db::rollback();
  212. return error_show(1004,"添加失败");
  213. }
  214. }catch (\Exception $e){
  215. Db::rollback();
  216. return error_show(1004,$e->getMessage());
  217. }
  218. }
  219. public function list(){
  220. $page =isset($this->post['page'])&&$this->post['page']!=="" ? intval($this->post['page']):1;
  221. $size =isset($this->post['size'])&&$this->post['size']!==""? intval($this->post['size']):10;
  222. $where=[["is_del","=",0]];
  223. $khNo = isset($this->post['khNo']) &&$this->post['khNo']!==""? trim($this->post['khNo']):"";
  224. if($khNo!==""){
  225. $where[]=["khNo","=",$khNo];
  226. }
  227. $project_name = isset($this->post['project_name']) &&$this->post['project_name']!==""? trim($this->post['project_name']):"";
  228. if($project_name!==""){
  229. $where[]=["project_name","like","%$project_name%"];
  230. }
  231. $status = isset($this->post['status']) &&$this->post['status']!==""? intval($this->post['status']):"";
  232. if($status!==""){
  233. $where[]=["status","=",$status];
  234. }
  235. $start = isset($this->post['start'])&&$this->post['start']!=="" ? $this->post['start']:"";
  236. if($start!==''){
  237. $where[]=["addtime",">=",$start];
  238. }
  239. $end = isset($this->post['end'])&&$this->post['end']!=="" ? $this->post['end']:"";
  240. if($end!==''){
  241. $where[]=["addtime","<=",$end];
  242. }
  243. $low = isset($this->post['low'])&&$this->post['low']!=="" ? floatval($this->post['low']):"";
  244. if($low!==''){
  245. $where[]=["budget_total",">=",$low];
  246. }
  247. $up = isset($this->post['up'])&&$this->post['up']!=="" ? floatval($this->post['up']):"";
  248. if($up!==''){
  249. $where[]=["budget_total","<=",$up];
  250. }
  251. $companyNo = isset($this->post['companyNo'])&&$this->post['companyNo']!=="" ? trim($this->post['companyNo']):"";
  252. if($companyNo!==''){
  253. $where[]=["companyNo","like","%$companyNo%"];
  254. }
  255. $platform_id = isset($this->post['platform_id'])&&$this->post['platform_id']!=="" ? intval($this->post['platform_id']):"";
  256. if($platform_id!==''){
  257. $where[]=["platform_id","=",$platform_id];
  258. }
  259. $count = Db::name('project')->where($where)->count();
  260. $total = ceil($count / $size);
  261. $page = $page >= $total ? $total : $page;
  262. $list = Db::name('project')->where($where)->page($page,$size)->order("addtime desc")->select();
  263. $data=[];
  264. foreach ($list as $value){
  265. $info = Db::name("platform")->where(['id'=>$value['platform_id']])->find();
  266. $value['platform_name']=isset($info['platform_name'])?$info['platform_name']:"";
  267. $value['platform_code']=isset($info['platform_code'])?$info['platform_code']:"";
  268. $khinfo = Db::name("customer_info")->where(["companyNo"=>$value['khNo']])->find();
  269. $value['khName'] = isset($khinfo['companyName'])?$khinfo['companyName']:"";
  270. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  271. $value['company'] = isset($company['company'])?$company['company']:"";
  272. $data[]=$value;
  273. }
  274. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  275. }
  276. public function feedlist(){
  277. $page =isset($this->post['page'])&&$this->post['page']!=="" ? intval($this->post['page']):1;
  278. $size =isset($this->post['size'])&&$this->post['size']!==""? intval($this->post['size']):10;
  279. $where=[["is_del","=",0]];
  280. $pgNo =isset($this->post['pgNo'])&&$this->post['pgNo']!==""?trim($this->post['pgNo']):"";
  281. if($pgNo!==""){
  282. $where[]=["pgNo","=",$pgNo];
  283. }
  284. $source =isset($this->post['source'])&&$this->post['source']!==""?intval($this->post['source']):"";
  285. if($source!==""){
  286. $where[]=["data_source","=",$source];
  287. }
  288. $cat_id =isset($this->post['cat_id'])&&$this->post['cat_id']!==""?intval($this->post['cat_id']):"";
  289. if($cat_id!==""){
  290. $where[]=["cat_id","=",$cat_id];
  291. }
  292. $count = Db::name('project_feedback')->where($where)->count();
  293. $total = ceil($count / $size);
  294. $page = $page >= $total ? $total : $page;
  295. $list = Db::name('project_feedback')->where($where)->page($page,$size)->order("addtime desc")->select();
  296. $data=[];
  297. foreach ($list as $value){
  298. $value['can']=isset($value['cat_id'])&&$value['cat_id']!=""?made($value['cat_id']):"";
  299. if($value['data_source']==1){
  300. $good=Db::name("good_platform")->alias("a")->leftJoin("good b","a.spuCode=b.spuCode")->where
  301. (["a.skuCode"=>$value['skuCode'],"a.is_del"=>0])->find();
  302. $good['unit_id'] = isset($good['good_unit'])?$good['good_unit']:"";
  303. $good['cost_desc'] = isset($good['craft_desc'])?$good['craft_desc']:"";
  304. $good['pakge_fee'] = isset($good['packing_fee'])?$good['packing_fee']:"0";
  305. $good['nake_fee'] = isset($good['nake_price'])?$good['nake_price']:"0";
  306. $good['metal_id'] = isset($good['noble_metal'])?$good['noble_metal']:"0";
  307. }else{
  308. $good=Db::name("consult_bids")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  309. }
  310. $value['good_name'] = isset($good['good_name'])?$good['good_name']:"";
  311. $value['brand_id'] = isset($good['brand_id'])?$good['brand_id']:"";
  312. $brand = Db::name("brand")->where(['id'=>$value["brand_id"]])->find();
  313. $value['brand_name'] =isset($brand['brand_name']) ? $brand['brand_name']:"";
  314. $value['specinfo'] = isset($good['specinfo'])?json_decode($good['specinfo'],true):"";
  315. $value['unit_id'] = isset($good['unit_id'])?$good['unit_id']:"";
  316. $unit = Db::name("unit")->where(['id'=>$value["unit_id"]])->find();
  317. $value["unit_name"]=isset($unit['unit'])?$unit['unit']:"";
  318. $value['cost_desc'] = isset($good['cost_desc'])?$good['cost_desc']:"";
  319. $value['work_day'] = isset($good['work_day'])?$good['work_day']:"";
  320. $value['good_img'] = isset($good['good_img'])?$good['good_img']:"";
  321. $value['expire_day'] = isset($good['expire_day'])?$good['expire_day']:"";
  322. $value['origin_place'] = isset($good['origin_place'])?$good['origin_place']:"";
  323. $value['supplierNo'] = isset($good['supplierNo'])?$good['supplierNo']:"";
  324. $value['pay_way'] = isset($good['pay_way'])?$good['pay_way']:"";
  325. $value['tax'] = isset($good['tax'])?$good['tax']:"";
  326. $value['send_way'] = isset($good['send_way'])?$good['send_way']:"";
  327. $value['metal_id'] = isset($good['metal_id'])?$good['metal_id']:"";
  328. $value['is_gold_price'] = isset($good['is_gold_price'])?$good['is_gold_price']:"";
  329. $value['config'] = isset($good['config'])?$good['config']:"";
  330. $value['weight'] = isset($good['weight'])?$good['weight']:"";
  331. $value['is_diff'] = isset($good['is_diff'])?$good['is_diff']:"0";
  332. $value['demo_fee'] = isset($good['demo_fee'])?$good['demo_fee']:"0";
  333. $value['deivery_fee'] = isset($good['deivery_fee'])?$good['deivery_fee']:"0";
  334. $value['open_fee'] = isset($good['open_fee'])?$good['open_fee']:"0";
  335. $value['pakge_fee'] = isset($good['pakge_fee'])?$good['pakge_fee']:"0";
  336. $value['nake_fee'] = isset($good['nake_fee'])?$good['nake_fee']:"0";
  337. $value['mark_fee'] = isset($good['mark_fee'])?$good['mark_fee']:"0";
  338. $value['cert_fee'] = isset($good['cert_fee'])?$good['cert_fee']:"0";
  339. $value['cost_fee'] = isset($good['cost_fee'])?$good['cost_fee']:"0";
  340. //$value['total_fee'] = isset($good['total_fee'])?$good['total_fee']:"0";
  341. $value['supply_area'] = isset($good['supply_area'])?$good['supply_area']:"";
  342. $data[]=$value;
  343. }
  344. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  345. }
  346. public function info(){
  347. $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  348. if($projectNo==""){
  349. return error_show(1004,"参数projectNo不能为空");
  350. }
  351. $type = isset($this->post['type'])&&$this->post['type']!=="" ? intval($this->post['type']) :0;
  352. $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
  353. if($info==false){
  354. return error_show(1004,"未找到项目信息");
  355. }
  356. $plat = Db::name("platform")->where(['id'=>$info['platform_id']])->find();
  357. $info['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  358. $info['platform_code']=isset($plat['platform_code'])?$plat['platform_code']:"";
  359. $khinfo = Db::name("customer_info")->where(["companyNo"=>$info['khNo']])->find();
  360. $info['khName'] = isset($khinfo['companyName'])?$khinfo['companyName']:"";
  361. $company = Db::name("business")->where(["companyNo"=>$info['companyNo']])->find();
  362. $info['company'] = isset($company['company'])?$company['company']:"";
  363. $ladder = Db::name("project_info")->where(['projectNo'=>$projectNo,"is_del"=>0])->select()->toArray();
  364. $info['ladder']=[];
  365. if(!empty($ladder)){
  366. foreach ($ladder as $value){
  367. $value["cat_info"]=isset($value['cat_id']) &&$value['cat_id']!=""? made($value['cat_id'],[]):[];
  368. $condition = $type==0?['pgNo'=>$value['pgNo'],"is_del"=>0] : ['pgNo'=>$value['pgNo'],"is_del"=>0,"status"=>1];
  369. $feedback = Db::name("project_feedback")->where($condition)->select()->toArray();
  370. array_walk($feedback,function (&$v){
  371. $v["cat_info"]=isset($v['cat_id'])&&$v['cat_id']!=""? made($v['cat_id'],[]):[];
  372. });
  373. // $zx = Db::name("consult_info")->where(["pgNo"=>$value["pgNo"],"is_del"=>0,"bargain_status"=>0])
  374. // ->column("infoNo");
  375. // if(!empty($zx)){
  376. // $zxback = Db::name("consult_bids")->where(["infoNo"=>$zx,"is_del"=>0])->select()->toArray();
  377. // array_walk($zxback,function (&$v){
  378. // $v["cat_info"]=isset($v['cat_id'])? made($v['cat_id'],[]):[];
  379. // });
  380. // }else{
  381. // $zxback=[];
  382. // }
  383. $value['feedback']=$feedback;
  384. // $value['zxback']=$zxback;
  385. $info['ladder'][]=$value;
  386. }
  387. }
  388. return app_show(0,"获取成功",$info);
  389. }
  390. public function plan_create(){
  391. $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  392. if($projectNo==""){
  393. return error_show(1004,"参数projectNo不能为空");
  394. }
  395. $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
  396. if($info==false){
  397. return error_show(1004,"未找到项目信息");
  398. }
  399. if($info['status']!=3 || $info['status']!=4){
  400. return error_show(1004,"项目状态有误");
  401. }
  402. $feedback =isset($this->post['feedback'])&&!empty($this->post['feedback'])?$this->post['feedback']:"";
  403. if($feedback==""){
  404. return error_show(1004,"参数feedback不能为空");
  405. }
  406. $feedinfo = Db::name("project_feedback")->where(['id'=>$feedback,"projectNo"=>$projectNo,"is_del"=>0])
  407. ->select()->toArray();
  408. if(empty($feedinfo)){
  409. return error_show(1004,"反馈数据未找到");
  410. }
  411. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  412. if($token==''){
  413. return error_show(1005,"参数token不能为空");
  414. }
  415. $user =GetUserInfo($token);
  416. if(empty($user)||$user['code']!=0){
  417. return error_show(1002,"用户数据不存在");
  418. }
  419. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  420. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  421. Db::startTrans();
  422. try {
  423. $planNo=makeNo("PLA");
  424. $total=0;
  425. $dl=[];
  426. foreach ($feedinfo as $value){
  427. $temp=[];
  428. $temp['planNo']=$planNo;
  429. $temp['feedback_id']=$value['id'];
  430. $temp['status']=1;
  431. $temp['is_del']=0;
  432. $temp['addtime']=date("Y-m-d H:i:s");
  433. $temp['updatetime']=date("Y-m-d H:i:s");
  434. $total+=$value['num']*$value['sale_price'];
  435. $dl[]=$temp;
  436. }
  437. $inn=Db::name("project_plan_rela")->insertAll($dl);
  438. if($inn>0){
  439. $data=[
  440. "planNo"=>$planNo,
  441. "projectNo"=>$projectNo,
  442. "createrid"=>$createrid,
  443. "creater"=>$creater,
  444. "sale_total"=>round($total,2),
  445. "status"=>0,
  446. "is_del"=>0,
  447. "addtime"=>date("Y-m-d H:i:s"),
  448. "updatetime"=>date("Y-m-d H:i:s")
  449. ];
  450. $up =Db::name("project_plan")->insert($data);
  451. if($up){
  452. $info['status']=4;
  453. $info['updatetime']=date("Y-m-d H:i:s");
  454. $cr =Db::name("project")->save($info);
  455. if($cr){
  456. Db::commit();
  457. return app_show(0,"方案制作成功",["planNo"=>$planNo]);
  458. }
  459. }
  460. }
  461. Db::rollback();
  462. return error_show(1004,"方案制作失败");
  463. }catch (\Exception $e){
  464. Db::rollback();
  465. return error_show(1004,$e->getMessage());
  466. }
  467. }
  468. public function planinfo(){
  469. $planNo = isset($this->post['planNo'])&& $this->post['planNo']!==""?trim($this->post["planNo"]):"";
  470. if($planNo==""){
  471. return error_show(1004,"参数planNo不能为空");
  472. }
  473. $plan = Db::name("project_plan")->where(["planNo"=>$planNo,"is_del"=>0])->find();
  474. if($plan==false){
  475. return error_show(1004,"未找到项目方案信息");
  476. }
  477. $plan['feedback']=[];
  478. $feedback =Db::name("project_plan_rela")->where(["planNo"=>$planNo,"is_del"=>0])->column("feedback_id");
  479. if(!empty($feedback)){
  480. $feedlist = Db::name("project_feedback")->where(["id"=>$feedback,"is_del"=>0])->select();
  481. if(!empty($feedlist)){
  482. foreach ($feedlist as $value){
  483. $value["cat_info"]=isset($value['cat_id'])&&$value['cat_id']!=""? made($value['cat_id'],[]):[];
  484. $plan['feedback'][]=$value;
  485. }
  486. }
  487. }
  488. return app_show(0,"获取成功",$plan);
  489. }
  490. public function project_plan(){
  491. $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  492. if($projectNo==""){
  493. return error_show(1004,"参数projectNo不能为空");
  494. }
  495. $type = isset($this->post['type'])&&$this->post['type']!=="" ? intval($this->post['type']) :0;
  496. $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
  497. if($info==false){
  498. return error_show(1004,"未找到项目信息");
  499. }
  500. $plat = Db::name("platform")->where(['id'=>$info['platform_id']])->find();
  501. $info['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  502. $info['platform_code']=isset($plat['platform_code'])?$plat['platform_code']:"";
  503. $khinfo = Db::name("customer_info")->where(["companyNo"=>$plat['khNo']])->find();
  504. $info['khName'] = isset($khinfo['CompanyName'])?$khinfo['CompanyName']:"";
  505. $ladder = Db::name("project_plan")->where(['projectNo'=>$projectNo,"is_del"=>0])->select()->toArray();
  506. $info['plan']=[];
  507. if(!empty($ladder)){
  508. foreach ($ladder as $value){
  509. $value['feedback']=[];
  510. $feedback =Db::name("project_plan_rela")->where(["planNo"=>$value['planNo'],"is_del"=>0])->column("feedback_id");
  511. if(!empty($feedback)){
  512. $feedlist = Db::name("project_feedback")->where(["id"=>$feedback,"is_del"=>0])->select();
  513. if(!empty($feedlist)){
  514. foreach ($feedlist as $value){
  515. $value["cat_info"]=isset($value['cat_id'])&&$value['cat_id']!=""? made($value['cat_id'],[]):[];
  516. $plan['feedback'][]=$value;
  517. }
  518. }
  519. }
  520. $info['plan'][]=$value;
  521. }
  522. }
  523. return app_show(0,"获取成功",$info);
  524. }
  525. public function feedCheck(){
  526. $feedid = isset($this->post['feedid'])&&!empty($this->post['feedid']) ? $this->post['feedid'] :[];
  527. if(empty($feedid)){
  528. return error_show(1004,"参数feedid不能为空");
  529. }
  530. $selec = Db::name("project_feedback")->where(["id"=>$feedid,'is_del'=>0,"status"=>0])->select();
  531. if(empty($selec)){
  532. return error_show(1004,"反馈数据信息未找到");
  533. }
  534. Db::startTrans();
  535. try{
  536. $up = Db::name("project_feedback")->where(["id"=>$feedid,'is_del'=>0,"status"=>0])->save(["status"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  537. if($up){
  538. foreach ($selec as $value){
  539. $projectinfo=[];
  540. $projectinfo['status']=3;
  541. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  542. $up = Db::name("project_info")->where(['pgNo'=>$value['pgNo']])->save($projectinfo);
  543. if($up){
  544. $count = Db::name("project_info")->where(["projectNo"=>$value['projectNo'],"status"=>2])
  545. ->count();
  546. if($count==0){
  547. $proc =Db::name("project")->where(["projectNo"=>$value['projectNo']])->save
  548. (["status"=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  549. if(!$proc){
  550. Db::rollback();
  551. return error_show(1004,"反馈数据选择失败");
  552. }
  553. }
  554. }else{
  555. Db::rollback();
  556. return error_show(1004,"反馈数据选择失败");
  557. }
  558. }
  559. Db::commit();
  560. return app_show(0,"反馈数据选择成功");
  561. }else{
  562. Db::rollback();
  563. return error_show(1004,"反馈数据选择失败");
  564. }
  565. }catch (\Exception $e){
  566. Db::rollback();
  567. return error_show(1004,$e->getMessage());
  568. }
  569. }
  570. public function planCheck(){
  571. $planNos = isset($this->post['planNos'])&&!empty($this->post['planNos'])? $this->post['planNos'] :"";
  572. if($planNos==""){
  573. return error_show(1004,"参数planNos不能为空");
  574. }
  575. $status=isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  576. if($status==""){
  577. return error_show(1004,"参数status不能为空");
  578. }
  579. $selec = Db::name("project_plan")->where(["planNo"=>$planNos,'is_del'=>0,"status"=>0])->select();
  580. if(empty($selec)){
  581. return error_show(1004,"项目方案数据信息未找到");
  582. }
  583. Db::startTrans();
  584. try{
  585. $up = Db::name("project_plan")->where(["planNo"=>$planNos,'is_del'=>0,"status"=>0])->save(["status"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  586. if($up) {
  587. $project = array_column($selec, "projectNo");
  588. if (empty($project)) {
  589. Db::rollback();
  590. return error_show(1004, "方案选择失败");
  591. }
  592. $pro = Db::name("project")->where(["projectNo" => $project, "status" => 4])->save(["status" => 5, "updatetime" => date("Y-m-d H:i:s")]);
  593. if ($pro) {
  594. Db::commit();
  595. return app_show(0, "方案数据修改成功");
  596. }
  597. }
  598. Db::rollback();
  599. return error_show(1004,"方案选择失败");
  600. }catch (\Exception $e){
  601. Db::rollback();
  602. return error_show(1004,$e->getMessage());
  603. }
  604. }
  605. public function changeRate(){
  606. $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  607. if($projectNo==""){
  608. return error_show(1004,"参数projectNo不能为空");
  609. }
  610. $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
  611. if($info==false){
  612. return error_show(1004,"未找到项目信息");
  613. }
  614. $rate = isset($this->post['rate'])&&$this->post['rate']!=="" ?floatval($this->post['rate']):"";
  615. if($rate===""){
  616. return error_show(1004,"参数rate不能为空");
  617. }
  618. $info['low_rate']=$rate;
  619. $info['updatetime']=date("Y-m-d H:i:s");
  620. $up =Db::name("project")->save($info);
  621. if($up){
  622. return app_show(0,"利润率修改成功");
  623. }else{
  624. return error_show(1004,"利润率修改失败");
  625. }
  626. }
  627. public function order(){
  628. $id = isset($this->post['id'])&& $this->post['id']!=="" ? intval($this->post['id']):"";
  629. if($id==""){
  630. return error_show(1004,"参数id不能为空");
  631. }
  632. $backinfo = Db::name("project_feedback")->where(["id"=>$id,"is_del"=>0])->find();
  633. if($backinfo==false){
  634. return error_show(1004,"未找到数据");
  635. }
  636. $prject = Db::name("project")->where(["projectNo"=>$backinfo['projectNo'],"is_del"=>0])->find();
  637. if($prject==false) {
  638. return error_show(1004, "未找到项目数据");
  639. }
  640. $send_type =isset($this->post['send_type'])&&$this->post['send_type']!=""? intval($this->post['send_type']):"";
  641. if($send_type==""){
  642. return error_show(1004,"参数send_type不能为空");
  643. }
  644. if($send_type==1){
  645. $va = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  646. if ($va == "") {
  647. return error_show(1002, "参数order_addr不能为空");
  648. }
  649. }
  650. $plat = Db::name("platform")->where(["id"=>$prject['platform_id']])->find();
  651. $token = isset($this->post['token'])&& $this->post['token']!=="" ? trim($this->post['token']):"";
  652. if($token==""){
  653. return error_show(1004,"参数token不能为空");
  654. }
  655. $apply_id = GetUserInfo($token);
  656. if (empty($apply_id) || $apply_id['code'] != 0) {
  657. return error_show(1002, "申请人数据不存在");
  658. }
  659. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  660. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  661. $orderCode = makeNo("CX");
  662. Db::startTrans();
  663. try{
  664. $data = [
  665. "orderCode" => $orderCode,
  666. "good_code" => $backinfo['spuCode'],
  667. "customer_code" => $prject['khNo'],
  668. "good_name" => $backinfo['good_name'],
  669. "good_num" => $backinfo['num'],
  670. "order_type" =>3,
  671. "item_code"=>isset($plat['platform_code'])? $plat['platform_code']:"",
  672. "good_type"=>1,
  673. "apply_id" => $rm,
  674. "apply_name" => $ri,
  675. "origin_price" =>$backinfo['nake_price'],
  676. "sale_price" => $backinfo['sale_price'],
  677. "post_fee" => 0,
  678. "status" => 0,
  679. "supplierNo" =>$prject['companyNo'],
  680. "send_num" => 0,
  681. "zxNo"=>$backinfo['pgNo'],
  682. "wsend_num" => $backinfo['num'],
  683. "send_type" => $send_type,
  684. "send_status" => 1,
  685. "is_del" => 0,
  686. "addtime" => date("Y-m-d H:i:s"),
  687. "updatetime" => date("Y-m-d H:i:s"),
  688. 'total_price' => $backinfo['sale_price'] * $backinfo['num'],
  689. ];
  690. $datainfo = Db::name('sale')->insert($data, true);
  691. if($datainfo>0){
  692. if($send_type==1){
  693. foreach ($va as $value) {
  694. $temp = [];
  695. $addrs = [];
  696. if ($value['addr_code'] !== '' && is_array($value['addr_code'])) {
  697. $addrs['provice_code'] = $value['addr_code'][0];
  698. $addrs['city_code'] = $value['addr_code'][1];
  699. $addrs['area_code'] = $value['addr_code'][2];
  700. $addr = json_encode($addrs);
  701. } else {
  702. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  703. }
  704. $temp['orderCode'] = $orderCode;
  705. $temp['contactor'] = $value['contactor'];
  706. $temp['mobile'] = $value['mobile'];
  707. $temp['addr'] = $value['addr'];
  708. $temp['addr_code'] = $addr;
  709. $temp['customer_code'] = $prject['khNo'];
  710. $temp['receipt_quantity'] = $value['receipt_quantity'];
  711. $temp['post_fee'] = 0;
  712. $temp['is_del'] = 0;
  713. $temp['addtime'] = date("Y-m-d H:i:s");
  714. $temp['updatetime'] = date("Y-m-d H:i:s");
  715. $temp['arrive_time'] = date("Y-m-d H:i:s");
  716. $vat[] = $temp;
  717. }
  718. $vmp = Db::name('order_addr')->insertAll($vat);
  719. if ($vmp==false) {
  720. Db::rollback();
  721. return error_show(1004, "销售订单创建失败");
  722. }
  723. }
  724. Db::commit();
  725. return error_show(0, "销售订单创建成功");
  726. }
  727. Db::rollback();
  728. return error_show(1004, "销售订单创建失败");
  729. }catch (\Exception $w){
  730. Db::rollback();
  731. return error_show(1004, $w->getMessage());
  732. }
  733. }
  734. public function feeddel(){
  735. $feedid = isset($this->post['id'])&&!empty($this->post['id']) ? $this->post['id'] :[];
  736. if(empty($feedid)){
  737. return error_show(1004,"参数feedid不能为空");
  738. }
  739. $selec = Db::name("project_feedback")->where(["id"=>$feedid,'is_del'=>0])->select();
  740. if(empty($selec)){
  741. return error_show(1004,"反馈数据信息未找到");
  742. }
  743. $up = Db::name("project_feedback")->where(["id"=>$feedid,'is_del'=>0])->save(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  744. if($up){
  745. return app_show(0,"反馈数据删除成功");
  746. }else{
  747. return error_show(1004,"反馈数据删除失败");
  748. }
  749. }
  750. }