123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491 |
- <?php
- namespace app\admin\controller;
- use think\App;
- use think\facade\Db;
- class Project extends \app\BaseController
- {
- private $post=[];
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->post=$this->request->post();
- }
- public function create(){
- $name = isset($this->post['name'])&&$this->post['name']!=""? trim($this->post['name']):"";
- if($name==""){
- return error_show(1004,"参数name不能为空");
- }
- $platform = isset($this->post['platform'])&&$this->post['platform']!=""? trim($this->post['platform']):"";
- if($platform==""){
- return error_show(1004,"参数platform不能为空");
- }
- $khNo = isset($this->post['khNo'])&&$this->post['khNo']!=""?trim($this->post['khNo']):"";
- $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""?trim($this->post['supplierNo']):"";
- if($khNo==""){
- return error_show(1004,"参数khNo不能为空");
- }
- if($supplierNo==""){
- return error_show(1004,"参数supplierNo不能为空");
- }
- $use_desc = isset($this->post['use_desc'])&&$this->post['use_desc']!=""?trim($this->post['use_desc']):"";
- $budget_total = isset($this->post['budget_total'])&&$this->post['budget_total']!=""?floatval($this->post['budget_total']):"";
- $arrtime = isset($this->post['arrtime'])&&$this->post['arrtime']!=""?$this->post['arrtime']:"";
- if($use_desc==""){
- return error_show(1004,"参数use_desc不能为空");
- }
- if($budget_total==""){
- return error_show(1004,"参数budget_total不能为空");
- }
- if($arrtime==""){
- return error_show(1004,"参数arrtime不能为空");
- }
- $low_rate = isset($this->post['low_rate'])&&$this->post['low_rate']!=""?floatval($this->post['low_rate']):"";
- if($low_rate==""){
- return error_show(1004,"参数low_rate不能为空");
- }
- $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder'])? $this->post['ladder']:"";
- if($ladder==""){
- return error_show(1004,"参数ladder不能为空");
- }
- $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(1005,"参数token不能为空");
- }
- $user =GetUserInfo($token);
- if(empty($user)||$user['code']!=0){
- return error_show(1002,"用户数据不存在");
- }
- $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- Db::startTrans();
- try {
- $projectNo = makeNo("PRO");
- $data=[
- "projectNo"=>$projectNo,
- "platform_id"=>$platform,
- "khNo"=>$khNo,
- "project_name"=>$name,
- "budget_total"=>$budget_total,
- "use_desc"=>$use_desc,
- "low_rate"=>$low_rate,
- "creater"=>$creater,
- "createrid"=>$createrid,
- "status"=>1,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $pro=Db::name("good_project")->insert($data);
- if($pro){
- if(!empty($ladder)){
- $la=[];
- foreach ($ladder as $value){
- $pgNo = makeNo("PRI");
- $temp=[];
- $temp['pgNo']=$pgNo;
- $temp['projectNo']=$projectNo;
- $temp['good_type']=$value['good_type'];
- $temp['good_name']=$value['good_name'];
- $temp['good_img']=$value['good_img'];
- $temp['cat_id']=$value['cat_id'];
- $temp['budget_price']=$value['budget_price'];
- $temp['num']=$value['num'];
- $temp['creater']=$creater;
- $temp['createrid']=$createrid;
- $temp['status']=1;
- $temp['is_del']=0;
- $temp['addtime']=date("Y-m-d H:i:s");
- $temp['updatetime']=date("Y-m-d H:i:s");
- $la[]=$temp;
- }
- $in = Db::name("project_info")->insertAll($la);
- if($in>0){
- Db::commit();
- return app_show(0,"项目新建成功",['projectNo'=>$projectNo]);
- }
- }
- }
- Db::rollback();
- return error_show(1004,"项目新建失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- public function addfeed(){
- $pgNo =isset($this->post['pgNo']) && $this->post['pgNo']!=""? trim($this->post['pgNo']):"";
- if($pgNo==""){
- return error_show(1004,"参数pgNo不能为空");
- }
- $projectinfo = Db::name("project_info")->where(["pgNo"=>$pgNo,"is_del"=>0])->find();
- if($projectinfo==false){
- return error_show(1004,"未找到项目阶梯信息");
- }
- $spuCode =isset($this->post['spuCode'])&&!empty($this->post['spuCode']) ?$this->post['spuCode']:"";
- if($spuCode==""){
- return error_show(1004,"参数spuCode不能为空");
- }
- $source =isset($this->post['source'])&&$this->post['source']!=="" ?intval($this->post['source']):"";
- if($source==""){
- return error_show(1004,"参数source不能为空");
- }
- $good=[];
- if($source==1){
- $good=Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->select()->toArray();
- if(empty($good)){
- return error_show(1004,"未找到商品信息");
- }
- }
- $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(1005,"参数token不能为空");
- }
- $user =GetUserInfo($token);
- if(empty($user)||$user['code']!=0){
- return error_show(1002,"用户数据不存在");
- }
- $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- Db::startTrans();
- try{
- $data=[];
- foreach ($good as $value){
- $temp=[];
- $temp['spuCode']=$value['spuCode'];
- $temp['pgNo']=$projectinfo['pgNo'];
- $temp['projectNo']=$projectinfo['projectNo'];
- $temp['good_name']=$value['good_name'];
- $temp['good_type']=$projectinfo['good_type'];
- $temp['data_source']=$source;
- $temp['cat_id']=$value['cat_id'];
- $temp['budget_price']=$projectinfo['budget_price'];
- $temp['sale_price']=$value['sale_price'];
- $temp['num']=$projectinfo['num'];
- $temp['status']=0;
- $temp['is_del']=0;
- $temp['creater']=$creater;
- $temp['createrid']=$createrid;
- $temp['addtime']=date("Y-m-d H:i:s");
- $temp['updatetime']=date("Y-m-d H:i:s");
- $data[]=$temp;
- }
- $nu = Db::name("project_feeback")->insertAll($data);
- if($nu>0){
- Db::commit();
- return app_show(0,"添加成功");
- }else{
- Db::rollback();
- return app_show(0,"添加成功");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- public function list(){
- $page =isset($this->post['page'])&&$this->post['page']!=="" ? intval($this->post['page']):1;
- $size =isset($this->post['size'])&&$this->post['size']!==""? intval($this->post['size']):10;
- $where=[["is_del","=",0]];
- $khNo = isset($this->post['khNo']) &&$this->post['khNo']!==""? trim($this->post['khNo']):"";
- if($khNo!==""){
- $where[]=["khNo","=",$khNo];
- }
- $project_name = isset($this->post['project_name']) &&$this->post['project_name']!==""? trim($this->post['project_name']):"";
- if($project_name!==""){
- $where[]=["project_name","like","%$project_name%"];
- }
- $status = isset($this->post['status']) &&$this->post['status']!==""? intval($this->post['status']):"";
- if($status!==""){
- $where[]=["status","=",$status];
- }
- $start = isset($this->post['start'])&&$this->post['start']!=="" ? $this->post['start']:"";
- if($start!==''){
- $where[]=["addtime",">=",$start];
- }
- $end = isset($this->post['end'])&&$this->post['end']!=="" ? $this->post['end']:"";
- if($end!==''){
- $where[]=["addtime","<=",$end];
- }
- $low = isset($this->post['low'])&&$this->post['low']!=="" ? floatval($this->post['low']):"";
- if($low!==''){
- $where[]=["budget_total",">=",$low];
- }
- $up = isset($this->post['up'])&&$this->post['up']!=="" ? floatval($this->post['up']):"";
- if($up!==''){
- $where[]=["budget_total","<=",$up];
- }
- $count = Db::name('project')->where($where)->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('project')->where($where)->page($page,$size)->order("addtime desc")->select();
- $data=[];
- foreach ($list as $value){
- $info = Db::name("platform")->where(['id'=>$value['platform_id']])->find();
- $value['platform_name']=isset($info['platform_name'])?$info['platform_name']:"";
- $value['platform_code']=isset($info['platform_code'])?$info['platform_code']:"";
- $khinfo = Db::name("customer_info")->where(["companyNo"=>$value['khNo']])->find();
- $value['khName'] = isset($khinfo['CompanyName'])?$khinfo['CompanyName']:"";
- $data[]=$value;
- }
- return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
- }
- public function feedlist(){
- $page =isset($this->post['page'])&&$this->post['page']!=="" ? intval($this->post['page']):1;
- $size =isset($this->post['size'])&&$this->post['size']!==""? intval($this->post['size']):10;
- $where=[["is_del","=",0]];
- $pgNo =isset($this->post['pgNo'])&&$this->post['pgNo']!==""?trim($this->post['pgNo']):"";
- if($pgNo!==""){
- $where[]=["pgNo","=",$pgNo];
- }
- $source =isset($this->post['source'])&&$this->post['source']!==""?intval($this->post['source']):"";
- if($source!==""){
- $where[]=["data_source","=",$source];
- }
- $cat_id =isset($this->post['cat_id'])&&$this->post['cat_id']!==""?intval($this->post['cat_id']):"";
- if($cat_id!==""){
- $where[]=["cat_id","=",$cat_id];
- }
- $count = Db::name('project_feedback')->where($where)->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('project_feedback')->where($where)->page($page,$size)->order("addtime desc")->select();
- return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
- }
- public function info(){
- $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
- if($projectNo==""){
- return error_show(1004,"参数projectNo不能为空");
- }
- $type = isset($this->post['type'])&&$this->post['type']!=="" ? intval($this->post['type']) :0;
- $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
- if($info==false){
- return error_show(1004,"未找到项目信息");
- }
- $plat = Db::name("platform")->where(['id'=>$info['platform_id']])->find();
- $info['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
- $info['platform_code']=isset($plat['platform_code'])?$plat['platform_code']:"";
- $khinfo = Db::name("customer_info")->where(["companyNo"=>$plat['khNo']])->find();
- $info['khName'] = isset($khinfo['CompanyName'])?$khinfo['CompanyName']:"";
- $ladder = Db::name("project_info")->where(['projectNo'=>$projectNo,"is_del"=>0])->select()->toArray();
- $info['ladder']=[];
- if(!empty($ladder)){
- foreach ($ladder as $value){
- $value["cat_info"]=isset($value['cat_id'])? made($value['cat_id'],[]):[];
- $condition = $type==0?['pgNo'=>$value['pgNo'],"is_del"=>0] : ['pgNo'=>$value['pgNo'],"is_del"=>0,"status"=>1];
- $feedback = Db::name("project_info")->where($condition)->select()->toArray();
- array_walk($feedback,function (&$v){
- $v["cat_info"]=isset($v['cat_id'])? made($v['cat_id'],[]):[];
- });
- $value['feedback']=$feedback;
- $info['ladder'][]=$value;
- }
- }
- return app_show(0,"获取成功",$info);
- }
- public function plan_create(){
- $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
- if($projectNo==""){
- return error_show(1004,"参数projectNo不能为空");
- }
- $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
- if($info==false){
- return error_show(1004,"未找到项目信息");
- }
- $feedback =isset($this->post['feedback'])&&!empty($this->post['feedback'])?$this->post['feedback']:"";
- if($feedback==""){
- return error_show(1004,"参数feedback不能为空");
- }
- $feedinfo = Db::name("project_feedback")->where(['id'=>$feedback,"projectNo"=>$projectNo,"is_del"=>0])
- ->select()->toArray();
- if(empty($feedinfo)){
- return error_show(1004,"反馈数据未找到");
- }
- $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(1005,"参数token不能为空");
- }
- $user =GetUserInfo($token);
- if(empty($user)||$user['code']!=0){
- return error_show(1002,"用户数据不存在");
- }
- $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- Db::startTrans();
- try {
- $planNo=makeNo("PLA");
- $total=0;
- $dl=[];
- foreach ($feedinfo as $value){
- $temp=[];
- $temp['planNo']=$planNo;
- $temp['feedback_id']=$value['id'];
- $temp['status']=1;
- $temp['is_del']=0;
- $temp['addtime']=date("Y-m-d H:i:s");
- $temp['updatetime']=date("Y-m-d H:i:s");
- $total+=$value['num']*$value['sale_price'];
- $dl[]=$temp;
- }
- $inn=Db::name("project_plan_rela")->insertAll($dl);
- if($inn>0){
- $data=[
- "planNo"=>$planNo,
- "projectNo"=>$projectNo,
- "createrid"=>$createrid,
- "creater"=>$creater,
- "sale_total"=>round($total,2),
- "status"=>0,
- "is_del"=>1,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $up =Db::name("project_plan")->insert($data);
- if($up){
- Db::commit();
- return app_show(0,"方案制作成功",["planNo"=>$planNo]);
- }
- }
- Db::rollback();
- return error_show(1004,"方案制作失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- public function planinfo(){
- $planNo = isset($this->post['planNo'])&& $this->post['planNo']!==""?trim($this->post["planNo"]):"";
- if($planNo==""){
- return error_show(1004,"参数planNo不能为空");
- }
- $plan = Db::name("project_plan")->where(["planNo"=>$planNo,"is_del"=>0])->find();
- if($plan==false){
- return error_show(1004,"未找到项目方案信息");
- }
- $plan['feedback']=[];
- $feedback =Db::name("preject_plan_rela")->where(["planNo"=>$planNo,"is_del"=>0])->column("feedback_id");
- if(!empty($feedback)){
- $feedlist = Db::name("project_feedback")->where(["id"=>$feedback,"is_del"=>0])->select();
- if(!empty($feedlist)){
- foreach ($feedlist as $value){
- $value["cat_info"]=isset($value['cat_id'])? made($value['cat_id'],[]):[];
- $plan['feedback'][]=$value;
- }
- }
- }
- return app_show(0,"获取成功",$plan);
- }
- public function project_plan(){
- $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
- if($projectNo==""){
- return error_show(1004,"参数projectNo不能为空");
- }
- $type = isset($this->post['type'])&&$this->post['type']!=="" ? intval($this->post['type']) :0;
- $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
- if($info==false){
- return error_show(1004,"未找到项目信息");
- }
- $plat = Db::name("platform")->where(['id'=>$info['platform_id']])->find();
- $info['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
- $info['platform_code']=isset($plat['platform_code'])?$plat['platform_code']:"";
- $khinfo = Db::name("customer_info")->where(["companyNo"=>$plat['khNo']])->find();
- $info['khName'] = isset($khinfo['CompanyName'])?$khinfo['CompanyName']:"";
- $ladder = Db::name("project_plan")->where(['projectNo'=>$projectNo,"is_del"=>0])->select()->toArray();
- $info['plan']=[];
- if(!empty($ladder)){
- foreach ($ladder as $value){
- $value['feedback']=[];
- $feedback =Db::name("preject_plan_rela")->where(["planNo"=>$value['planNo'],"is_del"=>0])->column("feedback_id");
- if(!empty($feedback)){
- $feedlist = Db::name("project_feedback")->where(["id"=>$feedback,"is_del"=>0])->select();
- if(!empty($feedlist)){
- foreach ($feedlist as $value){
- $value["cat_info"]=isset($value['cat_id'])? made($value['cat_id'],[]):[];
- $plan['feedback'][]=$value;
- }
- }
- }
- $info['ladder'][]=$value;
- }
- }
- return app_show(0,"获取成功",$info);
- }
- public function feedCheck(){
- $feedid = isset($this->post['feedid'])&&!empty($this->post['feedid']) ? $this->post['feedid'] :[];
- if(empty($feedid)){
- return error_show(1004,"参数feedid不能为空");
- }
- $selec = Db::name("project_feedback")->where(["id"=>$feedid,'is_del'=>0,"status"=>0])->select();
- if(empty($selec)){
- return error_show(1004,"反馈数据信息未找到");
- }
- $up = Db::name("project_feedback")->where(["id"=>$feedid,'is_del'=>0,"status"=>0])->save(["stauts"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
- if($up){
- return app_show(0,"反馈数据选择成功");
- }else{
- return error_show(1004,"反馈数据选择失败");
- }
- }
- public function planCheck(){
- $planNos = isset($this->post['planNos'])&&$this->post['planNos']!==""? trim($this->post['planNos']) :[];
- if($planNos==""){
- return error_show(1004,"参数planNos不能为空");
- }
- $status=isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
- if($status==""){
- return error_show(1004,"参数status不能为空");
- }
- $selec = Db::name("project_plan")->where(["planNo"=>$planNos,'is_del'=>0,"status"=>0])->select();
- if(empty($selec)){
- return error_show(1004,"项目方案数据信息未找到");
- }
- $up = Db::name("project_plan")->where(["planNo"=>$planNos,'is_del'=>0,"status"=>0])->save(["stauts"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
- if($up){
- return app_show(0,"方案数据修改成功");
- }else{
- return error_show(1004,"方案数据修改失败");
- }
- }
- public function changeRate(){
- $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
- if($projectNo==""){
- return error_show(1004,"参数projectNo不能为空");
- }
- $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
- if($info==false){
- return error_show(1004,"未找到项目信息");
- }
- $rate = isset($this->post['rate'])&&$this->post['rate']!=="" ?floatval($this->post['rate']):"";
- if($rate===""){
- return error_show(1004,"参数rate不能为空");
- }
- $info['low_rate']=$rate;
- $info['updatetime']=date("Y-m-d H:i:s");
- $up =Db::name("project")->save($info);
- if($up){
- return app_show(0,"利润率修改成功");
- }else{
- return app_show(0,"利润率修改失败");
- }
- }
- }
|