Project.php 61 KB

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