Project.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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. $companyNo = isset($this->post['companyNo'])&&$this->post['companyNo']!=""?trim($this->post['companyNo']):"";
  24. if($khNo==""){
  25. return error_show(1004,"参数khNo不能为空");
  26. }
  27. if($companyNo==""){
  28. return error_show(1004,"参数companyNo不能为空");
  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']):"0";
  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. "companyNo"=>$companyNo,
  68. "project_name"=>$name,
  69. "budget_total"=>$budget_total,
  70. "use_desc"=>$use_desc,
  71. "low_rate"=>$low_rate,
  72. "creater"=>$creater,
  73. "createrid"=>$createrid,
  74. "arrtime"=>$arrtime,
  75. "status"=>1,
  76. "is_del"=>0,
  77. "addtime"=>date("Y-m-d H:i:s"),
  78. "updatetime"=>date("Y-m-d H:i:s")
  79. ];
  80. $pro=Db::name("project")->insert($data);
  81. if($pro){
  82. if(!empty($ladder)){
  83. $la=[];
  84. foreach ($ladder as $value){
  85. $pgNo = makeNo("PRI");
  86. $temp=[];
  87. $temp['pgNo']=$pgNo;
  88. $temp['projectNo']=$projectNo;
  89. $temp['good_type']=$value['good_type'];
  90. $temp['good_name']=$value['good_name'];
  91. $temp['good_img']=$value['good_img'];
  92. $temp['cat_id']=$value['cat_id'];
  93. $temp['budget_price']=$value['budget_price'];
  94. $temp['num']=$value['num'];
  95. $temp['creater']=$creater;
  96. $temp['createrid']=$createrid;
  97. $temp['status']=1;
  98. $temp['is_del']=0;
  99. $temp['addtime']=date("Y-m-d H:i:s");
  100. $temp['updatetime']=date("Y-m-d H:i:s");
  101. $la[]=$temp;
  102. }
  103. $in = Db::name("project_info")->insertAll($la);
  104. if($in>0){
  105. Db::commit();
  106. return app_show(0,"项目新建成功",['projectNo'=>$projectNo]);
  107. }
  108. }
  109. }
  110. Db::rollback();
  111. return error_show(1004,"项目新建失败");
  112. }catch (\Exception $e){
  113. Db::rollback();
  114. return error_show(1004,$e->getMessage());
  115. }
  116. }
  117. public function addfeed(){
  118. $pgNo =isset($this->post['pgNo']) && $this->post['pgNo']!=""? trim($this->post['pgNo']):"";
  119. if($pgNo==""){
  120. return error_show(1004,"参数pgNo不能为空");
  121. }
  122. $projectinfo = Db::name("project_info")->where(["pgNo"=>$pgNo,"is_del"=>0])->find();
  123. if($projectinfo==false){
  124. return error_show(1004,"未找到项目阶梯信息");
  125. }
  126. $spuCode =isset($this->post['spuCode'])&&!empty($this->post['spuCode']) ?$this->post['spuCode']:"";
  127. if($spuCode==""){
  128. return error_show(1004,"参数spuCode不能为空");
  129. }
  130. $source =isset($this->post['source'])&&$this->post['source']!=="" ?intval($this->post['source']):"1";
  131. // if($source==""){
  132. // return error_show(1004,"参数source不能为空");
  133. // }
  134. $good=[];
  135. if($source==1){
  136. $good=Db::name("good")->where(["spuCode"=>$spuCode,"is_del"=>0])->select()->toArray();
  137. if(empty($good)){
  138. return error_show(1004,"未找到商品信息");
  139. }
  140. }
  141. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  142. if($token==''){
  143. return error_show(1005,"参数token不能为空");
  144. }
  145. $user =GetUserInfo($token);
  146. if(empty($user)||$user['code']!=0){
  147. return error_show(1002,"用户数据不存在");
  148. }
  149. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  150. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  151. Db::startTrans();
  152. try{
  153. $data=[];
  154. foreach ($good as $value){
  155. $temp=[];
  156. $temp['spuCode']=$value['spuCode'];
  157. $temp['pgNo']=$projectinfo['pgNo'];
  158. $temp['projectNo']=$projectinfo['projectNo'];
  159. $temp['good_name']=$value['good_name'];
  160. $temp['good_type']=$projectinfo['good_type'];
  161. $temp['data_source']=$source;
  162. $temp['cat_id']=$value['cat_id'];
  163. $temp['budget_price']=$projectinfo['budget_price'];
  164. $temp['sale_price']=$value['nake_price'];
  165. $temp['num']=$projectinfo['num'];
  166. $temp['status']=0;
  167. $temp['is_del']=0;
  168. $temp['creater']=$creater;
  169. $temp['createrid']=$createrid;
  170. $temp['addtime']=date("Y-m-d H:i:s");
  171. $temp['updatetime']=date("Y-m-d H:i:s");
  172. $data[]=$temp;
  173. }
  174. $nu = Db::name("project_feedback")->insertAll($data);
  175. if($nu>0){
  176. Db::commit();
  177. return app_show(0,"添加成功");
  178. }else{
  179. Db::rollback();
  180. return app_show(0,"添加成功");
  181. }
  182. }catch (\Exception $e){
  183. Db::rollback();
  184. return error_show(1004,$e->getMessage());
  185. }
  186. }
  187. public function list(){
  188. $page =isset($this->post['page'])&&$this->post['page']!=="" ? intval($this->post['page']):1;
  189. $size =isset($this->post['size'])&&$this->post['size']!==""? intval($this->post['size']):10;
  190. $where=[["is_del","=",0]];
  191. $khNo = isset($this->post['khNo']) &&$this->post['khNo']!==""? trim($this->post['khNo']):"";
  192. if($khNo!==""){
  193. $where[]=["khNo","=",$khNo];
  194. }
  195. $project_name = isset($this->post['project_name']) &&$this->post['project_name']!==""? trim($this->post['project_name']):"";
  196. if($project_name!==""){
  197. $where[]=["project_name","like","%$project_name%"];
  198. }
  199. $status = isset($this->post['status']) &&$this->post['status']!==""? intval($this->post['status']):"";
  200. if($status!==""){
  201. $where[]=["status","=",$status];
  202. }
  203. $start = isset($this->post['start'])&&$this->post['start']!=="" ? $this->post['start']:"";
  204. if($start!==''){
  205. $where[]=["addtime",">=",$start];
  206. }
  207. $end = isset($this->post['end'])&&$this->post['end']!=="" ? $this->post['end']:"";
  208. if($end!==''){
  209. $where[]=["addtime","<=",$end];
  210. }
  211. $low = isset($this->post['low'])&&$this->post['low']!=="" ? floatval($this->post['low']):"";
  212. if($low!==''){
  213. $where[]=["budget_total",">=",$low];
  214. }
  215. $up = isset($this->post['up'])&&$this->post['up']!=="" ? floatval($this->post['up']):"";
  216. if($up!==''){
  217. $where[]=["budget_total","<=",$up];
  218. }
  219. $count = Db::name('project')->where($where)->count();
  220. $total = ceil($count / $size);
  221. $page = $page >= $total ? $total : $page;
  222. $list = Db::name('project')->where($where)->page($page,$size)->order("addtime desc")->select();
  223. $data=[];
  224. foreach ($list as $value){
  225. $info = Db::name("platform")->where(['id'=>$value['platform_id']])->find();
  226. $value['platform_name']=isset($info['platform_name'])?$info['platform_name']:"";
  227. $value['platform_code']=isset($info['platform_code'])?$info['platform_code']:"";
  228. $khinfo = Db::name("customer_info")->where(["companyNo"=>$value['khNo']])->find();
  229. $value['khName'] = isset($khinfo['companyName'])?$khinfo['companyName']:"";
  230. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  231. $value['company'] = isset($company['company'])?$company['company']:"";
  232. $data[]=$value;
  233. }
  234. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  235. }
  236. public function feedlist(){
  237. $page =isset($this->post['page'])&&$this->post['page']!=="" ? intval($this->post['page']):1;
  238. $size =isset($this->post['size'])&&$this->post['size']!==""? intval($this->post['size']):10;
  239. $where=[["is_del","=",0]];
  240. $pgNo =isset($this->post['pgNo'])&&$this->post['pgNo']!==""?trim($this->post['pgNo']):"";
  241. if($pgNo!==""){
  242. $where[]=["pgNo","=",$pgNo];
  243. }
  244. $source =isset($this->post['source'])&&$this->post['source']!==""?intval($this->post['source']):"";
  245. if($source!==""){
  246. $where[]=["data_source","=",$source];
  247. }
  248. $cat_id =isset($this->post['cat_id'])&&$this->post['cat_id']!==""?intval($this->post['cat_id']):"";
  249. if($cat_id!==""){
  250. $where[]=["cat_id","=",$cat_id];
  251. }
  252. $count = Db::name('project_feedback')->where($where)->count();
  253. $total = ceil($count / $size);
  254. $page = $page >= $total ? $total : $page;
  255. $list = Db::name('project_feedback')->where($where)->page($page,$size)->order("addtime desc")->select();
  256. return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
  257. }
  258. public function info(){
  259. $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  260. if($projectNo==""){
  261. return error_show(1004,"参数projectNo不能为空");
  262. }
  263. $type = isset($this->post['type'])&&$this->post['type']!=="" ? intval($this->post['type']) :0;
  264. $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
  265. if($info==false){
  266. return error_show(1004,"未找到项目信息");
  267. }
  268. $plat = Db::name("platform")->where(['id'=>$info['platform_id']])->find();
  269. $info['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  270. $info['platform_code']=isset($plat['platform_code'])?$plat['platform_code']:"";
  271. $khinfo = Db::name("customer_info")->where(["companyNo"=>$info['khNo']])->find();
  272. $info['khName'] = isset($khinfo['companyName'])?$khinfo['companyName']:"";
  273. $company = Db::name("business")->where(["companyNo"=>$info['companyNo']])->find();
  274. $info['company'] = isset($company['company'])?$company['company']:"";
  275. $ladder = Db::name("project_info")->where(['projectNo'=>$projectNo,"is_del"=>0])->select()->toArray();
  276. $info['ladder']=[];
  277. if(!empty($ladder)){
  278. foreach ($ladder as $value){
  279. $value["cat_info"]=isset($value['cat_id'])? made($value['cat_id'],[]):[];
  280. $condition = $type==0?['pgNo'=>$value['pgNo'],"is_del"=>0] : ['pgNo'=>$value['pgNo'],"is_del"=>0,"status"=>1];
  281. $feedback = Db::name("project_feedback")->where($condition)->select()->toArray();
  282. array_walk($feedback,function (&$v){
  283. $v["cat_info"]=isset($v['cat_id'])? made($v['cat_id'],[]):[];
  284. });
  285. $value['feedback']=$feedback;
  286. $info['ladder'][]=$value;
  287. }
  288. }
  289. return app_show(0,"获取成功",$info);
  290. }
  291. public function plan_create(){
  292. $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  293. if($projectNo==""){
  294. return error_show(1004,"参数projectNo不能为空");
  295. }
  296. $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
  297. if($info==false){
  298. return error_show(1004,"未找到项目信息");
  299. }
  300. $feedback =isset($this->post['feedback'])&&!empty($this->post['feedback'])?$this->post['feedback']:"";
  301. if($feedback==""){
  302. return error_show(1004,"参数feedback不能为空");
  303. }
  304. $feedinfo = Db::name("project_feedback")->where(['id'=>$feedback,"projectNo"=>$projectNo,"is_del"=>0])
  305. ->select()->toArray();
  306. if(empty($feedinfo)){
  307. return error_show(1004,"反馈数据未找到");
  308. }
  309. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  310. if($token==''){
  311. return error_show(1005,"参数token不能为空");
  312. }
  313. $user =GetUserInfo($token);
  314. if(empty($user)||$user['code']!=0){
  315. return error_show(1002,"用户数据不存在");
  316. }
  317. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  318. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  319. Db::startTrans();
  320. try {
  321. $planNo=makeNo("PLA");
  322. $total=0;
  323. $dl=[];
  324. foreach ($feedinfo as $value){
  325. $temp=[];
  326. $temp['planNo']=$planNo;
  327. $temp['feedback_id']=$value['id'];
  328. $temp['status']=1;
  329. $temp['is_del']=0;
  330. $temp['addtime']=date("Y-m-d H:i:s");
  331. $temp['updatetime']=date("Y-m-d H:i:s");
  332. $total+=$value['num']*$value['sale_price'];
  333. $dl[]=$temp;
  334. }
  335. $inn=Db::name("project_plan_rela")->insertAll($dl);
  336. if($inn>0){
  337. $data=[
  338. "planNo"=>$planNo,
  339. "projectNo"=>$projectNo,
  340. "createrid"=>$createrid,
  341. "creater"=>$creater,
  342. "sale_total"=>round($total,2),
  343. "status"=>0,
  344. "is_del"=>0,
  345. "addtime"=>date("Y-m-d H:i:s"),
  346. "updatetime"=>date("Y-m-d H:i:s")
  347. ];
  348. $up =Db::name("project_plan")->insert($data);
  349. if($up){
  350. Db::commit();
  351. return app_show(0,"方案制作成功",["planNo"=>$planNo]);
  352. }
  353. }
  354. Db::rollback();
  355. return error_show(1004,"方案制作失败");
  356. }catch (\Exception $e){
  357. Db::rollback();
  358. return error_show(1004,$e->getMessage());
  359. }
  360. }
  361. public function planinfo(){
  362. $planNo = isset($this->post['planNo'])&& $this->post['planNo']!==""?trim($this->post["planNo"]):"";
  363. if($planNo==""){
  364. return error_show(1004,"参数planNo不能为空");
  365. }
  366. $plan = Db::name("project_plan")->where(["planNo"=>$planNo,"is_del"=>0])->find();
  367. if($plan==false){
  368. return error_show(1004,"未找到项目方案信息");
  369. }
  370. $plan['feedback']=[];
  371. $feedback =Db::name("project_plan_rela")->where(["planNo"=>$planNo,"is_del"=>0])->column("feedback_id");
  372. if(!empty($feedback)){
  373. $feedlist = Db::name("project_feedback")->where(["id"=>$feedback,"is_del"=>0])->select();
  374. if(!empty($feedlist)){
  375. foreach ($feedlist as $value){
  376. $value["cat_info"]=isset($value['cat_id'])? made($value['cat_id'],[]):[];
  377. $plan['feedback'][]=$value;
  378. }
  379. }
  380. }
  381. return app_show(0,"获取成功",$plan);
  382. }
  383. public function project_plan(){
  384. $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  385. if($projectNo==""){
  386. return error_show(1004,"参数projectNo不能为空");
  387. }
  388. $type = isset($this->post['type'])&&$this->post['type']!=="" ? intval($this->post['type']) :0;
  389. $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
  390. if($info==false){
  391. return error_show(1004,"未找到项目信息");
  392. }
  393. $plat = Db::name("platform")->where(['id'=>$info['platform_id']])->find();
  394. $info['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  395. $info['platform_code']=isset($plat['platform_code'])?$plat['platform_code']:"";
  396. $khinfo = Db::name("customer_info")->where(["companyNo"=>$plat['khNo']])->find();
  397. $info['khName'] = isset($khinfo['CompanyName'])?$khinfo['CompanyName']:"";
  398. $ladder = Db::name("project_plan")->where(['projectNo'=>$projectNo,"is_del"=>0])->select()->toArray();
  399. $info['plan']=[];
  400. if(!empty($ladder)){
  401. foreach ($ladder as $value){
  402. $value['feedback']=[];
  403. $feedback =Db::name("project_plan_rela")->where(["planNo"=>$value['planNo'],"is_del"=>0])->column("feedback_id");
  404. if(!empty($feedback)){
  405. $feedlist = Db::name("project_feedback")->where(["id"=>$feedback,"is_del"=>0])->select();
  406. if(!empty($feedlist)){
  407. foreach ($feedlist as $value){
  408. $value["cat_info"]=isset($value['cat_id'])? made($value['cat_id'],[]):[];
  409. $plan['feedback'][]=$value;
  410. }
  411. }
  412. }
  413. $info['plan'][]=$value;
  414. }
  415. }
  416. return app_show(0,"获取成功",$info);
  417. }
  418. public function feedCheck(){
  419. $feedid = isset($this->post['feedid'])&&!empty($this->post['feedid']) ? $this->post['feedid'] :[];
  420. if(empty($feedid)){
  421. return error_show(1004,"参数feedid不能为空");
  422. }
  423. $selec = Db::name("project_feedback")->where(["id"=>$feedid,'is_del'=>0,"status"=>0])->select();
  424. if(empty($selec)){
  425. return error_show(1004,"反馈数据信息未找到");
  426. }
  427. $up = Db::name("project_feedback")->where(["id"=>$feedid,'is_del'=>0,"status"=>0])->save(["status"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  428. if($up){
  429. return app_show(0,"反馈数据选择成功");
  430. }else{
  431. return error_show(1004,"反馈数据选择失败");
  432. }
  433. }
  434. public function planCheck(){
  435. $planNos = isset($this->post['planNos'])&&!empty($this->post['planNos'])? $this->post['planNos'] :"";
  436. if($planNos==""){
  437. return error_show(1004,"参数planNos不能为空");
  438. }
  439. $status=isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  440. if($status==""){
  441. return error_show(1004,"参数status不能为空");
  442. }
  443. $selec = Db::name("project_plan")->where(["planNo"=>$planNos,'is_del'=>0,"status"=>0])->select();
  444. if(empty($selec)){
  445. return error_show(1004,"项目方案数据信息未找到");
  446. }
  447. $up = Db::name("project_plan")->where(["planNo"=>$planNos,'is_del'=>0,"status"=>0])->save(["status"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  448. if($up){
  449. return app_show(0,"方案数据修改成功");
  450. }else{
  451. return error_show(1004,"方案数据修改失败");
  452. }
  453. }
  454. public function changeRate(){
  455. $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  456. if($projectNo==""){
  457. return error_show(1004,"参数projectNo不能为空");
  458. }
  459. $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
  460. if($info==false){
  461. return error_show(1004,"未找到项目信息");
  462. }
  463. $rate = isset($this->post['rate'])&&$this->post['rate']!=="" ?floatval($this->post['rate']):"";
  464. if($rate===""){
  465. return error_show(1004,"参数rate不能为空");
  466. }
  467. $info['low_rate']=$rate;
  468. $info['updatetime']=date("Y-m-d H:i:s");
  469. $up =Db::name("project")->save($info);
  470. if($up){
  471. return app_show(0,"利润率修改成功");
  472. }else{
  473. return error_show(1004,"利润率修改失败");
  474. }
  475. }
  476. public function order(){
  477. $id = isset($this->post['id'])&& $this->post['id']!=="" ? intval($this->post['id']):"";
  478. if($id==""){
  479. return error_show(1004,"参数id不能为空");
  480. }
  481. $backinfo = Db::name("project_feedback")->where(["id"=>$id,"is_del"=>0])->find();
  482. if($backinfo==false){
  483. return error_show(1004,"未找到数据");
  484. }
  485. $prject = Db::name("project")->where(["projectNo"=>$backinfo['projectNo'],"is_del"=>0])->find();
  486. if($prject==false) {
  487. return error_show(1004, "未找到项目数据");
  488. }
  489. $send_type =isset($this->post['send_type'])&&$this->post['send_type']!=""? intval($this->post['send_type']):"";
  490. if($send_type==""){
  491. return error_show(1004,"参数send_type不能为空");
  492. }
  493. if($send_type==1){
  494. $va = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  495. if ($va == "") {
  496. return error_show(1002, "参数order_addr不能为空");
  497. }
  498. }
  499. $plat = Db::name("platform")->where(["id"=>$prject['platform_id']])->find();
  500. $token = isset($this->post['token'])&& $this->post['token']!=="" ? trim($this->post['token']):"";
  501. if($token==""){
  502. return error_show(1004,"参数token不能为空");
  503. }
  504. $apply_id = GetUserInfo($token);
  505. if (empty($apply_id) || $apply_id['code'] != 0) {
  506. return error_show(1002, "申请人数据不存在");
  507. }
  508. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  509. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  510. $orderCode = makeNo("CX");
  511. Db::startTrans();
  512. try{
  513. $data = [
  514. "orderCode" => $orderCode,
  515. "good_code" => $backinfo['spuCode'],
  516. "customer_code" => $prject['khNo'],
  517. "good_name" => $backinfo['good_name'],
  518. "good_num" => $backinfo['num'],
  519. "order_type" =>3,
  520. "item_code"=>isset($plat['platform_code'])? $plat['platform_code']:"",
  521. "good_type"=>1,
  522. "apply_id" => $rm,
  523. "apply_name" => $ri,
  524. "origin_price" =>$backinfo['nake_price'],
  525. "sale_price" => $backinfo['sale_price'],
  526. "post_fee" => 0,
  527. "status" => 0,
  528. "supplierNo" =>$prject['companyNo'],
  529. "send_num" => 0,
  530. "zxNo"=>$backinfo['pgNo'],
  531. "wsend_num" => $backinfo['num'],
  532. "send_type" => $send_type,
  533. "send_status" => 1,
  534. "is_del" => 0,
  535. "addtime" => date("Y-m-d H:i:s"),
  536. "updatetime" => date("Y-m-d H:i:s"),
  537. 'total_price' => $backinfo['sale_price'] * $backinfo['num'],
  538. ];
  539. $datainfo = Db::name('sale')->insert($data, true);
  540. if($datainfo>0){
  541. if($send_type==1){
  542. foreach ($va as $value) {
  543. $temp = [];
  544. $addrs = [];
  545. if ($value['addr_code'] !== '' && is_array($value['addr_code'])) {
  546. $addrs['provice_code'] = $value['addr_code'][0];
  547. $addrs['city_code'] = $value['addr_code'][1];
  548. $addrs['area_code'] = $value['addr_code'][2];
  549. $addr = json_encode($addrs);
  550. } else {
  551. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  552. }
  553. $temp['orderCode'] = $orderCode;
  554. $temp['contactor'] = $value['contactor'];
  555. $temp['mobile'] = $value['mobile'];
  556. $temp['addr'] = $value['addr'];
  557. $temp['addr_code'] = $addr;
  558. $temp['customer_code'] = $prject['khNo'];
  559. $temp['receipt_quantity'] = $value['receipt_quantity'];
  560. $temp['post_fee'] = 0;
  561. $temp['is_del'] = 0;
  562. $temp['addtime'] = date("Y-m-d H:i:s");
  563. $temp['updatetime'] = date("Y-m-d H:i:s");
  564. $temp['arrive_time'] = date("Y-m-d H:i:s");
  565. $vat[] = $temp;
  566. }
  567. $vmp = Db::name('order_addr')->insertAll($vat);
  568. if ($vmp==false) {
  569. Db::rollback();
  570. return error_show(1004, "销售订单创建失败");
  571. }
  572. }
  573. Db::commit();
  574. return error_show(0, "销售订单创建成功");
  575. }
  576. Db::rollback();
  577. return error_show(1004, "销售订单创建失败");
  578. }catch (\Exception $w){
  579. Db::rollback();
  580. return error_show(1004, $w->getMessage());
  581. }
  582. }
  583. }