Project.php 61 KB

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