Consult.php 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  1. <?php
  2. namespace app\abutment\controller;
  3. use app\admin\common\User;
  4. use app\admin\model\ActionLog;
  5. use app\admin\model\ProcessOrder;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. class Consult extends HomeBaseController
  9. {
  10. private $noble = ['0' => '', '1' => '18K', '2' => '24K', '3' => '白银'];
  11. //招标工作台列表
  12. public function crontablist()
  13. {
  14. $this->post = $this->request->filter('trim')->post();
  15. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  16. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  17. //过滤贵金属相关的记录
  18. $where = [['a.is_del', "=", 0], ['b.is_del', "=", 0], ['a.cat_id', "not in", [6, 65, 88, 396, 718, 719, 819]]];
  19. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  20. if ($zxNo !== "") $where[] = ['a.zxNo', '=', $zxNo];
  21. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  22. if ($salesman !== "") $where[] = ["b.salesman", 'like', "%$salesman%"];
  23. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  24. if ($cpName !== "") $where[] = ["a.good_Name", 'like', "%$cpName%"];
  25. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  26. if ($khNo !== "") $where[] = ["b.khNo", 'like', "%$khNo%"];
  27. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  28. if ($start != "") $where[] = ["a.addtime", '>=', $start];
  29. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  30. if ($end != "") $where[] = ["a.addtime", '<=', $end];
  31. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  32. if ($status !== "") $where[] = ["a.status", '=', $status];
  33. $count = Db::name('consult_info')
  34. ->alias("a")
  35. ->leftJoin("consult_order b", "a.zxNo=b.zxNo")
  36. ->where($where)
  37. ->count();
  38. $total = ceil($count / $size);
  39. $page = $page >= $total ? $total : $page;
  40. $list = Db::name('consult_info')
  41. ->alias("a")
  42. ->leftJoin("consult_order b", "a.zxNo=b.zxNo")
  43. ->where($where)
  44. ->page($page, $size)
  45. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")
  46. ->select()
  47. ->toArray();
  48. $data = [];
  49. $all_cat = Db::name('cat')
  50. ->whereIn('id', array_column($list, 'cat_id'))
  51. ->column('order_rate', 'id');
  52. $all_brand = Db::name('brand')
  53. ->whereIn('id', array_column($list, 'brand_id'))
  54. ->column('brand_name', 'id');
  55. $userCommon = new User();
  56. $customer = $userCommon->handle('getCodeAndName',['code'=>array_column($list,'khNo')]);
  57. foreach ($list as $value) {
  58. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  59. // $cat = Db::name("cat")->where(["id" => $value['cat_id']])->find();
  60. $budget = isset($all_cat[$value['cat_id']]) ? $all_cat[$value['cat_id']] : 0;
  61. $value['original_price'] = sprintf("%.2f", $value['budget_price'] * (1 - $budget / 100));
  62. // $brand = Db::name("brand")->where(['id' => $value['brand_id']])->find();
  63. $value['brand_name'] = isset($all_brand[$value['brand_id']]) && $all_brand[$value['brand_id']] != '' ? $all_brand[$value['brand_id']] : "";
  64. $value['khname'] = "";
  65. $value['specinfo'] = isset($value['specinfo']) && $value['specinfo'] != "" ? json_decode($value['specinfo'], true) : [];
  66. if ($value['khNo'] !== "") {
  67. // $kh = Db::name("customer_info")
  68. // ->where(['companyNo' => $value['khNo']])
  69. // ->find();
  70. $value['khname'] = $customer['data'][$value['khNo']]??'';//isset($kh['companyName']) ? $kh['companyName'] : "";
  71. }
  72. $consult = Db::name("consult_bids")
  73. ->where(["infoNo" => $value['infoNo'], "createrid" => $this->request->user['uid'], "is_del" => 0])
  74. ->find();
  75. $consults = Db::name("consult_bids")
  76. ->where(["infoNo" => $value['infoNo'], "is_del" => 0])
  77. ->find();
  78. $value['is_feed'] = $consult == false ? 0 : 1;
  79. $value['is_all_feed'] = $consults == false ? 0 : 1;
  80. $value['metal_name'] = isset($value['metal_id']) && $value['metal_id'] != 0 ? $this->noble[$value['metal_id']] : "";
  81. $data[] = $value;
  82. }
  83. return json_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  84. }
  85. //招标工作台详情
  86. public function zxinfo()
  87. {
  88. $this->post = $this->request->filter('trim')->post();
  89. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] != "" ? trim($this->post['infoNo']) : "";
  90. if ($infoNo == "") {
  91. return json_show(1004, "参数infoNo不能为空");
  92. }
  93. $zxinfo = Db::name("consult_info")->where(["infoNo" => $infoNo, "is_del" => 0])->find();
  94. if ($zxinfo == false) {
  95. return json_show(1004, "未找到信息数据");
  96. }
  97. $zxorder = Db::name("consult_order")->where(["zxNo" => $zxinfo['zxNo'], "is_del" => 0])->find();
  98. if ($zxorder == false) {
  99. return json_show(1004, "未找到咨询信息数据");
  100. }
  101. $cat = Db::name("cat")->where(["id" => $zxinfo['cat_id']])->find();
  102. $budget = isset($cat['order_rate']) ? $cat['order_rate'] : 0;
  103. $zxinfo['can'] = isset($zxinfo['cat_id']) && $zxinfo['cat_id'] != 0 ? made($zxinfo['cat_id'], []) : [];
  104. $zxinfo['khname'] = "";
  105. $zxinfo['original_price'] = sprintf("%.2f", $zxinfo['budget_price'] * (1 - $budget / 100));
  106. $zxinfo['khNo'] = "";
  107. $zxinfo['brand_id'] = $zxinfo['brand_id'] == 0 ? "" : $zxinfo['brand_id'];
  108. $zxinfo['brand'] = "";
  109. $zxinfo['companyNo'] = isset($zxorder['companyNo']) ? $zxorder['companyNo'] : "";
  110. $zxinfo['projectNo'] = isset($zxorder['projectNo']) ? $zxorder['projectNo'] : "";
  111. $zxinfo['is_project'] = isset($zxorder['is_project']) ? $zxorder['is_project'] : "";
  112. $zxinfo['company'] = "";
  113. $zxinfo['endtime'] = isset($zxorder['endtime']) ? $zxorder['endtime'] : "";
  114. $zxinfo['platform_code'] = isset($zxorder['platform_code']) ? $zxorder['platform_code'] : "";
  115. $zxinfo['salesman'] = isset($zxorder['salesman']) ? $zxorder['salesman'] : "";
  116. $zxinfo['saleid'] = isset($zxorder['saleid']) ? $zxorder['saleid'] : "";
  117. $zxinfo['depart'] = isset($zxorder['depart']) ? $zxorder['depart'] : "";
  118. $zxinfo['project_name'] = "";
  119. $zxinfo['budget_total'] = "";
  120. $zxinfo['departinfo'] = [];
  121. $zxinfo['unit_name'] = "";
  122. $zxinfo['metal_name'] = isset($zxinfo['metal_id']) && $zxinfo['metal_id'] != 0 ? $this->noble[$zxinfo['metal_id']] : "";
  123. $zxinfo['specinfo'] = json_decode($zxinfo['specinfo'], true);
  124. $codes=[];
  125. if ($zxorder['khNo'] !== "") $codes[]=$zxorder['khNo'];
  126. // $kh = Db::name("customer_info")->where(['companyNo' => $zxorder['khNo']])->find();
  127. // $zxinfo['khname'] = isset($kh['companyName']) ? $kh['companyName'] : "";
  128. // $zxinfo['khNo'] = $zxorder['khNo'];
  129. // }
  130. if ($zxinfo['unit'] !== "") {
  131. $unit = Db::name("unit")->where(['id' => $zxinfo['unit']])->find();
  132. $zxinfo['unit_name'] = isset($unit['unit']) ? $unit['unit'] : "";
  133. }
  134. if ($zxinfo['brand_id'] !== "") {
  135. $unit = Db::name("brand")->where(['id' => $zxinfo['brand_id']])->find();
  136. $zxinfo['brand'] = isset($unit['brand_name']) ? $unit['brand_name'] : "";
  137. }
  138. if ($zxorder['companyNo'] !== "") $codes[]=$zxorder['companyNo'];
  139. // $kh = Db::name("business")->where(['companyNo' => $zxorder['companyNo']])->find();
  140. // $zxinfo['company'] = isset($kh['company']) ? $kh['company'] : "";
  141. // }
  142. if ($zxorder['is_project'] == 1 && $zxorder['projectNo'] !== "") {
  143. $project = Db::name("project")->where(["projectNo" => $zxorder['projectNo'], "is_del" => 0])->find();
  144. $zxinfo['project_name'] = isset($project['project_name']) ? $project['project_name'] : "";
  145. $zxinfo['budget_total'] = isset($project['budget_total']) ? $project['budget_total'] : "";
  146. $zxinfo['project_use_desc'] = isset($project['use_desc']) ? $project['use_desc'] : "";
  147. $projectinfo = Db::name("project_info")->where(["pgNo" => $zxinfo['pgNo']])->find();
  148. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo'] : "";
  149. }
  150. $userCommon = new User();
  151. if ($zxorder['depart'] > 0) {
  152. $rs = $userCommon->handle('ciinfo', ['id' => $zxorder['depart']]);
  153. $zxinfo['departinfo'] = $rs['data'] ?? [];
  154. }
  155. if ($zxorder['platform_code'] > 0) {
  156. $palt = Db::name("platform")->where(["id" => $zxorder['platform_code']])->find();
  157. $zxinfo['platform_name'] = isset($palt['platform_name']) ? $palt['platform_name'] : "";
  158. }
  159. if($codes){
  160. $names = $userCommon->handle('getCodeAndName',['code'=>$codes]);
  161. $zxinfo['khname'] = $names['data'][$zxorder['khNo']]??'';//isset($kh['companyName']) ? $kh['companyName'] : "";
  162. $zxinfo['khNo'] = $zxorder['khNo'];
  163. $zxinfo['company'] = $names['data'][$zxorder['companyNo']]??'';//
  164. }
  165. return json_show(0, "获取成功", $zxinfo);
  166. }
  167. //采反商品列表
  168. public function bidlist()
  169. {
  170. $this->post = $this->request->filter('trim')->post();
  171. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  172. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  173. $where = [['is_del', "=", 0]];
  174. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  175. if ($zxNo !== "") {
  176. $where[] = ['zxNo', 'like', '%' . $zxNo . '%'];
  177. }
  178. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  179. if ($infoNo !== "") {
  180. $where[] = ['infoNo', 'like', '%' . $infoNo . '%'];
  181. }
  182. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  183. if ($bidNo !== "") {
  184. $where[] = ['bidNo', 'like', '%' . $bidNo . '%'];
  185. }
  186. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  187. if ($pgNo !== "") {
  188. $bidinfo = Db::name("consult_info")->where([["pgNo", "=", $pgNo], ["is_del", "=", 0]])->column("infoNo");
  189. $where[] = ['infoNo', 'in', $bidinfo];
  190. }
  191. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  192. if ($bargain_status !== "") {
  193. $bidinfo = Db::name("consult_info")->where([["bargain_status", "=", $bargain_status], ["is_del", "=", 0]])->column("infoNo");
  194. $where[] = ['infoNo', 'in', $bidinfo];
  195. }
  196. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  197. if ($projectNo !== "") {
  198. $zxlist = Db::name("consult_order")->where(["projectNo" => $projectNo, "is_del" => 0, "is_project" => 1])->column("zxNo");
  199. $where[] = ['zxNo', 'in', $zxlist];
  200. }
  201. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  202. if ($is_own == 1) {
  203. // $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  204. // if($token==""){
  205. // return json_show(101,'token不能为空');
  206. // }
  207. // $apply_id =GetUserInfo($token);
  208. // if(empty($apply_id)||$apply_id['code']!=0){
  209. // return json_show(1002,"申请人数据不存在");
  210. // }
  211. $rm = $this->request->user['uid'];
  212. $where[] = ['createrid', "=", $rm];
  213. }
  214. $count = Db::name('consult_bids')->where($where)->count();
  215. $total = ceil($count / $size);
  216. $page = $page >= $total ? $total : $page;
  217. $list = Db::name('consult_bids')->where($where)->page($page, $size)->select()->toArray();
  218. $data = [];
  219. foreach ($list as $value) {
  220. $catinfo = Db::name("cat")->where(["id" => $value['cat_id']])->find();
  221. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  222. $unit = Db::name("unit")->where(["id" => $value['unit_id']])->find();
  223. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  224. $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  225. $value['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  226. if ($value['brand_id'] != 0) {
  227. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  228. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  229. } else {
  230. $value["brand_name"] = "";
  231. $value["brand_id"] = "";
  232. }
  233. $bidinfo = Db::name("consult_info")->where(["infoNo" => $value["infoNo"]])->find();
  234. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] : 0;
  235. $god = [
  236. "metal_id" => $value['metal_id'],
  237. "weight" => $value["good_weight"],
  238. "demo_fee" => $value["demo_fee"],
  239. "delivery_fee" => $value["delivery_fee"],
  240. "open_fee" => $value["open_fee"],
  241. "packing_fee" => $value["pakge_fee"],
  242. "mark_fee" => $value["mark_fee"],
  243. "nake_fee" => $value["nake_fee"],
  244. "cert_fee" => $value["cert_fee"],
  245. // "cost_fee"=>$value["cost_fee"],
  246. "cost_fee" => $value["sale_cost_fee"] != $value['origin_cost_fee'] ? $value["sale_cost_fee"] : $value["cost_fee"],
  247. "num" => $bidinfo["num"],
  248. ];
  249. $top_cat = made($value['cat_id']);
  250. $top_cat_id = isset($top_cat[0]['id']) ? $top_cat[0]['id'] : 0;
  251. if ($value['is_gold_price'] == 1 && $top_cat_id == 6) {
  252. $price = GoldPrice($god, $budget / 100);
  253. $value['sale_price'] = round($price, 2);
  254. $value['origin_price'] = $value["sale_cost_fee"] != $value['origin_cost_fee'] ? $value["sale_price"] :
  255. $value["origin_price"];
  256. }
  257. $value['cost_fee'] = $value['origin_cost_fee'];
  258. $value['specinfo'] = json_decode($value['specinfo'], true);
  259. $value['metal_name'] = isset($value['metal_id']) && $value['metal_id'] != 0 ? $this->noble[$value['metal_id']] : "";
  260. $value['bargain_status'] = $bidinfo['bargain_status'];
  261. //reject驳回原因,status==5表示驳回
  262. $value['reject'] = [];
  263. if ($value['status'] >= 5) {
  264. $value['reject'] = Db::name('bargain_order')
  265. ->field('id,remark,status')
  266. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  267. ->whereIn('status', [3, 8, 11])->order("id desc")
  268. ->find();
  269. }
  270. //产地
  271. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  272. if ($value['delivery_place'] != "") {
  273. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['delivery_place']);
  274. }
  275. $value['delivery_place_cn'] = GetAddr(json_encode($place));
  276. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  277. if ($value['origin_place'] != "") {
  278. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['origin_place']);
  279. }
  280. $value['origin_addr'] = GetAddr(json_encode($place));
  281. // if($value['origin_place']!=''){
  282. // $code = explode(",",$value['origin_place']);
  283. // $temp=[];
  284. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  285. // $temp['city_code']=isset($code[1])?$code[1]:"";
  286. // $temp['area_code']=isset($code[2])?$code[2]:"";
  287. // $addr= GetAddr(json_encode($temp));
  288. // $value['origin_addr'] = $addr;
  289. // }
  290. $data[] = $value;
  291. }
  292. return json_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  293. }
  294. //创建采反商品
  295. public function create()
  296. {
  297. $this->post = $this->request->filter('trim')->post();
  298. $is_project = isset($this->post['is_project']) && $this->post['is_project'] !== "" ? intval($this->post['is_project']) : "";
  299. if ($is_project === "") {
  300. return json_show(1002, "参数is_project不能为空");
  301. }
  302. if ($is_project == 1) {
  303. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  304. if ($projectNo === "") {
  305. return json_show(1002, "参数projectNo不能为空");
  306. }
  307. }
  308. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  309. if ($khNo === "") {
  310. return json_show(1002, "参数khNo不能为空");
  311. }
  312. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  313. if ($companyNo === "") {
  314. return json_show(1002, "参数companyNo不能为空");
  315. }
  316. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !== "" ? $this->post['endtime'] : "";
  317. if ($endtime === "") {
  318. return json_show(1002, "参数endtime不能为空");
  319. }
  320. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !== "" ? trim($this->post['platform_code']) :
  321. "";
  322. if ($platform_code === "") {
  323. return json_show(1002, "参数platform_code不能为空");
  324. }
  325. $ladder = isset($this->post['ladder']) && !empty($this->post['ladder']) ? $this->post['ladder'] : "";
  326. if ($ladder == "") {
  327. return json_show(1005, "参数ladder不能为空");
  328. }
  329. // $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  330. // if($token==''){
  331. // return json_show(105,"参数token不能为空");
  332. // }
  333. // $user =GetUserInfo($token);
  334. // if(empty($user)||$user['code']!=0){
  335. // return json_show(102,"用户数据不存在");
  336. // }
  337. $createrid = $this->request->user['uid'];
  338. $creater = $this->request->user['nickname'];
  339. $depart = Db::name("depart_user")->where(["uid" => $createrid, "status" => 1, "is_del" => 0])->find();
  340. $zxNo = makeNo("ZX");
  341. Db::startTrans();
  342. try {
  343. $data = [
  344. "zxNo" => $zxNo,
  345. "createrid" => $createrid,
  346. "creater" => $creater,
  347. "is_project" => $is_project,
  348. "projectNo" => isset($projectNo) ? $projectNo : "",
  349. "khNo" => $khNo,
  350. "companyNo" => $companyNo,
  351. "endtime" => $endtime,
  352. "salesman" => $creater,
  353. "platform_code" => $platform_code,
  354. "saleid" => $createrid,
  355. "depart" => isset($depart['itemid']) ? $depart['itemid'] : 0,
  356. "status" => 0,
  357. "is_del" => 0,
  358. "addtime" => date("Y-m-d H:i:s"),
  359. "updatetime" => date("Y-m-d H:i:s"),
  360. ];
  361. $zx = Db::name("consult_order")->insert($data);
  362. if ($zx) {
  363. //判断是否是项目,且该项目是否存在台账记录中
  364. if ($is_project == 1) $stand_exists = Db::name('standing_book')->field('id')->where('projectNo', $projectNo)->find();
  365. foreach ($ladder as $value) {
  366. $infoNo = makeNo("IF");
  367. $specinfo = [];
  368. if (isset($value['specinfo']) && !empty($value['specinfo'])) {
  369. foreach ($value["specinfo"] as $v) {
  370. $spec = Db::name("specs")->where(["id" => $v['specid']])->find();
  371. $spec_value = Db::name("spec_value")->where(["id" => $v['spec_value_id']])->find();
  372. $v['spec_name'] = isset($spec['spec_name']) ? $spec['spec_name'] : "";
  373. $v['spec_value_name'] = isset($spec_value['spec_value']) ? $spec_value['spec_value'] : "";
  374. $specinfo[] = $v;
  375. }
  376. }
  377. $info = [
  378. "infoNo" => $infoNo,
  379. "zxNo" => $zxNo,
  380. "spuCode" => "",
  381. "good_name" => $value['good_name'],
  382. "good_img" => $value['good_img'],
  383. "cat_id" => $value['cat_id'],
  384. "unit" => $value['unit'],
  385. "brand_id" => $value['brand_id'],
  386. "arrival_time" => $value['arrival_time'],
  387. "specinfo" => empty($specinfo) ? "" : json_encode($specinfo),
  388. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  389. "is_addrs" => $value['is_addrs'],
  390. "is_custom" => $value['is_custom'],
  391. "metal_id" => $value['metal_id'],
  392. "config" => isset($value['config']) ? $value['config'] : "",
  393. "other_config" => isset($value['other_config']) ? $value['other_config'] : "",
  394. "specs_weight" => isset($value['specs_weight']) ? $value['specs_weight'] : "0",
  395. "gold_price" => isset($value['gold_price']) ? $value['gold_price'] : "0",
  396. "is_gold_price" => isset($value['is_gold_price']) ? $value['is_gold_price'] : "0",
  397. "total_weight" => isset($value['total_weight']) ? $value['total_weight'] : "0",
  398. "budget_price" => $value['budget_price'],
  399. "num" => $value['num'],
  400. "pgNo" => isset($value['pgNo']) && $value['pgNo'] !== "" ? trim($value['pgNo']) : "",
  401. "use_desc" => $value['use_desc'],
  402. "remark" => $value['remark'],
  403. "status" => 1,
  404. "is_del" => 0,
  405. "addtime" => date("Y-m-d H:i:s"),
  406. "updatetime" => date("Y-m-d H:i:s"),
  407. 'enclosure_file' => isset($value['enclosure_file']) ? $value['enclosure_file'] : '',
  408. ];
  409. $up = Db::name("consult_info")->insertGetId($info);
  410. if (!$up) {
  411. Db::rollback();
  412. return json_show(1004, '添加失败');
  413. } else {
  414. //修改状态
  415. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  416. "order_code" => $infoNo,//咨询单详情编号
  417. "status" => 1,//这里的status是之前的值
  418. "action_remark" => '',//备注
  419. "action_type" => "create"//新建create,编辑edit,更改状态status
  420. ], "ZXD", 1, $info);
  421. //竞价单不走流程,不推待办已办
  422. // ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  423. // "order_type" => 'ZXD',
  424. // "order_code" => $infoNo,//咨询单详情编号
  425. // "order_id" => $up,
  426. // "order_status" => 1,
  427. // 'before_status'=>0
  428. // ]);
  429. //如果存在该项目编码,更新对应的第一个竞价单编码,其他竞价单编码新增(带着项目编码)
  430. if (isset($stand_exists)) {
  431. Db::name('standing_book')
  432. ->where('id', $stand_exists['id'])
  433. ->update([
  434. 'infoNo' => $infoNo,
  435. 'updatetime' => date('Y-m-d H:i:s')
  436. ]);
  437. unset($stand_exists);//后面的竞价单编码不用更新,都是新增
  438. } else {
  439. //添加台账信息
  440. Db::name('standing_book')
  441. ->insert([
  442. 'standBookNo' => makeNo("IO"),
  443. 'projectNo' => isset($projectNo) ? $projectNo : '',
  444. 'infoNo' => $infoNo,
  445. 'companyNo' => $companyNo,
  446. 'customer_code' => $khNo,
  447. 'addtime' => date('Y-m-d H:i:s'),
  448. 'updatetime' => date('Y-m-d H:i:s')
  449. ]);
  450. }
  451. }
  452. }
  453. Db::commit();
  454. return json_show(0, "新建成功", ["zxNo" => $zxNo]);
  455. } else {
  456. Db::rollback();
  457. return json_show(1004, "新建失败");
  458. }
  459. } catch (\Exception $e) {
  460. Db::rollback();
  461. return json_show(1003, $e->getMessage());
  462. }
  463. }
  464. //复制上面的bidlist方法,只更改排序方式
  465. public function bidlistCopy()
  466. {
  467. $this->post = $this->request->filter('trim')->post();
  468. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  469. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  470. $where = [['cb.is_del', "=", 0], ['c.status', '<>', 6]];//不要'取消转单'状态下的数据
  471. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  472. if ($zxNo !== "") {
  473. $where[] = ['cb.zxNo', 'like', '%' . $zxNo . '%'];
  474. }
  475. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  476. if ($infoNo !== "") {
  477. $where[] = ['cb.infoNo', 'like', '%' . $infoNo . '%'];
  478. }
  479. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  480. if ($bidNo !== "") {
  481. $where[] = ['cb.bidNo', 'like', '%' . $bidNo . '%'];
  482. }
  483. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  484. if ($pgNo !== "") {
  485. $bidinfo = Db::name("consult_info")->where([["pgNo", "=", $pgNo], ["is_del", "=", 0]])->column("infoNo");
  486. $where[] = ['cb.infoNo', 'in', $bidinfo];
  487. }
  488. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  489. if ($bargain_status !== "") {
  490. $bidinfo = Db::name("consult_info")->where([["bargain_status", "=", $bargain_status], ["is_del", "=", 0]])->column("infoNo");
  491. $where[] = ['cb.infoNo', 'in', $bidinfo];
  492. }
  493. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  494. if ($projectNo !== "") {
  495. $zxlist = Db::name("consult_order")->where(["projectNo" => $projectNo, "is_del" => 0, "is_project" => 1])->column
  496. ("zxNo");
  497. $where[] = ['cb.zxNo', 'in', $zxlist];
  498. }
  499. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  500. if ($is_own == 1) {
  501. // $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  502. // if ($token == "") {
  503. // return json_show(101, 'token不能为空');
  504. // }
  505. // $apply_id = GetUserInfo($token);
  506. // if (empty($apply_id) || $apply_id['code'] != 0) {
  507. // return json_show(1002, "申请人数据不存在");
  508. // }
  509. $where[] = ['cb.createrid', "=", $this->request->user['uid']];
  510. $where[] = ['cb.supplierNo', "=", $this->request->user['supplierNo']];
  511. }
  512. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  513. if ($company_name !== "") $where[] = ["cb.createrid", 'in', get_company_item_user_by_name($company_name)];
  514. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
  515. if($relaComNo!="") $where[]=['cb.supplierNo','=', $relaComNo];
  516. $count = Db::name('consult_bids')
  517. ->alias('cb')
  518. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  519. ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
  520. ->where($where)
  521. ->count();
  522. $total = ceil($count / $size);
  523. $page = $page >= $total ? $total : $page;
  524. $list = Db::name('consult_bids')
  525. ->alias('cb')
  526. ->field('cb.*')
  527. ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
  528. ->where($where)
  529. ->page($page, $size)
  530. ->order('cb.addtime', 'desc')
  531. ->select()
  532. ->toArray();
  533. $all_createrid = array_column($list,'createrid');
  534. $item = get_company_name_by_uid($all_createrid);
  535. $data = [];
  536. foreach ($list as $value) {
  537. $catinfo = Db::name("cat")->where(["id" => $value['cat_id']])->find();
  538. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  539. $unit = Db::name("unit")->where(["id" => $value['unit_id']])->find();
  540. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  541. $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  542. $value['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  543. if ($value['brand_id'] != 0) {
  544. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  545. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  546. } else {
  547. $value["brand_name"] = "";
  548. $value["brand_id"] = "";
  549. }
  550. $bidinfo = Db::name("consult_info")->where(["infoNo" => $value["infoNo"]])->find();
  551. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] : 0;
  552. $god = [
  553. "metal_id" => $value['metal_id'],
  554. "weight" => $value["good_weight"],
  555. "demo_fee" => $value["demo_fee"],
  556. "delivery_fee" => $value["delivery_fee"],
  557. "open_fee" => $value["open_fee"],
  558. "packing_fee" => $value["pakge_fee"],
  559. "mark_fee" => $value["mark_fee"],
  560. "nake_fee" => $value["nake_fee"],
  561. "cert_fee" => $value["cert_fee"],
  562. "cost_fee" => $value["sale_cost_fee"] != $value["origin_cost_fee"] ? $value["sale_cost_fee"] : $value["cost_fee"],
  563. "num" => $bidinfo["num"],
  564. ];
  565. if ($value['is_gold_price'] == 1) {
  566. $price = GoldPrice($god, $budget / 100);
  567. $value['sale_price'] = round($price, 2);
  568. }
  569. $value['cost_fee'] = $value['origin_cost_fee'];
  570. $value['specinfo'] = json_decode($value['specinfo'], true);
  571. $value['metal_name'] = isset($value['metal_id']) && $value['metal_id'] != 0 ? $this->noble[$value['metal_id']] : "";
  572. $value['bargain_status'] = $bidinfo['bargain_status'];
  573. //reject驳回原因,status==5表示驳回
  574. $value['reject'] = [];
  575. if ($value['status'] >= 5) {
  576. $value['reject'] = Db::name('bargain_order')
  577. ->field('id,remark,status')
  578. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  579. ->whereIn('status', [3, 8, 11])->order("id desc")
  580. ->find();
  581. }
  582. //产地
  583. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  584. if ($value['delivery_place'] != "") {
  585. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['delivery_place']);
  586. }
  587. $value['delivery_place_cn'] = GetAddr(json_encode($place));
  588. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  589. if ($value['origin_place'] != "") {
  590. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['origin_place']);
  591. }
  592. $value['origin_addr'] = GetAddr(json_encode($place));
  593. // if($value['origin_place']!=''){
  594. // $code = explode(",",$value['origin_place']);
  595. // $temp=[];
  596. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  597. // $temp['city_code']=isset($code[1])?$code[1]:"";
  598. // $temp['area_code']=isset($code[2])?$code[2]:"";
  599. // $addr= GetAddr(json_encode($temp));
  600. // $value['origin_addr'] = $addr;
  601. // }
  602. $value['company_name'] = $item[$value['createrid']] ?? '';
  603. $data[] = $value;
  604. }
  605. return json_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  606. }
  607. //反馈商品详情
  608. public function feadinfo()
  609. {
  610. $this->post = $this->request->filter('trim')->post();
  611. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] != "" ? trim($this->post['bidNo']) : "";
  612. if ($bidNo == "") {
  613. return json_show(1004, "参数bidNo不能为空");
  614. }
  615. $info = Db::name("consult_bids")->where(['bidNo' => $bidNo, "is_del" => 0])->find();
  616. if ($info == false) {
  617. return json_show(1004, "未找到商品数据");
  618. }
  619. $unit = Db::name("unit")->where(["id" => $info['unit_id']])->find();
  620. $info['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  621. $info['cat_info'] = made($info['cat_id'], []);
  622. $info['noble_weight'] = $info['good_weight'];
  623. $supplier = Db::name("supplier")->where(["code" => $info['supplierNo']])->find();
  624. $info['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  625. if ($info['brand_id'] != 0) {
  626. $brand = Db::name("brand")->where(["id" => $info['brand_id']])->find();
  627. $info["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  628. } else {
  629. $info["brand_name"] = "";
  630. $info["brand_id"] = "";
  631. }
  632. $catinfo = Db::name("cat")->where(["id" => $info['cat_id']])->find();
  633. $bidinfo = Db::name("consult_info")->where(["infoNo" => $info["infoNo"]])->find();
  634. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] : 0;
  635. $god = [
  636. "metal_id" => $info['metal_id'],
  637. "weight" => $info["good_weight"],
  638. "demo_fee" => $info["demo_fee"],
  639. "delivery_fee" => $info["delivery_fee"],
  640. "open_fee" => $info["open_fee"],
  641. "packing_fee" => $info["pakge_fee"],
  642. "mark_fee" => $info["mark_fee"],
  643. "nake_fee" => $info["nake_fee"],
  644. "cert_fee" => $info["cert_fee"],
  645. "cost_fee" => $info["cost_fee"],
  646. "num" => $bidinfo["num"],
  647. ];
  648. if ($info['is_gold_price'] == 1) {
  649. $price = GoldPrice($god, $budget / 100);
  650. $info['sale_price'] = round($price, 2);
  651. }
  652. $info['specinfo'] = json_decode($info['specinfo'], true);
  653. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  654. if ($info['delivery_place'] != "") {
  655. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $info['delivery_place']);
  656. }
  657. $info['delivery_place_cn'] = GetAddr(json_encode($place));
  658. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  659. if ($info['origin_place'] != "") {
  660. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $info['origin_place']);
  661. }
  662. $info['origin_place_cn'] = GetAddr(json_encode($place));
  663. $info['metal_name'] = isset($info['metal_id']) && $info['metal_id'] != 0 ? $this->noble[$info['metal_id']] : "";
  664. $bargain = Db::name("bargain_order")->where(['bidsNo' => $bidNo, "is_del" => 0])->find();
  665. $info['bargain'] = $bargain;
  666. $info['good_img'] = explode(',', $info['good_img']);
  667. return json_show(0, "获取成功", $info);
  668. }
  669. //反馈商品添加
  670. public function feadback()
  671. {
  672. $this->post = $this->request->filter('trim')->post();
  673. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] != "" ? trim($this->post['infoNo']) : "";
  674. if ($infoNo == "") {
  675. return json_show(1002, "参数infoNo不能为空");
  676. }
  677. $zxinfo = Db::name("consult_info")->where(["infoNo" => $infoNo, "is_del" => 0])->find();
  678. if ($zxinfo == false) {
  679. return json_show(1003, "未找到信息数据");
  680. }
  681. if ($zxinfo['status'] != 1) {
  682. return json_show(1004, "任务未进行");
  683. }
  684. $zx = Db::name("consult_order")->where(["zxNo" => $zxinfo['zxNo'], "is_del" => 0])->find();
  685. if ($zx == false) {
  686. return json_show(1003, "未找咨询信息数据");
  687. }
  688. $pname = isset($this->post['pname']) && $this->post['pname'] != "" ? trim($this->post['pname']) : "";
  689. if ($pname == "") {
  690. return json_show(1002, "参数pname不能为空");
  691. }
  692. $brandid = isset($this->post['brandid']) && $this->post['brandid'] != "" ? intval($this->post['brandid']) : "";
  693. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] != "" ? trim($this->post['cat_id']) : "";
  694. if ($cat_id == "") {
  695. return json_show(1002, "参数cat_id不能为空");
  696. }
  697. $specin = isset($this->post['specinfo']) && !empty($this->post['specinfo']) ? $this->post['specinfo'] : "";
  698. if ($specin == "") {
  699. return json_show(1003, "参数specinfo不能为空");
  700. }
  701. $specinfo = [];
  702. foreach ($specin as $v) {
  703. $spec = Db::name("specs")->where(["id" => $v['specid']])->find();
  704. $spec_value = Db::name("spec_value")->where(["id" => $v['spec_value_id']])->find();
  705. $v['spec_name'] = isset($spec['spec_name']) ? $spec['spec_name'] : "";
  706. $v['spec_value_name'] = isset($spec_value['spec_value']) ? $spec_value['spec_value'] : "";
  707. $specinfo[] = $v;
  708. }
  709. $unit_id = isset($this->post['unit_id']) && $this->post['unit_id'] != "" ? intval($this->post['unit_id']) : "";
  710. $cost_desc = isset($this->post['cost_desc']) && $this->post['cost_desc'] != "" ? trim($this->post['cost_desc']) : "";
  711. $work_day = isset($this->post['work_day']) && $this->post['work_day'] != "" ? intval($this->post['work_day']) : "";
  712. $delivery_day = isset($this->post['delivery_day']) && $this->post['delivery_day'] != "" ? intval($this->post['delivery_day']) : "";
  713. $good_img = isset($this->post['good_img']) && $this->post['good_img'] != "" ? $this->post['good_img'] : [];
  714. $expire_day = isset($this->post['expire_day']) && $this->post['expire_day'] != "" ? intval($this->post['expire_day']) : "";
  715. $origin_place = isset($this->post['origin_place']) && $this->post['origin_place'] != "" ? trim($this->post['origin_place']) : "";
  716. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] != "" ? trim($this->post['supplierNo']) : "";
  717. $pay_way = isset($this->post['pay_way']) && $this->post['pay_way'] != "" ? intval($this->post['pay_way']) : "";
  718. $tax = isset($this->post['tax']) && $this->post['tax'] != "" ? trim($this->post['tax']) : "";
  719. $send_way = isset($this->post['send_way']) && $this->post['send_way'] != "" ? intval($this->post['send_way']) : "";
  720. $metal_id = isset($this->post['metal_id']) && $this->post['metal_id'] != "" ? intval($this->post['metal_id']) : "0";
  721. $is_gold_price = isset($this->post['is_gold_price']) && $this->post['is_gold_price'] != "" ? intval($this->post['is_gold_price']) : "0";
  722. $config = isset($this->post['config']) && $this->post['config'] != "" ? $this->post['config'] : "";
  723. $other_config = isset($this->post['other_config']) && $this->post['other_config'] != "" ? $this->post['other_config'] : "";
  724. $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? floatval($this->post['weight']) : "0";
  725. $good_weight = isset($this->post['noble_weight']) && $this->post['noble_weight'] !== "" ? floatval($this->post['noble_weight']) : "0";
  726. $demo_fee = isset($this->post['demo_fee']) && $this->post['demo_fee'] !== "" ? floatval($this->post['demo_fee']) : "0";
  727. $delivery_fee = isset($this->post['delivery_fee']) && $this->post['delivery_fee'] !== "" ? floatval($this->post['delivery_fee']) : "0";
  728. $open_fee = isset($this->post['open_fee']) && $this->post['open_fee'] !== "" ? floatval($this->post['open_fee']) : "0";
  729. $pakge_fee = isset($this->post['pakge_fee']) && $this->post['pakge_fee'] !== "" ? floatval($this->post['pakge_fee']) : "0";
  730. $nake_fee = isset($this->post['nake_fee']) && $this->post['nake_fee'] !== "" ? floatval($this->post['nake_fee']) : "0";
  731. $mark_fee = isset($this->post['mark_fee']) && $this->post['mark_fee'] !== "" ? floatval($this->post['mark_fee']) : "0";
  732. $cert_fee = isset($this->post['cert_fee']) && $this->post['cert_fee'] !== "" ? floatval($this->post['cert_fee']) : "0";
  733. $cost_fee = isset($this->post['cost_fee']) && $this->post['cost_fee'] !== "" ? floatval($this->post['cost_fee']) : "0";
  734. if ($nake_fee === "") {
  735. return json_show(1004, "参数nake_fee不能为空");
  736. }
  737. $is_diff = isset($this->post['is_diff']) && $this->post['is_diff'] !== "" ? intval($this->post['is_diff']) : "";
  738. $supply_area = isset($this->post['supply_area']) && $this->post['supply_area'] !== "" ? intval($this->post['supply_area']) : "";
  739. $remark = isset($this->post['remark']) && $this->post['remark'] != "" ? trim($this->post['remark']) : "";
  740. $delivery_place = isset($this->post['delivery_place']) && $this->post['delivery_place'] != '' ? trim($this->post['delivery_place']) : "";
  741. if ($delivery_place == '') {
  742. return json_show(1002, "参数delivery_place不能为空");
  743. }
  744. // $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
  745. // if ($token == '') {
  746. // return json_show(1002, "参数token不能为空");
  747. // }
  748. // $user = GetUserInfo($token);
  749. // if (empty($user) || $user['code'] != 0) {
  750. // return json_show(1005, "用户数据不存在");
  751. // }
  752. $createrid = $this->request->user['uid'];
  753. $creater = $this->request->user['nickname'];
  754. $bidNo = makeNo("BD");
  755. $spucode = makeNo("SKU");
  756. $catinfo = Db::name("cat")->where(["id" => $cat_id])->find();
  757. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] / 100 : 0;
  758. //部分参数的大小校验
  759. $vali = Validate::rule([
  760. 'expire_day|有效时长' => 'require|elt:214748364',
  761. 'delivery_day|物流时长' => 'require|elt:214748364',
  762. 'work_day|生产工期' => 'require|elt:214748364',
  763. 'weight|总重量' => 'require|max:10',
  764. ]);
  765. $temp = [
  766. 'expire_day' => $expire_day,
  767. 'delivery_day' => $delivery_day,
  768. 'work_day' => $work_day,
  769. 'weight' => $weight,
  770. ];
  771. if (!$vali->check($temp)) return json_show(0, $vali->getError());
  772. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  773. $cat_top_list = made($cat_id);
  774. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  775. if ($is_gold_price == 1 && $cat_top_id == 6) {
  776. $gold = Db::name("gold_price1")->where(["type" => $metal_id, "is_del" => 0, "status" => 1])->order("addtime desc")->find();
  777. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  778. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  779. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $good_weight * $gold["price"] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  780. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  781. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  782. // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  783. $saleprice = $total_fee / (1 - $budget);
  784. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  785. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $good_weight - $gold["price"];
  786. } else {
  787. if ($nake_fee) {
  788. $saleprice = ($demo_fee / $zxinfo['num'] + $delivery_fee + $open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  789. $total_fee = $demo_fee / $zxinfo['num'] + $delivery_fee + $open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  790. } else {
  791. $saleprice = ($demo_fee / $zxinfo['num'] + $delivery_fee + $open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee) / (1 - $budget);
  792. $total_fee = $demo_fee / $zxinfo['num'] + $delivery_fee + $open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee;
  793. }
  794. }
  795. $supplier = Db::name('supplier')
  796. ->field('id,person,personid')
  797. ->where('code',$supplierNo)
  798. ->findOrEmpty();
  799. $data = [
  800. "bidNo" => $bidNo,
  801. "infoNo" => $infoNo,
  802. "zxNo" => $zxinfo['zxNo'],
  803. "spuCode" => $spucode,
  804. "good_name" => $pname,
  805. "brand_id" => $brandid,
  806. "cat_id" => $cat_id,
  807. "specinfo" => json_encode($specinfo),
  808. "unit_id" => $unit_id,
  809. "cost_desc" => $cost_desc,
  810. "work_day" => $work_day,
  811. "delivery_day" => $delivery_day,
  812. "good_img" => is_array($good_img) ? implode(',', $good_img) : $good_img,
  813. "expire_day" => $expire_day,
  814. "origin_place" => $origin_place,
  815. "supplierNo" => $supplierNo,
  816. "pay_way" => $pay_way,
  817. "tax" => $tax,
  818. "send_way" => $send_way,
  819. "metal_id" => $metal_id,
  820. "is_gold_price" => $is_gold_price,
  821. "config" => $config,
  822. "other_config" => $other_config,
  823. "weight" => $weight,
  824. "good_weight" => $good_weight,
  825. "gold_price" => isset($gold["price"]) ? $gold["price"] : 0,
  826. "is_diff" => $is_diff,
  827. "demo_fee" => $demo_fee,
  828. "delivery_fee" => $delivery_fee,
  829. "open_fee" => $open_fee,
  830. "pakge_fee" => $pakge_fee,
  831. "nake_fee" => $nake_fee,
  832. "mark_fee" => $mark_fee,
  833. "cert_fee" => $cert_fee,
  834. "cost_fee" => $cost_fee,
  835. "total_fee" => $total_fee,
  836. "supply_area" => $supply_area,
  837. "remark" => $remark,
  838. "sale_price" => $saleprice,
  839. "sale_cost_fee" => $sale_cost_fee,
  840. "origin_cost_fee" => $sale_cost_fee,
  841. "origin_price" => $saleprice,
  842. "createrid" => $createrid,
  843. "creater" => $creater,
  844. "status" => $zxinfo['status'] == 1 ? 1 : 2,
  845. "is_del" => 0,
  846. "addtime" => date("Y-m-d H:i:s"),
  847. "updatetime" => date("Y-m-d H:i:s"),
  848. 'delivery_place' => $delivery_place,//发货地
  849. 'cgder' => $supplier['person'] ?? '',
  850. 'cgderid' => $supplier['personid'] ?? 0,
  851. ];
  852. Db::startTrans();
  853. try {
  854. $insert = Db::name("consult_bids")->insert($data);
  855. if ($insert) {
  856. if ($zx['is_project'] == 1 && $zx['projectNo'] != "" && $zxinfo['pgNo'] != "") {
  857. $projectinfo = Db::name("project_info")->where(["pgNo" => $zxinfo["pgNo"], "projectNo" => $zx['projectNo'], "is_del" => 0])->find();
  858. if ($projectinfo == false) {
  859. Db::rollback();
  860. return json_show(1006, "未找到项目信息");
  861. }
  862. $temp = [];
  863. $temp['spuCode'] = $spucode;
  864. $temp['skuCode'] = "";
  865. $temp['pgNo'] = $zxinfo['pgNo'];
  866. $temp['projectNo'] = $zx['projectNo'];
  867. $temp['good_name'] = $pname;
  868. $temp['good_type'] = $projectinfo['good_type'];
  869. $temp['data_source'] = 2;
  870. $temp['cat_id'] = $cat_id;
  871. $temp['budget_price'] = $projectinfo['budget_price'];
  872. $temp['sale_price'] = $saleprice;
  873. $temp['origin_price'] = $total_fee;
  874. $temp['num'] = $zxinfo['num'];
  875. $temp['status'] = 0;
  876. $temp['is_del'] = 0;
  877. $temp['creater'] = $creater;
  878. $temp['createrid'] = $createrid;
  879. $temp['addtime'] = date("Y-m-d H:i:s");
  880. $temp['updatetime'] = date("Y-m-d H:i:s");
  881. $nu = Db::name("project_feedback")->insert($temp);
  882. if ($nu == false) {
  883. Db::rollback();
  884. return json_show(1006, "项目反馈失败");
  885. } else {
  886. $old_projectinfo_status = $projectinfo['status'];
  887. $projectinfo['status'] = 2;
  888. $projectinfo['updatetime'] = date("Y-m-d H:i:s");
  889. $up = Db::name("project_info")->save($projectinfo);
  890. if ($up) {
  891. //修改状态,添加待办,只记录动作
  892. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  893. "order_code" => $projectinfo['pgNo'],//编码
  894. "status" => $old_projectinfo_status,//这里的status是之前的值
  895. "action_remark" => '',//备注
  896. "action_type" => "status"//新建create,编辑edit,更改状态status
  897. ], "PRI", 2, $projectinfo);
  898. $count = Db::name("project_info")->where(["projectNo" => $projectinfo['projectNo'], "status" => 1])->count();
  899. if ($count == 0) {
  900. $projetc = Db::name("project")->where(["projectNo" => $projectinfo['projectNo'], "status" => 1])->find();
  901. if ($projetc != false) {
  902. $proc = Db::name("project")->where(["projectNo" => $projectinfo['projectNo'], "status" => 1])->save
  903. (["status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  904. if ($proc == false) {
  905. Db::rollback();
  906. return json_show(1006, "项目反馈失败");
  907. } else {
  908. //修改状态,添加待办
  909. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  910. "order_code" => $projetc['projectNo'],//项目编码
  911. "status" => 1,//这里的status是之前的值
  912. "action_remark" => '',//备注
  913. "action_type" => "status"//新建create,编辑edit,更改状态status
  914. ], "PRO", 2, $projetc);
  915. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  916. "order_type" => 'PRO',
  917. "order_code" => $projetc['projectNo'],
  918. "order_id" => $projetc['id'],
  919. "order_status" => 2,
  920. "before_status" => 1,
  921. 'holder_id'=>$projetc['createrid'],
  922. 'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
  923. ]);
  924. }
  925. }
  926. }
  927. }
  928. }
  929. }
  930. Db::commit();
  931. return json_show(0, "反馈成功", ["bidNo" => $bidNo]);
  932. } else {
  933. Db::rollback();
  934. return json_show(1006, "反馈失败");
  935. }
  936. } catch (\Exception $e) {
  937. Db::rollback();
  938. return json_show(1006, $e->getMessage());
  939. }
  940. }
  941. //反馈商品编辑
  942. public function feededit()
  943. {
  944. $this->post = $this->request->filter('trim')->post();
  945. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] != "" ? trim($this->post['bidNo']) : "";
  946. if ($bidNo == "") {
  947. return json_show(1002, "参数bidNo不能为空");
  948. }
  949. $bidinfo = Db::name("consult_bids")->where(["bidNo" => $bidNo, "is_del" => 0])->find();
  950. if ($bidinfo == false) {
  951. return json_show(1003, "未找到信息数据");
  952. }
  953. if ($bidinfo['status'] >= 5) {
  954. return json_show(1004, "咨询单已确认无法修改");
  955. }
  956. $zxinfo = Db::name("consult_info")->where(["infoNo" => $bidinfo['infoNo'], "is_del" => 0])->find();
  957. if ($zxinfo == false) {
  958. return json_show(1003, "未找到信息数据");
  959. }
  960. $zx = Db::name("consult_order")->where(["zxNo" => $zxinfo['zxNo'], "is_del" => 0])->find();
  961. if ($zx == false) {
  962. return json_show(1003, "未找咨询信息数据");
  963. }
  964. $pname = isset($this->post['pname']) && $this->post['pname'] != "" ? trim($this->post['pname']) : "";
  965. if ($pname == "") {
  966. return json_show(1002, "参数pname不能为空");
  967. }
  968. $brandid = isset($this->post['brandid']) && $this->post['brandid'] != "" ? intval($this->post['brandid']) : "";
  969. // if($brandid==""){
  970. // return json_show(1002,"参数brandid不能为空");
  971. // }
  972. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] != "" ? trim($this->post['cat_id']) : "";
  973. if ($cat_id == "") {
  974. return json_show(1002, "参数cat_id不能为空");
  975. }
  976. $specin = isset($this->post['specinfo']) && !empty($this->post['specinfo']) ? $this->post['specinfo'] : "";
  977. if ($specin == "") {
  978. return json_show(1003, "参数specinfo不能为空");
  979. }
  980. $specinfo = [];
  981. foreach ($specin as $v) {
  982. $spec = Db::name("specs")->where(["id" => $v['specid']])->find();
  983. $spec_value = Db::name("spec_value")->where(["id" => $v['spec_value_id']])->find();
  984. $v['spec_name'] = isset($spec['spec_name']) ? $spec['spec_name'] : "";
  985. $v['spec_value_name'] = isset($spec_value['spec_value']) ? $spec_value['spec_value'] : "";
  986. $specinfo[] = $v;
  987. }
  988. $unit_id = isset($this->post['unit_id']) && $this->post['unit_id'] != "" ? intval($this->post['unit_id']) : "";
  989. $cost_desc = isset($this->post['cost_desc']) && $this->post['cost_desc'] != "" ? trim($this->post['cost_desc']) : "";
  990. $work_day = isset($this->post['work_day']) && $this->post['work_day'] != "" ? intval($this->post['work_day']) : "";
  991. $delivery_day = isset($this->post['delivery_day']) && $this->post['delivery_day'] != "" ? intval($this->post['delivery_day']) : "";
  992. $good_img = isset($this->post['good_img']) && $this->post['good_img'] != "" ? $this->post['good_img'] : [];
  993. $expire_day = isset($this->post['expire_day']) && $this->post['expire_day'] != "" ? intval($this->post['expire_day']) : "";
  994. $origin_place = isset($this->post['origin_place']) && $this->post['origin_place'] != "" ? trim($this->post['origin_place']) : "";
  995. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] != "" ? trim($this->post['supplierNo']) : "";
  996. $pay_way = isset($this->post['pay_way']) && $this->post['pay_way'] != "" ? intval($this->post['pay_way']) : "";
  997. $tax = isset($this->post['tax']) && $this->post['tax'] != "" ? trim($this->post['tax']) : "";
  998. $send_way = isset($this->post['send_way']) && $this->post['send_way'] != "" ? intval($this->post['send_way']) : "0";
  999. $metal_id = isset($this->post['metal_id']) && $this->post['metal_id'] != "" ? intval($this->post['metal_id']) : "0";
  1000. $is_gold_price = isset($this->post['is_gold_price']) && $this->post['is_gold_price'] != "" ? intval($this->post['is_gold_price']) : "0";
  1001. $config = isset($this->post['config']) && $this->post['config'] != "" ? $this->post['config'] : "";
  1002. $other_config = isset($this->post['other_config']) && $this->post['other_config'] != "" ? $this->post['other_config'] : "";
  1003. $weight = isset($this->post['weight']) && $this->post['weight'] != "" ? floatval($this->post['weight']) : "0";
  1004. $noble_weight = isset($this->post['noble_weight']) && $this->post['noble_weight'] != "" ? floatval($this->post['noble_weight']) : "0";
  1005. $demo_fee = isset($this->post['demo_fee']) && $this->post['demo_fee'] != "" ? floatval($this->post['demo_fee']) : "0";
  1006. $delivery_fee = isset($this->post['delivery_fee']) && $this->post['delivery_fee'] != "" ? floatval($this->post['delivery_fee']) : "0";
  1007. $open_fee = isset($this->post['open_fee']) && $this->post['open_fee'] != "" ? floatval($this->post['open_fee']) : "0";
  1008. $pakge_fee = isset($this->post['pakge_fee']) && $this->post['pakge_fee'] != "" ? floatval($this->post['pakge_fee']) : "0";
  1009. $nake_fee = isset($this->post['nake_fee']) && $this->post['nake_fee'] !== "" ? floatval($this->post['nake_fee']) : 0;
  1010. $mark_fee = isset($this->post['mark_fee']) && $this->post['mark_fee'] != "" ? floatval($this->post['mark_fee']) : "0";
  1011. $cert_fee = isset($this->post['cert_fee']) && $this->post['cert_fee'] != "" ? floatval($this->post['cert_fee']) : "0";
  1012. $cost_fee = isset($this->post['cost_fee']) && $this->post['cost_fee'] != "" ? floatval($this->post['cost_fee']) : "0";
  1013. $is_diff = isset($this->post['is_diff']) && $this->post['is_diff'] !== "" ? intval($this->post['is_diff']) : "";
  1014. $supply_area = isset($this->post['supply_area']) && $this->post['supply_area'] !== "" ? intval($this->post['supply_area']) : "";
  1015. $remark = isset($this->post['remark']) && $this->post['remark'] != "" ? trim($this->post['remark']) : "";
  1016. $delivery_place = isset($this->post['delivery_place']) && $this->post['delivery_place'] != '' ? trim($this->post['delivery_place']) : "";
  1017. if ($delivery_place == '') {
  1018. return json_show(1002, "参数delivery_place不能为空");
  1019. }
  1020. $catinfo = Db::name("cat")->where(["id" => $cat_id])->find();
  1021. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] / 100 : 0;
  1022. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  1023. $cat_top_list = made($cat_id);
  1024. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  1025. if ($is_gold_price == 1 && $cat_top_id == 6) {
  1026. $gold = Db::name("gold_price1")->where(["type" => $metal_id, "is_del" => 0, "status" => 1])->order("addtime desc")->find();
  1027. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1028. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $noble_weight * $gold["price"] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  1029. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1030. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1031. $saleprice = $total_fee / (1 - $budget);
  1032. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1033. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $noble_weight - $gold["price"];
  1034. } else {
  1035. $saleprice = ($demo_fee / $zxinfo['num'] + $delivery_fee + $open_fee / $zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  1036. $total_fee = $demo_fee / $zxinfo['num'] + $delivery_fee + $open_fee / $zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  1037. }
  1038. Db::startTrans();
  1039. try {
  1040. $createrid = $this->request->user['uid'];
  1041. $creater = $this->request->user['nickname'];
  1042. $data = [
  1043. "good_name" => $pname,
  1044. "brand_id" => $brandid,
  1045. "cat_id" => $cat_id,
  1046. "specinfo" => json_encode($specinfo),
  1047. // "material"=>$material,
  1048. "unit_id" => $unit_id,
  1049. "cost_desc" => $cost_desc,
  1050. "work_day" => $work_day,
  1051. "delivery_day" => $delivery_day,
  1052. "good_img" => is_array($good_img) ? implode(',', $good_img) : $good_img,
  1053. "expire_day" => $expire_day,
  1054. "origin_place" => $origin_place,
  1055. "supplierNo" => $supplierNo,
  1056. "pay_way" => $pay_way,
  1057. "tax" => $tax,
  1058. "send_way" => $send_way,
  1059. "metal_id" => $metal_id,
  1060. "is_gold_price" => $is_gold_price,
  1061. "config" => $config,
  1062. "other_config" => $other_config,
  1063. "weight" => $weight,
  1064. "good_weight" => $noble_weight,
  1065. "is_diff" => $is_diff,
  1066. "demo_fee" => $demo_fee,
  1067. "gold_price" => isset($gold["price"]) ? $gold["price"] : 0,
  1068. "delivery_fee" => $delivery_fee,
  1069. "open_fee" => $open_fee,
  1070. "pakge_fee" => $pakge_fee,
  1071. "nake_fee" => $nake_fee,
  1072. "mark_fee" => $mark_fee,
  1073. "cert_fee" => $cert_fee,
  1074. "cost_fee" => $cost_fee,
  1075. "sale_cost_fee" => $sale_cost_fee,
  1076. "origin_cost_fee" => $sale_cost_fee,
  1077. "total_fee" => $total_fee,
  1078. "sale_price" => $saleprice,
  1079. "origin_price" => $saleprice,
  1080. "supply_area" => $supply_area,
  1081. "remark" => $remark,
  1082. "status" => 0,
  1083. "updatetime" => date("Y-m-d H:i:s"),
  1084. 'delivery_place' => $delivery_place
  1085. ];
  1086. $insert = Db::name("consult_bids")->where($bidinfo)->save($data);
  1087. if ($insert) {
  1088. if ($zxinfo['bargain_status'] == 1) {
  1089. $zxinfo['bargain_status'] = 0;
  1090. $infoip = Db::name("consult_info")->save($zxinfo);
  1091. if ($infoip == false) {
  1092. Db::rollback();
  1093. return json_show(1006, "咨询信息状态更新失败");
  1094. }
  1095. }
  1096. if ($zx['is_project'] == 1 && $zx['projectNo'] != "" && $zxinfo['pgNo'] != "") {
  1097. $projectinfo = Db::name("project_info")->where(["pgNo" => $zxinfo["pgNo"], "projectNo" => $zx['projectNo'], "is_del" => 0])->find();
  1098. if ($projectinfo == false) {
  1099. Db::rollback();
  1100. return json_show(1006, "未找到项目信息");
  1101. }
  1102. $feed = Db::name("project_feedback")->where(["pgNo" => $zxinfo["pgNo"], "projectNo" => $zx['projectNo'], "spuCode" => $bidinfo['spuCode'], "is_del" => 0])->find();
  1103. if ($feed != false) {
  1104. $feed['good_name'] = $pname;
  1105. $feed['good_type'] = $projectinfo['good_type'];
  1106. $feed['cat_id'] = $cat_id;
  1107. $feed['sale_price'] = $saleprice;
  1108. $feed['origin_price'] = $total_fee;
  1109. $feed['updatetime'] = date("Y-m-d H:i:s");
  1110. $temp['updatetime'] = date("Y-m-d H:i:s");
  1111. $nu = Db::name("project_feedback")->save($feed);
  1112. if ($nu == false) {
  1113. Db::rollback();
  1114. return json_show(1006, "项目反馈失败");
  1115. } else {
  1116. $old_projectinfo_status = $projectinfo['status'];
  1117. $projectinfo['status'] = 2;
  1118. $projectinfo['updatetime'] = date("Y-m-d H:i:s");
  1119. $up = Db::name("project_info")->save($projectinfo);
  1120. if ($up) {
  1121. //修改状态,添加待办,只记录动作
  1122. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1123. "order_code" => $projectinfo['pgNo'],//编码
  1124. "status" => $old_projectinfo_status,//这里的status是之前的值
  1125. "action_remark" => '',//备注
  1126. "action_type" => "status"//新建create,编辑edit,更改状态status
  1127. ], "PRI", 2, $projectinfo
  1128. );
  1129. $count = Db::name("project_info")->where(["projectNo" => $projectinfo['projectNo'], "status" => 1])->count();
  1130. if ($count == 0) {
  1131. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1132. $project_id = Db::name("project")->where(["projectNo" => $projectinfo['projectNo'], "status" => 1])->field('id,createrid')->findOrEmpty();
  1133. if ($project_id) {
  1134. $proc = Db::name("project")->where(["id" => $project_id['id']])->update(["status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  1135. if ($proc == false) {
  1136. Db::rollback();
  1137. return json_show(1006, "项目反馈失败");
  1138. } else {
  1139. //修改状态,添加待办
  1140. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1141. "order_code" => $projectinfo['projectNo'],//项目编码
  1142. "status" => 1,//这里的status是之前的值
  1143. "action_remark" => '',//备注
  1144. "action_type" => "status"//新建create,编辑edit,更改状态status
  1145. ], "PRO", 2, $this->post);
  1146. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1147. "order_type" => 'PRO',
  1148. "order_code" => $projectinfo['projectNo'],
  1149. "order_id" => $project_id['id'],
  1150. "order_status" => 2,
  1151. "before_status" => 1,
  1152. 'holder_id'=>$project_id['createrid'],
  1153. 'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
  1154. ]
  1155. );
  1156. }
  1157. }
  1158. }
  1159. }
  1160. }
  1161. }
  1162. }
  1163. Db::commit();
  1164. return json_show(0, "编辑成功");
  1165. } else {
  1166. Db::rollback();
  1167. return json_show(1004, "编辑失败");
  1168. }
  1169. } catch (\Exception $e) {
  1170. Db::rollback();
  1171. return json_show(1004, $e->getMessage());
  1172. }
  1173. }
  1174. }