Project.php 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\DataGroup as DataGroupModel;
  5. use app\admin\model\ProcessOrder;
  6. use think\App;
  7. use think\facade\Db;
  8. //项目
  9. class Project extends Base
  10. {
  11. public function __construct(App $app)
  12. {
  13. parent::__construct($app);
  14. }
  15. public function create(){
  16. $name = isset($this->post['name'])&&$this->post['name']!=""? trim($this->post['name']):"";
  17. if($name==""){
  18. return error_show(1004,"参数name不能为空");
  19. }
  20. $platform = isset($this->post['platform'])&&$this->post['platform']!=""? trim($this->post['platform']):"";
  21. if($platform==""){
  22. return error_show(1004,"参数platform不能为空");
  23. }
  24. $khNo = isset($this->post['khNo'])&&$this->post['khNo']!=""?trim($this->post['khNo']):"";
  25. $companyNo = isset($this->post['companyNo'])&&$this->post['companyNo']!=""?trim($this->post['companyNo']):"";
  26. if($khNo==""){
  27. return error_show(1004,"参数khNo不能为空");
  28. }
  29. if($companyNo==""){
  30. return error_show(1004,"参数companyNo不能为空");
  31. }
  32. $use_desc = isset($this->post['use_desc'])&&$this->post['use_desc']!=""?trim($this->post['use_desc']):"";
  33. $budget_total = isset($this->post['budget_total'])&&$this->post['budget_total']!=""?floatval($this->post['budget_total']):"";
  34. $arrtime = isset($this->post['arrtime'])&&$this->post['arrtime']!=""?$this->post['arrtime']:"";
  35. $endtime = isset($this->post['endtime'])&&$this->post['endtime']!=""?$this->post['endtime']:"";
  36. if($use_desc==""){
  37. return error_show(1004,"参数use_desc不能为空");
  38. }
  39. if($budget_total==""){
  40. return error_show(1004,"参数budget_total不能为空");
  41. }
  42. if($arrtime==""){
  43. return error_show(1004,"参数arrtime不能为空");
  44. }
  45. if($endtime==""){
  46. return error_show(1004,"参数endtime不能为空");
  47. }
  48. $low_rate = isset($this->post['low_rate'])&&$this->post['low_rate']!=""?floatval($this->post['low_rate']):"0";
  49. // if($low_rate==""){
  50. // return error_show(1004,"参数low_rate不能为空");
  51. // }
  52. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder'])? $this->post['ladder']:"";
  53. if($ladder==""){
  54. return error_show(1004,"参数ladder不能为空");
  55. }
  56. $pay_id = isset($this->post['pay_id']) && $this->post['pay_id'] !== "" ? intval($this->post['pay_id']) : "0";
  57. if($pay_id!=0){
  58. $payinfo =Db::name("pay")->where("id",$pay_id)->findOrEmpty();
  59. if(empty($payinfo)) return error_show(1004, "支付渠道信息未找到");
  60. if($payinfo['status']!=1)return error_show(1004, "支付渠道已禁用");
  61. $supplierArr =Db::name("pay_rate")->where(["pay_id"=>$pay_id,"status"=>1,"is_del"=>0])->column("companyNo");
  62. if(in_array($companyNo,$supplierArr)) return error_show(1004, "支付渠道含有该业务公司,支付渠道无法使用!");
  63. }
  64. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  65. if($token==''){
  66. return error_show(105,"参数token不能为空");
  67. }
  68. $user =GetUserInfo($token);
  69. if(empty($user)||$user['code']!=0){
  70. return error_show(1002,"用户数据不存在");
  71. }
  72. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  73. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  74. Db::startTrans();
  75. try {
  76. $projectNo = makeNo("PR");
  77. $data=[
  78. "projectNo"=>$projectNo,
  79. "platform_id"=>$platform,
  80. "khNo"=>$khNo,
  81. "companyNo"=>$companyNo,
  82. "project_name"=>$name,
  83. "budget_total"=>$budget_total,
  84. "use_desc"=>$use_desc,
  85. "low_rate"=>$low_rate,
  86. "creater"=>$creater,
  87. "createrid"=>$createrid,
  88. "arrtime"=>$arrtime,
  89. "endtime"=>$endtime,
  90. "pay_id"=>$pay_id,
  91. "status"=>1,
  92. "is_del"=>0,
  93. "addtime"=>date("Y-m-d H:i:s"),
  94. "updatetime"=>date("Y-m-d H:i:s")
  95. ];
  96. $pro=Db::name("project")->insertGetId($data);
  97. if($pro>0){
  98. if(!empty($ladder)){
  99. $la=[];
  100. foreach ($ladder as $value){
  101. $pgNo = makeNo("PI");
  102. $temp=[];
  103. $temp['pgNo']=$pgNo;
  104. $temp['projectNo']=$projectNo;
  105. $temp['good_type']=$value['good_type'];
  106. $temp['good_name']=$value['good_name'];
  107. $temp['good_img']=$value['good_img'];
  108. $temp['cat_id']=isset($value['cat_id'])?$value['cat_id']:0;
  109. $temp['budget_price']=$value['budget_price'];
  110. $temp['num']=$value['num'];
  111. $temp['creater']=$creater;
  112. $temp['createrid']=$createrid;
  113. $temp['status']=1;
  114. $temp['is_del']=0;
  115. $temp['addtime']=date("Y-m-d H:i:s");
  116. $temp['updatetime']=date("Y-m-d H:i:s");
  117. $in = Db::name("project_info")->insert($temp,true);
  118. if($in>0){
  119. ActionLog::logAdd(['id'=>$createrid,'nickname'=>$creater], [
  120. "order_code" => $pgNo,//编码,这里是project的编码
  121. "status" => 1,//这里的status是之前的值
  122. "action_remark" => '',//备注
  123. "action_type" => "create"//新建create,编辑edit,更改状态status
  124. ], "PRI", 1, $temp);
  125. }else{
  126. Db::rollback();
  127. return error_show(1004,"项目新建失败");
  128. }
  129. }
  130. //修改状态,添加待办
  131. ActionLog::logAdd(['id'=>$createrid,'nickname'=>$creater], [
  132. "order_code" => $projectNo,//项目编码
  133. "status" =>0,//这里的status是之前的值
  134. "action_remark" => '',//备注
  135. "action_type" => "create"//新建create,编辑edit更改状态status
  136. ], "PRT", 1, $this->post);
  137. $process = ["order_code" => $projectNo, "order_id" => Db::name("project")->getLastInsID(), "order_status" =>1, "order_type" => 'PRT',"before_status"=>1];//order_status==7修改毛利率
  138. ProcessOrder::AddProcess(['id'=>$createrid,'nickname'=>$creater], $process);
  139. //修改状态,添加待办,只记录动作
  140. ActionLog::logAdd(['id'=>$createrid,'nickname'=>$creater], [
  141. "order_code" => $projectNo,//编码,这里是project的编码
  142. "status" => 1,//这里的status是之前的值
  143. "action_remark" => '',//备注
  144. "action_type" => "create"//新建create,编辑edit,更改状态status
  145. ], "PRO", 1, $this->post);
  146. $process = ["order_code" => $projectNo, "order_id" => $pro, "order_status" =>1, "order_type" =>"PRO","before_status"=>1,'holder_id'=>$data['createrid']];
  147. ProcessOrder::AddProcess(['id'=>$createrid,'nickname'=>$creater], $process);
  148. //台账记录
  149. Db::name('standing_book')
  150. ->insert([
  151. 'standBookNo' => makeNo("IO"),
  152. 'projectNo' => $projectNo,
  153. 'companyNo' => $companyNo,
  154. 'customer_code' => $khNo,
  155. 'addtime' => date('Y-m-d H:i:s'),
  156. 'updatetime' => date('Y-m-d H:i:s')
  157. ]);
  158. Db::commit();
  159. return app_show(0,"项目新建成功",['projectNo'=>$projectNo]);
  160. }
  161. }
  162. Db::rollback();
  163. return error_show(1004,"项目新建失败");
  164. }catch (\Exception $e){
  165. Db::rollback();
  166. return error_show(1004,$e->getMessage());
  167. }
  168. }
  169. public function addfeed(){
  170. $pgNo =isset($this->post['pgNo']) && $this->post['pgNo']!=""? trim($this->post['pgNo']):"";
  171. if($pgNo==""){
  172. return error_show(1004,"参数pgNo不能为空");
  173. }
  174. $projectinfo = Db::name("project_info")->where(["pgNo"=>$pgNo,"is_del"=>0])->find();
  175. if($projectinfo==false){
  176. return error_show(1004,"未找到项目阶梯信息");
  177. }
  178. $project = Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"is_del"=>0])->find();
  179. if($project==false){
  180. return error_show(1004,"未找到项目阶梯信息");
  181. }
  182. $spuCode =isset($this->post['spuCode'])&&!empty($this->post['spuCode']) ?$this->post['spuCode']:"";
  183. if($spuCode==""){
  184. return error_show(1004,"参数spuCode不能为空");
  185. }
  186. $source =isset($this->post['source'])&&$this->post['source']!=="" ?intval($this->post['source']):"1";
  187. if($source==""){
  188. return error_show(1004,"参数source不能为空");
  189. }
  190. $good=[];
  191. if($source==1){
  192. $good=Db::name("good_platform")->alias("a")->leftJoin("good b","a.spuCode=b.spuCode")->where
  193. (["a.skuCode"=>$spuCode,"a.is_del"=>0])->select()->toArray();
  194. if(empty($good)){
  195. return error_show(1004,"未找到商品信息");
  196. }
  197. }else{
  198. $good=Db::name("consult_bids")->where(["spuCode"=>$spuCode,"is_del"=>0])->select()->toArray();
  199. if(empty($good)){
  200. return error_show(1004,"未找到商品信息");
  201. }
  202. }
  203. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  204. if($token==''){
  205. return error_show(105,"参数token不能为空");
  206. }
  207. $user =GetUserInfo($token);
  208. if(empty($user)||$user['code']!=0){
  209. return error_show($user['code'],"用户数据不存在");
  210. }
  211. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  212. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  213. Db::startTrans();
  214. try{
  215. $data=[];
  216. foreach ($good as $value){
  217. $temp=[];
  218. $temp['spuCode']=$value['spuCode'];
  219. $temp['skuCode']=isset($value['skuCode'])?$value['skuCode']:"";
  220. $temp['pgNo']=$projectinfo['pgNo'];
  221. $temp['projectNo']=$projectinfo['projectNo'];
  222. $temp['good_name']=$value['good_name'];
  223. $temp['good_type']=$projectinfo['good_type'];
  224. $temp['data_source']=$source;
  225. $temp['cat_id']=$value['cat_id'];
  226. $temp['budget_price']=$projectinfo['budget_price'];
  227. if($source==1){
  228. $ladd = Db::name("good_ladder")->where([["skuCode","=",$value['skuCode']],["min_num","<=",
  229. $projectinfo["num"]],["status","=",1],["is_del","=",0]])->order("min_num desc")->find();
  230. $nake =Db::name("good_nake")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->where([["min_num","<=",$projectinfo['num']]])
  231. ->order("min_num desc")->find();
  232. $origin_price=isset($nake['nake_total'])?$nake['nake_total']:"0" ;
  233. $sale_price = $ladd['sale_price'];
  234. if($value['is_gold_price']==1 && $value['is_stock']!=1){
  235. $gold = Db::name("gold_price1")
  236. ->field('id,price')
  237. ->where(["type" => $value['noble_metal'], "is_del" => 0, "status" => 1])
  238. ->order("addtime desc")
  239. ->find();
  240. //$saleprice(最终售价) = (打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价+物流费)/(1-成本售价/100);
  241. $sale_price = ($value['demo_fee'] / $projectinfo["num"] + $value['open_fee'] / $projectinfo["num"]
  242. + $value['noble_weight'] * $gold["price"] + $ladd['cost_fee'] * $value['noble_weight'] + $nake['package_fee'] + $nake['mark_fee'] + $nake['cert_fee'] + $nake['nake_fee'] + $nake['delivery_fee']);
  243. }
  244. }else{
  245. $sale_price =$value['sale_price'];
  246. $origin_price =$value['sale_price'];
  247. }
  248. $temp['sale_price']=$sale_price;
  249. $temp['origin_price']=$origin_price;
  250. $temp['num']=$projectinfo['num'];
  251. $temp['status']=0;
  252. $temp['is_del']=0;
  253. $temp['creater']=$creater;
  254. $temp['createrid']=$createrid;
  255. $temp['addtime']=date("Y-m-d H:i:s");
  256. $temp['updatetime']=date("Y-m-d H:i:s");
  257. $data[]=$temp;
  258. }
  259. $nu = Db::name("project_feedback")->insertAll($data);
  260. if($nu>0){
  261. $old_projectinfo_status = $projectinfo['status'];
  262. $projectinfo['status']=2;
  263. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  264. $up = Db::name("project_info")->save($projectinfo);
  265. if($up){
  266. //修改状态,添加待办,只记录动作
  267. ActionLog::logAdd($this->post['token'], [
  268. "order_code" => $pgNo,//编码,这里是project的编码
  269. "status" => $old_projectinfo_status,//这里的status是之前的值
  270. "action_remark" => '',//备注
  271. "action_type" => "status"//新建create,编辑edit,更改状态status
  272. ], "PRI", 2, $projectinfo);
  273. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  274. ->count();
  275. if($count==0){
  276. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  277. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  278. if($proc){
  279. //修改状态,添加待办
  280. ActionLog::logAdd($this->post['token'], [
  281. "order_code"=>$projectinfo['projectNo'],//项目编码
  282. "status"=>1,//这里的status是之前的值
  283. "action_remark"=>'',//备注
  284. "action_type"=>"status"//新建create,编辑edit,更改状态status
  285. ],"PRO",2,["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  286. ProcessOrder::AddProcess($this->post['token'],[
  287. "order_type"=>'PRO',
  288. "order_code"=>$projectinfo['projectNo'],
  289. "order_id"=>$project['id'],//这里更新是根据编码更新的,没有主键id
  290. "order_status"=>2,
  291. "before_status"=>1,
  292. 'holder_id'=>$project['createrid']
  293. ]);
  294. Db::commit();
  295. return app_show(0,"添加成功");
  296. }
  297. }
  298. }
  299. Db::commit();
  300. return app_show(0,"添加成功");
  301. }else{
  302. Db::rollback();
  303. return error_show(1004,"添加失败");
  304. }
  305. }catch (\Exception $e){
  306. Db::rollback();
  307. return error_show(1004,$e->getMessage());
  308. }
  309. }
  310. public function list(){
  311. $page =isset($this->post['page'])&&$this->post['page']!=="" ? intval($this->post['page']):1;
  312. $size =isset($this->post['size'])&&$this->post['size']!==""? intval($this->post['size']):10;
  313. $where=[["p.is_del","=",0]];
  314. $khNo = isset($this->post['khNo']) &&$this->post['khNo']!==""? trim($this->post['khNo']):"";
  315. if($khNo!==""){
  316. $where[]=["p.khNo","=",$khNo];
  317. }
  318. $project_name = isset($this->post['project_name']) &&$this->post['project_name']!==""? trim($this->post['project_name']):"";
  319. if($project_name!==""){
  320. $where[]=["p.project_name","like","%$project_name%"];
  321. }
  322. $status = isset($this->post['status']) &&$this->post['status']!==""? intval($this->post['status']):"";
  323. if($status!==""){
  324. $where[]=["p.status","=",$status];
  325. }
  326. $start = isset($this->post['start'])&&$this->post['start']!=="" ? $this->post['start']:"";
  327. if($start!==''){
  328. $where[]=["p.addtime",">=",$start];
  329. }
  330. $end = isset($this->post['end'])&&$this->post['end']!=="" ? $this->post['end']:"";
  331. if($end!==''){
  332. $where[]=["p.addtime","<=",$end];
  333. }
  334. $low = isset($this->post['low'])&&$this->post['low']!=="" ? floatval($this->post['low']):"";
  335. if($low!==''){
  336. $where[]=["p.budget_total",">=",$low];
  337. }
  338. $up = isset($this->post['up'])&&$this->post['up']!=="" ? floatval($this->post['up']):"";
  339. if($up!==''){
  340. $where[]=["p.budget_total","<=",$up];
  341. }
  342. $companyNo = isset($this->post['companyNo'])&&$this->post['companyNo']!=="" ? trim($this->post['companyNo']):"";
  343. if($companyNo!==''){
  344. $where[]=["p.companyNo","like","%$companyNo%"];
  345. }
  346. $platform_id = isset($this->post['platform_id'])&&$this->post['platform_id']!=="" ? intval($this->post['platform_id']):"";
  347. if($platform_id!==''){
  348. $where[]=["p.platform_id","=",$platform_id];
  349. }
  350. $company_name = isset($this->post['company_name'])&&$this->post['company_name']!=="" ? trim($this->post['company_name']):"";
  351. if($company_name!=='') $where[] = ["p.createrid", 'in', get_company_item_user_by_name($company_name)];
  352. // $role=$this->checkRole();
  353. // if(!empty($role['write'])){
  354. // $where[]=["p.createrid","in",$role['write']];
  355. // }
  356. // $role = $this->checkDataShare();
  357. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ['p.createrid', 'in', $role[DataGroupModel::$type_全部]];
  358. $role = $this->checkDataShare();
  359. $hand = resign_hand_user($this->uid,0);
  360. if (!empty($role[DataGroupModel::$type_全部])) {
  361. $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部]));
  362. $where[] = ['p.createrid', 'in',$arr];
  363. }
  364. // if(!empty($role['platform'])){
  365. // $where[]=["p.platform_id","in",$role['platform']];
  366. // }
  367. $count = Db::name('project') ->alias('p')->where($where)->count();
  368. $total = ceil($count / $size);
  369. $page = $page >= $total ? $total : $page;
  370. $list = Db::name('project')
  371. ->alias('p')
  372. ->field('p.*,u.itemid')
  373. ->leftJoin('depart_user u', 'u.uid=p.createrid AND u.is_del=0')
  374. ->where($where)
  375. ->page($page,$size)
  376. ->order("p.addtime desc")
  377. ->cursor();
  378. $data=[];
  379. foreach ($list as $value){
  380. $info = Db::name("platform")->where(['id'=>$value['platform_id']])->find();
  381. $value['platform_name']=isset($info['platform_name'])?$info['platform_name']:"";
  382. $value['platform_code']=isset($info['platform_code'])?$info['platform_code']:"";
  383. $khinfo = Db::name("customer_info")->where(["companyNo"=>$value['khNo']])->find();
  384. $value['khName'] = isset($khinfo['companyName'])?$khinfo['companyName']:"";
  385. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  386. $value['company'] = isset($company['company'])?$company['company']:"";
  387. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  388. //是否具有编辑权限
  389. $value['is_allow_update'] = 0;
  390. if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  391. $data[]=$value;
  392. }
  393. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  394. }
  395. public function feedlist(){
  396. $page =isset($this->post['page'])&&$this->post['page']!=="" ? intval($this->post['page']):1;
  397. $size =isset($this->post['size'])&&$this->post['size']!==""? intval($this->post['size']):10;
  398. $where=[["is_del","=",0]];
  399. $pgNo =isset($this->post['pgNo'])&&$this->post['pgNo']!==""?trim($this->post['pgNo']):"";
  400. if($pgNo!==""){
  401. $where[]=["pgNo","=",$pgNo];
  402. }
  403. $projectNo =isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  404. if($projectNo!==""){
  405. $where[]=["projectNo","=",$projectNo];
  406. }
  407. $source =isset($this->post['source'])&&$this->post['source']!==""?intval($this->post['source']):"";
  408. if($source!==""){
  409. $where[]=["data_source","=",$source];
  410. }
  411. $cat_id =isset($this->post['cat_id'])&&$this->post['cat_id']!==""?intval($this->post['cat_id']):"";
  412. if($cat_id!==""){
  413. $where[]=["cat_id","=",$cat_id];
  414. }
  415. $status =isset($this->post['status'])&&$this->post['status']!==""?intval($this->post['status']):"";
  416. if($status!==""){
  417. $where[]=["status","=",$status];
  418. }
  419. $count = Db::name('project_feedback')->where($where)->count();
  420. $total = ceil($count / $size);
  421. $page = $page >= $total ? $total : $page;
  422. $list = Db::name('project_feedback')->where($where)->page($page,$size)->order("addtime desc")->select();
  423. $data=[];
  424. foreach ($list as $value){
  425. $value['can']=isset($value['cat_id'])&&$value['cat_id']!=""?made($value['cat_id']):"";
  426. if($value['data_source']==1){
  427. $good=Db::name("good_platform")->alias("a")->leftJoin("good b","a.spuCode=b.spuCode")->where
  428. (["a.skuCode"=>$value['skuCode'],"a.is_del"=>0])->find();
  429. $nake = Db::name("good_nake")->where([["spuCode","=",$value['spuCode']],["min_num","<=",
  430. $value["num"]],["is_del","=",0]])->order("min_num desc")->find();
  431. $good['unit_id'] = isset($good['good_unit'])?$good['good_unit']:"";
  432. $good['cost_desc'] = isset($good['craft_desc'])?$good['craft_desc']:"";
  433. $good['pakge_fee'] = isset($nake['package_fee'])?$nake['package_fee']:"0";
  434. $good['mark_fee'] = isset($nake['mark_fee'])?$nake['mark_fee']:"0";
  435. $good['other_fee'] = isset($nake['other_fee'])?$nake['other_fee']:"0";
  436. $good['cert_fee'] = isset($nake['cert_fee'])?$nake['cert_fee']:"0";
  437. $good['delivery_fee'] = isset($nake['delivery_fee'])?$nake['delivery_fee']:"0";
  438. $good['nake_fee'] = isset($nake['nake_fee'])?$nake['nake_fee']:"0";
  439. $good['metal_id'] = isset($good['noble_metal'])?$good['noble_metal']:"0";
  440. $spec = Db::name("good_spec")->where(["spuCode"=>$good['spuCode'],"is_del"=>0])->select()->toArray();
  441. $good['specinfo']=[];
  442. if(!empty($spec)){
  443. foreach ($spec as $vae){
  444. $specs=Db::name("specs")->where(["id"=>$vae['spec_id']])->find();
  445. $spec_value = Db::name("spec_value")->where(["id"=>$vae["spec_value_id"]])->find();
  446. $temp = ["specid"=>$vae['spec_id'],"spec_name"=>$specs['spec_name'],"spec_value_id"=>$vae['spec_value_id'],"spec_value_name"=>$spec_value["spec_value"]];
  447. $good['specinfo'][]=$temp;
  448. }
  449. }
  450. $nake =Db::name("good_nake")->where(["spuCode"=>$good['spuCode'],"is_del"=>0])->where([["min_num","<=",$value['num']]])
  451. ->order("min_num desc")->find();
  452. $good['origin_price']=$nake['nake_total'];
  453. $good['work_day']=$good['lead_time'];
  454. $good_img = $good['good_thumb_img'];
  455. }else{
  456. $good=Db::name("consult_bids")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  457. $good['specinfo'] = isset($good['specinfo'])&&$good['specinfo']!=""?json_decode($good['specinfo'],
  458. true):"";
  459. $catinfo = Db::name("cat")->where(["id"=>$good['cat_id']])->find();
  460. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:100;
  461. $good_img = $good['good_img'];
  462. }
  463. $nobel =\think\facade\Config::get("noble");
  464. $value['good_name'] = isset($good['good_name'])?$good['good_name']:"";
  465. // $value['good_img'] = isset($good['good_img'])?$good['good_img']:"";
  466. $value['brand_id'] = isset($good['brand_id'])?$good['brand_id']:"";
  467. $brand = Db::name("brand")->where(['id'=>$value["brand_id"]])->find();
  468. $value['brand_name'] =isset($brand['brand_name']) ? $brand['brand_name']:"";
  469. $value['specinfo'] = isset($good['specinfo'])&&$good['specinfo']!=""?$good['specinfo']:[];
  470. $value['unit_id'] = isset($good['unit_id'])?$good['unit_id']:"";
  471. $unit = Db::name("unit")->where(['id'=>$value["unit_id"]])->find();
  472. $value["unit_name"]=isset($unit['unit'])?$unit['unit']:"";
  473. $value['cost_desc'] = isset($good['cost_desc'])?$good['cost_desc']:"";
  474. $value['work_day'] = isset($good['work_day'])?$good['work_day']:"";
  475. $value['delivery_day'] = isset($good['delivery_day'])?$good['delivery_day']:"";
  476. $value['expire_day'] = isset($good['expire_day'])?$good['expire_day']:"0";
  477. $value['good_img'] = $good_img;
  478. $value['expire_day'] = isset($good['expire_day'])?$good['expire_day']:"";
  479. $value['origin_place'] = isset($good['origin_place'])?$good['origin_place']:"";
  480. $value['supplierNo'] = isset($good['supplierNo'])?$good['supplierNo']:"";
  481. $value['pay_way'] = isset($good['pay_way'])?$good['pay_way']:"";
  482. $value['tax'] = isset($good['tax'])?$good['tax']:"";
  483. $value['send_way'] = isset($good['send_way'])?$good['send_way']:"";
  484. $value['metal_id'] = isset($good['metal_id'])?$good['metal_id']:"";
  485. $value['metal_name'] = isset($nobel[$good['metal_id']])?$nobel[$good['metal_id']]:"";
  486. $value['is_gold_price'] = isset($good['is_gold_price'])?$good['is_gold_price']:"0";
  487. $value['config'] = isset($good['config'])?$good['config']:"";
  488. $value['other_config'] = isset($good['other_config'])?$good['other_config']:"";
  489. $value['weight'] = isset($good['weight'])?$good['weight']:"";
  490. $value['is_diff'] = isset($good['is_diff'])?$good['is_diff']:"0";
  491. $value['demo_fee'] = isset($good['demo_fee'])?$good['demo_fee']:"0";
  492. $value['deivery_fee'] = isset($good['deivery_fee'])?$good['deivery_fee']:"0";
  493. $value['open_fee'] = isset($good['open_fee'])?$good['open_fee']:"0";
  494. $value['pakge_fee'] = isset($good['pakge_fee'])?$good['pakge_fee']:"0";
  495. $value['nake_fee'] = isset($good['nake_fee'])?$good['nake_fee']:"0";
  496. $value['mark_fee'] = isset($good['mark_fee'])?$good['mark_fee']:"0";
  497. $value['cert_fee'] = isset($good['cert_fee'])?$good['cert_fee']:"0";
  498. $value['cost_fee'] = isset($good['cost_fee'])?$good['cost_fee']:"0";
  499. $value['rate'] = $value['sale_price'] == 0 ? 0 : round(($value['sale_price'] - $value['origin_price']) / $value['sale_price'] * 100, 2);
  500. $value['supply_area'] = isset($good['supply_area'])?$good['supply_area']:"";
  501. $data[]=$value;
  502. }
  503. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  504. }
  505. public function info(){
  506. $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  507. if($projectNo==""){
  508. return error_show(1004,"参数projectNo不能为空");
  509. }
  510. $type = isset($this->post['type'])&&$this->post['type']!=="" ? intval($this->post['type']) :0;
  511. $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
  512. if($info==false){
  513. return error_show(1004,"未找到项目信息");
  514. }
  515. $plat = Db::name("platform")->where(['id'=>$info['platform_id']])->find();
  516. $info['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  517. $info['platform_code']=isset($plat['platform_code'])?$plat['platform_code']:"";
  518. $khinfo = Db::name("customer_info")->where(["companyNo"=>$info['khNo']])->find();
  519. $info['khName'] = isset($khinfo['companyName'])?$khinfo['companyName']:"";
  520. $company = Db::name("business")->where(["companyNo"=>$info['companyNo']])->find();
  521. $info['company'] = isset($company['company'])?$company['company']:"";
  522. $info['pay_name'] = $info['pay_id']==0?"":Db::name("pay")->where("id",$info['pay_id'])->value("pay_name",'');
  523. $ladder = Db::name("project_info")->where(['projectNo'=>$projectNo,"is_del"=>0])->select()->toArray();
  524. $info['ladder']=[];
  525. if(!empty($ladder)){
  526. foreach ($ladder as $value){
  527. $value["cat_info"]=isset($value['cat_id']) &&$value['cat_id']!=""? made($value['cat_id'],[]):[];
  528. $condition = $type==0?['pgNo'=>$value['pgNo'],"is_del"=>0] : ['pgNo'=>$value['pgNo'],"is_del"=>0,"status"=>1];
  529. $feedback = Db::name("project_feedback")->where($condition)->select()->toArray();
  530. array_walk($feedback,function (&$v){
  531. $v["cat_info"]=isset($v['cat_id'])&&$v['cat_id']!=""? made($v['cat_id'],[]):[];
  532. });
  533. // $zx = Db::name("consult_info")->where(["pgNo"=>$value["pgNo"],"is_del"=>0,"bargain_status"=>0])
  534. // ->column("infoNo");
  535. // if(!empty($zx)){
  536. // $zxback = Db::name("consult_bids")->where(["infoNo"=>$zx,"is_del"=>0])->select()->toArray();
  537. // array_walk($zxback,function (&$v){
  538. // $v["cat_info"]=isset($v['cat_id'])? made($v['cat_id'],[]):[];
  539. // });
  540. // }else{
  541. // $zxback=[];
  542. // }
  543. $value['feedback']=$feedback;
  544. // $value['zxback']=$zxback;
  545. $info['ladder'][]=$value;
  546. }
  547. }
  548. return app_show(0,"获取成功",$info);
  549. }
  550. public function plan_create(){
  551. $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  552. if($projectNo==""){
  553. return error_show(1004,"参数projectNo不能为空");
  554. }
  555. $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
  556. if($info==false){
  557. return error_show(1004,"未找到项目信息");
  558. }
  559. if($info['low_rate']<=0){
  560. return error_show(1004,"项目毛利未设置");
  561. }
  562. if($info['status']!=3 && $info['status']!=4){
  563. return error_show(1004,"项目状态有误");
  564. }
  565. $feedback =isset($this->post['feedback'])&&!empty($this->post['feedback'])?$this->post['feedback']:"";
  566. if($feedback==""){
  567. return error_show(1004,"参数feedback不能为空");
  568. }
  569. $feedid =array_column($feedback,"feedid");
  570. $feedinfo = Db::name("project_feedback")->where(['id'=>$feedid,"projectNo"=>$projectNo,"is_del"=>0])
  571. ->select()->toArray();
  572. if(empty($feedinfo)){
  573. return error_show(1004,"反馈数据未找到");
  574. }
  575. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  576. if($token==''){
  577. return error_show(105,"参数token不能为空");
  578. }
  579. $user =GetUserInfo($token);
  580. if(empty($user)||$user['code']!=0){
  581. return error_show(1002,"用户数据不存在");
  582. }
  583. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  584. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  585. Db::startTrans();
  586. try {
  587. $planNo=makeNo("PL");
  588. $total=0;
  589. $num_t=0;
  590. $origia=0;
  591. $dl=[];
  592. foreach ($feedinfo as $value){
  593. $key =array_search($value['id'],$feedid);
  594. $price = $feedback[$key];
  595. // if($price['sale_price']<$value['origin_price']){
  596. // Db::rollback();
  597. // return error_show(1004,"反馈商品价格不能小于初始金额");
  598. // }
  599. if($price['good_num']<$value['num']){
  600. Db::rollback();
  601. return error_show(1004,"商品数量不能小于初始数量");
  602. }
  603. if($value['data_source']==2){
  604. $bids =Db::name("consult_info")->where(["pgNo"=>$value['pgNo'],"is_del"=>0])->find();
  605. if($bids==false){
  606. Db::rollback();
  607. return error_show(1004,"未找到反馈商品咨询单");
  608. }
  609. $old_bids_status = $bids["status"];
  610. $bids["status"]=3;
  611. $bids["updatetime"]=date("Y-m-d H:i:s");
  612. $bd=Db::name("consult_info")->save($bids);
  613. if($bd==false){
  614. Db::rollback();
  615. return error_show(1004,"反馈商品咨询单更新失败");
  616. }else{
  617. //修改状态,添加待办
  618. ActionLog::logAdd($this->post['token'], [
  619. "order_code" => $bids['infoNo'],//咨询单详情编号
  620. "status" => $old_bids_status,//这里的status是之前的值
  621. "action_remark" => '',//备注
  622. "action_type" => "status"//新建create,编辑edit,更改状态status
  623. ], "ZXD", 3, $bids);
  624. }
  625. }
  626. // $value['sale_price'] = $price['sale_price'];
  627. // $value['updatetime'] = date("Y-m-d H:i:s");
  628. // $cre=Db::name("project_feedback")->save($value);
  629. // if($cre==false){
  630. // Db::rollback();
  631. // return error_show(1004,"反馈商品价格修改失败");
  632. // }
  633. $temp=[];
  634. $temp['planNo']=$planNo;
  635. $temp['feedback_id']=$value['id'];
  636. $temp['sale_price']=$price["sale_price"];
  637. $temp['sale_num']=$price["good_num"];
  638. $temp['status']=1;
  639. $temp['is_del']=0;
  640. $temp['addtime']=date("Y-m-d H:i:s");
  641. $temp['updatetime']=date("Y-m-d H:i:s");
  642. $total+=$price['good_num']*$price["sale_price"];
  643. $origia+=$price['good_num']*$value["origin_price"];
  644. $num_t+=$price['good_num'];
  645. $dl[]=$temp;
  646. }
  647. $rate = round(($total-$origia)/$total,4)*100;
  648. if($rate<$info['low_rate']){
  649. Db::rollback();
  650. return error_show(1004,"方案毛利不能低于最低项目毛利率");
  651. }
  652. $inn=Db::name("project_plan_rela")->insertAll($dl);
  653. if($inn>0){
  654. $data=[
  655. "planNo"=>$planNo,
  656. "projectNo"=>$projectNo,
  657. "createrid"=>$createrid,
  658. "creater"=>$creater,
  659. "sale_total"=>round($total,2),
  660. "total_num"=>$num_t,
  661. "origin_total"=>round($origia,2),
  662. "sale_rate"=>$rate,
  663. "status"=>0,
  664. "is_del"=>0,
  665. "addtime"=>date("Y-m-d H:i:s"),
  666. "updatetime"=>date("Y-m-d H:i:s")
  667. ];
  668. $up =Db::name("project_plan")->insert($data);
  669. if($up){
  670. $old_project_status = $info['status'];
  671. $info['status']=4;
  672. $info['updatetime']=date("Y-m-d H:i:s");
  673. $cr =Db::name("project")->save($info);
  674. if($cr){
  675. //修改状态,添加待办
  676. ActionLog::logAdd($this->post['token'], [
  677. "order_code" => $projectNo,//项目编码
  678. "status" => $old_project_status,//这里的status是之前的值
  679. "action_remark" => '',//备注
  680. "action_type" => "status"//新建create,编辑edit,更改状态status
  681. ], "PRO", 4, $info);
  682. ProcessOrder::AddProcess($this->post['token'], [
  683. "order_type" => 'PRO',
  684. "order_code" => $projectNo,
  685. "order_id" => $info['id'],
  686. "order_status" => 4,
  687. "before_status"=>$old_project_status,
  688. 'holder_id'=>$info['createrid']
  689. ]);
  690. Db::commit();
  691. return app_show(0,"方案制作成功",["planNo"=>$planNo]);
  692. }
  693. }
  694. }
  695. Db::rollback();
  696. return error_show(1004,"方案制作失败");
  697. }catch (\Exception $e){
  698. Db::rollback();
  699. return error_show(1004,$e->getMessage());
  700. }
  701. }
  702. public function planinfo(){
  703. $planNo = isset($this->post['planNo'])&& $this->post['planNo']!==""?trim($this->post["planNo"]):"";
  704. if($planNo==""){
  705. return error_show(1004,"参数planNo不能为空");
  706. }
  707. $plan = Db::name("project_plan")->where(["planNo"=>$planNo,"is_del"=>0])->find();
  708. if($plan==false){
  709. return error_show(1004,"未找到项目方案信息");
  710. }
  711. $plan['feedback']=[];
  712. $feedback =Db::name("project_plan_rela")->where(["planNo"=>$planNo,"is_del"=>0])->column("feedback_id,sale_price,sale_num");
  713. if(!empty($feedback)){
  714. $feedid = array_column($feedback,"feedback_id");
  715. $feedlist = Db::name("project_feedback")->where(["id"=>$feedid,"is_del"=>0])->select();
  716. if(!empty($feedlist)){
  717. foreach ($feedlist as $value){
  718. $key =array_search($value['id'],$feedid);
  719. $price = $feedback[$key]['sale_price'];
  720. $value["cat_info"]=isset($value['cat_id'])&&$value['cat_id']!=""? made($value['cat_id'],[]):[];
  721. $value["sale_price"]=$price;
  722. $value["origin_num"]=$value['num'];
  723. $value["num"]=$feedback[$key]['sale_num'];
  724. $plan['feedback'][]=$value;
  725. }
  726. }
  727. }
  728. return app_show(0,"获取成功",$plan);
  729. }
  730. public function project_plan(){
  731. $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  732. if($projectNo==""){
  733. return error_show(1004,"参数projectNo不能为空");
  734. }
  735. $type = isset($this->post['type'])&&$this->post['type']!=="" ? intval($this->post['type']) :0;
  736. $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
  737. if($info==false){
  738. return error_show(1004,"未找到项目信息");
  739. }
  740. $plat = Db::name("platform")->where(['id'=>$info['platform_id']])->find();
  741. $info['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  742. $info['platform_code']=isset($plat['platform_code'])?$plat['platform_code']:"";
  743. $khinfo = Db::name("customer_info")->where(["companyNo"=>$info['khNo']])->find();
  744. $info['khName'] = isset($khinfo['companyName'])?$khinfo['companyName']:"";
  745. if($type==1){
  746. $where = ['projectNo'=>$projectNo,"is_del"=>0,"status"=>1];
  747. }else{
  748. $where = ['projectNo'=>$projectNo,"is_del"=>0];
  749. }
  750. $ladder = Db::name("project_plan")->where($where)->order("addtime desc")->select()->toArray();
  751. $info=[];
  752. if(!empty($ladder)){
  753. foreach ($ladder as $value){
  754. $value['feedback']=[];
  755. $feedback =Db::name("project_plan_rela")->where(["planNo"=>$value['planNo'],"is_del"=>0])->column("feedback_id,sale_price,sale_num");
  756. if(!empty($feedback)){
  757. $feedid = array_column($feedback,"feedback_id");
  758. $feedlist = Db::name("project_feedback")->where(["id"=>$feedid,"is_del"=>0])->select();
  759. if(!empty($feedlist)){
  760. foreach ($feedlist as $val){
  761. $key =array_search($val['id'],$feedid);
  762. $price = $feedback[$key]['sale_price'];
  763. $val["cat_info"]=isset($val['cat_id'])&&$val['cat_id']!=""? made($val['cat_id'],[]):[];
  764. $val["origin_sale_price"]=$val['sale_price'];
  765. $val["sale_price"]=$price;
  766. $val["origin_num"]=$val['num'];
  767. $val["num"]=$feedback[$key]['sale_num'];
  768. if($val['data_source']!=1){
  769. $good=Db::name("consult_bids")->where(["spuCode"=>$val['spuCode'],"is_del"=>0])->find();
  770. $good['specinfo']=isset($good['specinfo'])&&$good['specinfo']!=""?json_decode($good['specinfo'],true):[];
  771. }else{
  772. $good=Db::name("good")->where(["spuCode"=>$val['spuCode'],"is_del"=>0])->find();
  773. $spec = Db::name("good_spec")->where(["spuCode"=>$val['spuCode'],"is_del"=>0])->select()->toArray();
  774. $good['specinfo']=[];
  775. if(!empty($spec)){
  776. foreach ($spec as $vae){
  777. $specs=Db::name("specs")->where(["id"=>$vae['spec_id']])->find();
  778. $spec_value = Db::name("spec_value")->where(["id"=>$vae["spec_value_id"]])->find();
  779. $temp = ["specid"=>$vae['spec_id'],"spec_name"=>$specs['spec_name'],"spec_value_id"=>$vae['spec_value_id'],"spec_value_name"=>$spec_value["spec_value"]];
  780. $good['specinfo'][]=$temp;
  781. }
  782. }
  783. }
  784. if(isset($good['brand_id'])){
  785. $brand =Db::name("brand")->where(["id"=>$good['brand_id']])->find();
  786. }
  787. $val['good_img']=isset($good['good_thumb_img'])&&$good['good_thumb_img']!=""?trim($good['good_thumb_img']):"";
  788. $val['brand_id']=isset($good['brand_id'])&&$good['brand_id']!=""?$good['brand_id']:"";
  789. $val['brand_name']=isset($brand['brand_name'])&&$brand['brand_name']!=""?$brand['brand_name']:"";
  790. $val['specinfo']=isset($good['specinfo'])&&$good['specinfo']!=""?$good['specinfo']:[];
  791. $value['feedback'][]=$val;
  792. }
  793. }
  794. }
  795. $info[]=$value;
  796. }
  797. }
  798. return app_show(0,"获取成功",$info);
  799. }
  800. public function feedCheck(){
  801. $feedid = isset($this->post['feedid'])&&!empty($this->post['feedid']) ? $this->post['feedid'] :[];
  802. if(empty($feedid)){
  803. return error_show(1004,"参数feedid不能为空");
  804. }
  805. $feedid=array_unique($feedid);
  806. $selec = Db::name("project_feedback")->where(["id"=>$feedid,'is_del'=>0,"status"=>0])->select()->toArray();
  807. if(empty($selec)){
  808. return error_show(1004,"反馈数据信息未找到");
  809. }
  810. $pgnos =array_column($selec,"pgNo");
  811. $infolist = Db::name("project_info")->where(['pgNo'=>$pgnos])->select()->toArray();
  812. if(empty($infolist)){
  813. return error_show(1004,"项目商品数据未找到");
  814. }
  815. Db::startTrans();
  816. try{
  817. $up = Db::name("project_feedback")->where(["id"=>$feedid,'is_del'=>0,"status"=>0])->save(["status"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  818. if($up){
  819. foreach ($infolist as $value){
  820. $poject=Db::name("project")->where(["projectNo"=>$value['projectNo']])->find();
  821. if($poject==false){
  822. Db::rollback();
  823. return error_show(1004,"项目单未找到");
  824. }
  825. $old_projectinfo_status = $value['status'];
  826. $value['status']=3;
  827. $value['updatetime']=date("Y-m-d H:i:s");
  828. $up = Db::name("project_info")->save($value);
  829. if($up){
  830. //修改状态,添加待办,只记录动作
  831. ActionLog::logAdd($this->post['token'], [
  832. "order_code" => $value['pgNo'],//编码
  833. "status" => $old_projectinfo_status,//这里的status是之前的值
  834. "action_remark" => '',//备注
  835. "action_type" => "status"//新建create,编辑edit,更改状态status
  836. ], "PRI", 3, $value);
  837. $count = Db::name("project_info")->where(["projectNo"=>$value['projectNo'],"status"=>2])
  838. ->count();
  839. if($count==0){
  840. $proc =Db::name("project")->where(["projectNo"=>$value['projectNo']])->save
  841. (["status"=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  842. if(!$proc){
  843. Db::rollback();
  844. return error_show(1004,"反馈数据选择失败");
  845. }else{
  846. //修改状态,添加待办
  847. ActionLog::logAdd($this->post['token'], [
  848. "order_code" =>$value['projectNo'],//项目编码
  849. "status" => $poject['status'],//这里的status是之前的值
  850. "action_remark" => '',//备注
  851. "action_type" => "status"//新建create,编辑edit,更改状态status
  852. ], "PRO", 3, ["status"=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  853. ProcessOrder::AddProcess($this->post['token'], [
  854. "order_type" => 'PRO',
  855. "order_code" =>$value['projectNo'],
  856. "order_id" => $poject['id'],
  857. "order_status" => 3,
  858. "before_status"=>$poject['status'],
  859. 'holder_id'=>$poject['createrid']
  860. ]);
  861. }
  862. }
  863. }else{
  864. Db::rollback();
  865. return error_show(1004,"反馈数据选择失败");
  866. }
  867. }
  868. Db::commit();
  869. return app_show(0,"反馈数据选择成功");
  870. }else{
  871. Db::rollback();
  872. return error_show(1004,"反馈数据选择失败");
  873. }
  874. }catch (\Exception $e){
  875. Db::rollback();
  876. return error_show(1004,$e->getMessage());
  877. }
  878. }
  879. public function planCheck(){
  880. $planNos = isset($this->post['planNos'])&&!empty($this->post['planNos'])? $this->post['planNos'] :"";
  881. if($planNos==""){
  882. return error_show(1004,"参数planNos不能为空");
  883. }
  884. $status=isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  885. if($status==""){
  886. return error_show(1004,"参数status不能为空");
  887. }
  888. $selec = Db::name("project_plan")->where(["planNo"=>$planNos,'is_del'=>0,"status"=>0])->select()->toArray();
  889. if(empty($selec)){
  890. return error_show(1004,"项目方案数据信息未找到");
  891. }
  892. Db::startTrans();
  893. try{
  894. $up = Db::name("project_plan")->where(["planNo"=>$planNos,'is_del'=>0,"status"=>0])->save(["status"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  895. if($up) {
  896. foreach ($selec as $value){
  897. //修改状态,添加待办,只记录动作
  898. ActionLog::logAdd($this->post['token'], [
  899. "order_code" => $value['planNo'],//编码
  900. "status" => $value['status'],//这里的status是之前的值
  901. "action_remark" => '',//备注
  902. "action_type" => "edit"//新建create,编辑edit,更改状态status
  903. ], "PRO", 1, $value);
  904. }
  905. $project = array_column($selec, "projectNo");
  906. if (empty($project)) {
  907. Db::rollback();
  908. return error_show(1004, "方案选择失败");
  909. }
  910. $pro = Db::name("project")->where(["projectNo" => $project, "status" => 4])->save(["status" => 5, "updatetime" => date("Y-m-d H:i:s")]);
  911. if ($pro) {
  912. foreach ($project as $value){
  913. $poject=Db::name("project")->where(["projectNo"=>$value])->find();
  914. if($poject==false){
  915. Db::rollback();
  916. return error_show(1004,"项目单未找到");
  917. }
  918. //修改状态,添加待办
  919. ActionLog::logAdd($this->post['token'], [
  920. "order_code" =>$value,//项目编码
  921. "status" => 4,//这里的status是之前的值
  922. "action_remark" => '',//备注
  923. "action_type" => "status"//新建create,编辑edit,更改状态status
  924. ], "PRO", 5, ["status"=>5,"updatetime"=>date("Y-m-d H:i:s")]);
  925. ProcessOrder::AddProcess($this->post['token'], [
  926. "order_type" => 'PRO',
  927. "order_code" =>$value,
  928. "order_id" => $poject['id'],
  929. "order_status" => 5,
  930. "before_status"=>4,
  931. 'holder_id'=>$poject['createrid']
  932. ]);
  933. }
  934. Db::commit();
  935. return app_show(0, "方案数据修改成功");
  936. }
  937. }
  938. Db::rollback();
  939. return error_show(1004,"方案选择失败");
  940. }catch (\Exception $e){
  941. Db::rollback();
  942. return error_show(1004,$e->getMessage());
  943. }
  944. }
  945. public function changeRate(){
  946. $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
  947. if($projectNo==""){
  948. return error_show(1004,"参数projectNo不能为空");
  949. }
  950. $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
  951. if($info==false){
  952. return error_show(1004,"未找到项目信息");
  953. }
  954. $rate = isset($this->post['rate'])&&$this->post['rate']!=="" ?floatval($this->post['rate']):"";
  955. if($rate===""){
  956. return error_show(1004,"参数rate不能为空");
  957. }
  958. $info['low_rate']=$rate;
  959. $info['updatetime']=date("Y-m-d H:i:s");
  960. $up =Db::name("project")->save($info);
  961. if($up){
  962. return app_show(0,"利润率修改成功");
  963. }else{
  964. return error_show(1004,"利润率修改失败");
  965. }
  966. }
  967. //废弃???@wf by 22.09.01(在路由文件中没有找到这个方法)
  968. public function order(){
  969. $id = isset($this->post['id'])&& $this->post['id']!=="" ? intval($this->post['id']):"";
  970. if($id==""){
  971. return error_show(1004,"参数id不能为空");
  972. }
  973. $backinfo = Db::name("project_feedback")->where(["id"=>$id,"is_del"=>0])->find();
  974. if($backinfo==false){
  975. return error_show(1004,"未找到数据");
  976. }
  977. $prject = Db::name("project")->where(["projectNo"=>$backinfo['projectNo'],"is_del"=>0])->find();
  978. if($prject==false) {
  979. return error_show(1004, "未找到项目数据");
  980. }
  981. $send_type =isset($this->post['send_type'])&&$this->post['send_type']!=""? intval($this->post['send_type']):"";
  982. if($send_type==""){
  983. return error_show(1004,"参数send_type不能为空");
  984. }
  985. if($send_type==1){
  986. $va = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  987. if ($va == "") {
  988. return error_show(1002, "参数order_addr不能为空");
  989. }
  990. }
  991. $plat = Db::name("platform")->where(["id"=>$prject['platform_id']])->find();
  992. $token = isset($this->post['token'])&& $this->post['token']!=="" ? trim($this->post['token']):"";
  993. if($token==""){
  994. return error_show(1004,"参数token不能为空");
  995. }
  996. $apply_id = GetUserInfo($token);
  997. if (empty($apply_id) || $apply_id['code'] != 0) {
  998. return error_show(1002, "申请人数据不存在");
  999. }
  1000. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1001. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1002. $orderCode = makeNo("QR");
  1003. Db::startTrans();
  1004. try{
  1005. $data = [
  1006. "orderCode" => $orderCode,
  1007. "good_code" => $backinfo['spuCode'],
  1008. "customer_code" => $prject['khNo'],
  1009. "good_name" => $backinfo['good_name'],
  1010. "good_num" => $backinfo['num'],
  1011. "order_type" =>3,
  1012. "order_source" =>3,//3项目
  1013. "item_code"=>isset($plat['platform_code'])? $plat['platform_code']:"",
  1014. "good_type"=>1,
  1015. "apply_id" => $rm,
  1016. "apply_name" => $ri,
  1017. "origin_price" =>$backinfo['nake_price'],
  1018. "sale_price" => $backinfo['sale_price'],
  1019. "post_fee" => 0,
  1020. "status" => 0,
  1021. "supplierNo" =>$prject['companyNo'],
  1022. "send_num" => 0,
  1023. "zxNo"=>$backinfo['pgNo'],
  1024. "wsend_num" => $backinfo['num'],
  1025. "send_type" => $send_type,
  1026. "send_status" => 1,
  1027. "is_del" => 0,
  1028. "addtime" => date("Y-m-d H:i:s"),
  1029. "updatetime" => date("Y-m-d H:i:s"),
  1030. 'total_price' => $backinfo['sale_price'] * $backinfo['num'],
  1031. ];
  1032. $datainfo = Db::name('sale')->insert($data, true);
  1033. if($datainfo>0){
  1034. if($send_type==1){
  1035. foreach ($va as $value) {
  1036. $temp = [];
  1037. $addrs = [];
  1038. if ($value['addr_code'] !== '' && is_array($value['addr_code'])) {
  1039. $addrs['provice_code'] = $value['addr_code'][0];
  1040. $addrs['city_code'] = $value['addr_code'][1];
  1041. $addrs['area_code'] = $value['addr_code'][2];
  1042. $addr = json_encode($addrs);
  1043. } else {
  1044. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  1045. }
  1046. $temp['orderCode'] = $orderCode;
  1047. $temp['contactor'] = $value['contactor'];
  1048. $temp['mobile'] = $value['mobile'];
  1049. $temp['addr'] = $value['addr'];
  1050. $temp['addr_code'] = $addr;
  1051. $temp['customer_code'] = $prject['khNo'];
  1052. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1053. $temp['post_fee'] = 0;
  1054. $temp['is_del'] = 0;
  1055. $temp['addtime'] = date("Y-m-d H:i:s");
  1056. $temp['updatetime'] = date("Y-m-d H:i:s");
  1057. $temp['arrive_time'] = date("Y-m-d H:i:s");
  1058. $vat[] = $temp;
  1059. }
  1060. $vmp = Db::name('order_addr')->insertAll($vat);
  1061. if ($vmp==false) {
  1062. Db::rollback();
  1063. return error_show(1004, "销售订单创建失败");
  1064. }
  1065. }
  1066. Db::name('standing_book')
  1067. ->where('projectNo', $backinfo['projectNo'])
  1068. ->update([
  1069. 'sale_id' => $datainfo,
  1070. 'orderCode' => $orderCode,
  1071. 'customer_code' => $prject['khNo'],
  1072. 'spuCode' => $backinfo['spuCode'],
  1073. 'order_type' => $data['order_type'],
  1074. 'order_source' => $data['order_source'],
  1075. 'supplierNo' => $prject['companyNo'],
  1076. 'updatetime' => date("Y-m-d H:i:s")
  1077. ]);
  1078. Db::commit();
  1079. return error_show(0, "销售订单创建成功");
  1080. }
  1081. Db::rollback();
  1082. return error_show(1004, "销售订单创建失败");
  1083. }catch (\Exception $w){
  1084. Db::rollback();
  1085. return error_show(1004, $w->getMessage());
  1086. }
  1087. }
  1088. public function feeddel(){
  1089. $feedid = isset($this->post['id'])&&!empty($this->post['id']) ? $this->post['id'] :[];
  1090. if(empty($feedid)){
  1091. return error_show(1004,"参数feedid不能为空");
  1092. }
  1093. $selec = Db::name("project_feedback")->where(["id"=>$feedid,'is_del'=>0])->select();
  1094. if(empty($selec)){
  1095. return error_show(1004,"反馈数据信息未找到");
  1096. }
  1097. $up = Db::name("project_feedback")->where(["id"=>$feedid,'is_del'=>0])->save(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  1098. if($up){
  1099. return app_show(0,"反馈数据删除成功");
  1100. }else{
  1101. return error_show(1004,"反馈数据删除失败");
  1102. }
  1103. }
  1104. }