Consult.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class Consult extends BaseController
  7. {
  8. public $post = "";
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. $this->post=$this->request->post();
  13. // $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  14. // if($token==""){
  15. // return error_show(101,'token不能为空');
  16. // }
  17. // $effetc = VerifyTokens($token);
  18. // if(!empty($effetc) && $effetc['code']!=0) {
  19. // return error_show($effetc['code'], $effetc['message']);
  20. // }
  21. }
  22. // public function list(){
  23. // $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  24. // $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  25. // $where=[['is_del',"=",0],["cat_id","<>",0]];
  26. // $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  27. // if ($zxNo !== "") {
  28. // $where[] = ['zxNo','=',$zxNo];
  29. // }
  30. // $sequenceNo = isset($this->post['sequenceNo']) && $this->post['sequenceNo'] !== "" ? trim($this->post['sequenceNo']) : "";
  31. // if ($sequenceNo !== "") {
  32. // $where[] = ['sequenceNo','like',"%$sequenceNo%"];
  33. // }
  34. // $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  35. // if ($salesman !== "") {
  36. // //$where["salesman"] =Db::Raw("like '%$salesman%'");
  37. // $where[]= ["salesman",'like',"%$salesman%"];
  38. // }
  39. // $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  40. // if ($cpName !== "") {
  41. // //$where["cpName"]= Db::Raw("like '%$cpName%'");
  42. // $where[]= ["cpName",'like',"%$cpName%"];
  43. // }
  44. // $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  45. // if ($khNo !== "") {
  46. // // $where['khNo'] = $khNo;
  47. // $where[]= ["khNo",'like',"%$khNo%"];
  48. // }
  49. // $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  50. // if ($start !="") {
  51. // //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  52. // $where[]= ["zxtime",'>=',$start];
  53. // }
  54. // $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  55. // if($end !=""){
  56. // $where[]= ["zxtime",'<=',$end];
  57. // }
  58. // $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  59. // if ($status !== "") {
  60. // $where[]= ["status",'=',$status];
  61. // }
  62. // $count = Db::name('consult')->where($where)->count();
  63. // $total = ceil($count / $size);
  64. // $page = $page >= $total ? $total : $page;
  65. // $list = Db::name('consult')->where($where)->page($page,$size)
  66. // ->select();
  67. // $data=[];
  68. // foreach ($list as $value){
  69. // $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  70. // $data[]=$value;
  71. // }
  72. // return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  73. // }
  74. public function conlist(){
  75. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  76. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  77. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  78. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  79. if ($zxNo !== "") {
  80. $where[] = ['a.zxNo','=',$zxNo];
  81. }
  82. // $sequenceNo = isset($this->post['sequenceNo']) && $this->post['sequenceNo'] !== "" ? trim($this->post['sequenceNo']) : "";
  83. // if ($sequenceNo !== "") {
  84. // $where[] = ['sequenceNo','like',"%$sequenceNo%"];
  85. // }
  86. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  87. if ($salesman !== "") {
  88. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  89. $where[]= ["b.salesman",'like',"%$salesman%"];
  90. }
  91. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  92. if ($cpName !== "") {
  93. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  94. $where[]= ["a.good_Name",'like',"%$cpName%"];
  95. }
  96. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  97. if ($khNo !== "") {
  98. // $where['khNo'] = $khNo;
  99. $where[]= ["b.khNo",'like',"%$khNo%"];
  100. }
  101. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  102. if ($start !="") {
  103. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  104. $where[]= ["a.addtime",'>=',$start];
  105. }
  106. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  107. if($end !=""){
  108. $where[]= ["a.addtime",'<=',$end];
  109. }
  110. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  111. if ($status !== "") {
  112. $where[]= ["a.status",'=',$status];
  113. }
  114. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  115. ->count();
  116. $total = ceil($count / $size);
  117. $page = $page >= $total ? $total : $page;
  118. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  119. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  120. $data=[];
  121. foreach ($list as $value){
  122. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  123. $value['khname']="";
  124. if($value['khNo']!==""){
  125. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  126. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  127. }
  128. $data[]=$value;
  129. }
  130. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  131. }
  132. public function info(){
  133. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  134. if($id==""){
  135. return error_show(1002,"咨询单编号不能为空");
  136. }
  137. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  138. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  139. $fo['can']=$in;
  140. if(empty($fo)){
  141. return error_show(1002,"未找到咨询单编号");
  142. }else{
  143. return app_show(0,"获取成功",$fo);
  144. }
  145. }
  146. public function del(){
  147. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  148. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  149. if($de==false){
  150. return error_show(1002,'咨询单信息未找到');
  151. }
  152. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  153. if($dell){
  154. return error_show(0,"删除成功");
  155. }else
  156. return error_show(1002,"删除失败");
  157. }
  158. public function create(){
  159. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  160. if($is_project===""){
  161. return error_show(1002,"参数is_project不能为空");
  162. }
  163. if($is_project==1){
  164. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  165. if($projectNo===""){
  166. return error_show(1002,"参数projectNo不能为空");
  167. }
  168. }
  169. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  170. if($khNo===""){
  171. return error_show(1002,"参数khNo不能为空");
  172. }
  173. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  174. if($companyNo===""){
  175. return error_show(1002,"参数companyNo不能为空");
  176. }
  177. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  178. if($endtime===""){
  179. return error_show(1002,"参数endtime不能为空");
  180. }
  181. // $saleid = isset($this->post['saleid']) && $this->post['saleid'] !=="" ? intval($this->post['saleid']) : "";
  182. // if($saleid===""){
  183. // return error_show(1002,"参数saleid不能为空");
  184. // }
  185. // $depart = isset($this->post['depart']) && $this->post['depart'] !=="" ? intval($this->post['depart']) : "";
  186. // if($depart===""){
  187. // return error_show(1002,"参数depart不能为空");
  188. // }
  189. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  190. "";
  191. if($platform_code===""){
  192. return error_show(1002,"参数platform_code不能为空");
  193. }
  194. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  195. if($ladder==""){
  196. return error_show(1005,"参数ladder不能为空");
  197. }
  198. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  199. if($token==''){
  200. return error_show(1005,"参数token不能为空");
  201. }
  202. $user =GetUserInfo($token);
  203. if(empty($user)||$user['code']!=0){
  204. return error_show(1002,"用户数据不存在");
  205. }
  206. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  207. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  208. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  209. $zxNo=makeNo("ZX");
  210. $data=[
  211. "zxNo"=>$zxNo,
  212. "createrid"=>$createrid,
  213. "creater"=>$creater,
  214. "is_project"=>$is_project,
  215. "projectNo"=>isset($projectNo) ? $projectNo:"",
  216. "khNo"=>$khNo,
  217. "companyNo"=>$companyNo,
  218. "endtime"=>$endtime,
  219. "salesman"=>$creater,
  220. "platform_code"=>$platform_code,
  221. "saleid"=>$createrid,
  222. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  223. "status"=>0,
  224. "is_del"=>0,
  225. "addtime"=>date("Y-m-d H:i:s"),
  226. "updatetime"=>date("Y-m-d H:i:s"),
  227. ];
  228. $zx = Db::name("consult_order")->insert($data);
  229. if($zx){
  230. foreach ($ladder as $value){
  231. $infoNo=isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):makeNo("INF");
  232. $info=[
  233. "infoNo"=>$infoNo,
  234. "zxNo"=>$zxNo,
  235. "spuCode"=>"",
  236. "good_name"=>$value['good_name'],
  237. "good_img"=>$value['good_img'],
  238. "cat_id"=>$value['cat_id'],
  239. "unit"=>$value['unit'],
  240. "brand_id"=>$value['brand_id'],
  241. "arrival_time"=>$value['arrival_time'],
  242. "model"=>$value['model'],
  243. "color"=>$value['color'],
  244. "material"=>$value['material'],
  245. "cost_desc"=>$value['cost_desc'],
  246. "is_addrs"=>$value['is_addrs'],
  247. "is_custom"=>$value['is_custom'],
  248. "metal_id"=>$value['metal_id'],
  249. "config"=>isset($value['config'])?$value['config']:"",
  250. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  251. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  252. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  253. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  254. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  255. "budget_price"=>$value['budget_price'],
  256. "num"=>$value['num'],
  257. "use_desc"=>$value['use_desc'],
  258. "remark"=>$value['remark'],
  259. "status"=>1,
  260. "is_del"=>0,
  261. "addtime"=>date("Y-m-d H:i:s"),
  262. "updatetime"=>date("Y-m-d H:i:s")
  263. ];
  264. $up = Db::name("consult_info")->insert($info);
  265. if(!$up){
  266. Db::rollback();
  267. return error_show(1004,'添加失败');
  268. }
  269. }
  270. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  271. }else{
  272. return error_show(1004,"新建失败");
  273. }
  274. }
  275. // public function zxadd(){
  276. // $good_name = isset($this->post['good_name'])&&$this->post['good_name']!==""?trim($this->post['good_name']):"";
  277. // if($good_name===""){
  278. // return error_show(1004,"参数good_name不能为空");
  279. // }
  280. // $zxNo = isset($this->post['zxNo'])&&$this->post['zxNo']!==""?trim($this->post['zxNo']):"";
  281. // if($zxNo===""){
  282. // return error_show(1004,"参数zxNo不能为空");
  283. // }
  284. //
  285. // $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!==""?intval($this->post['cat_id']):"";
  286. // if($cat_id===""){
  287. // return error_show(1004,"参数cat_id不能为空");
  288. // }
  289. // $arrival_time = isset($this->post['arrival_time'])&&$this->post['arrival_time']!==""?$this->post['arrival_time']
  290. // :"";
  291. // if($arrival_time===""){
  292. // return error_show(1004,"参数arrival_time不能为空");
  293. // }
  294. // $good_img = isset($this->post['good_img'])&&$this->post['good_img']!==""?trim($this->post['good_img']):"";
  295. // if($good_img===""){
  296. // return error_show(1004,"参数good_img不能为空");
  297. // }
  298. // $is_custom = isset($this->post['is_custom'])&&$this->post['is_custom']!==""?intval($this->post['is_custom']):"";
  299. // if($is_custom===""){
  300. // return error_show(1004,"参数is_custom不能为空");
  301. // }
  302. // $unit = isset($this->post['unit'])&&$this->post['unit']!==""?trim($this->post['unit']):"";
  303. // if($unit===""){
  304. // return error_show(1004,"参数unit不能为空");
  305. // }
  306. // $brand_id = isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"";
  307. // if($brand_id===""){
  308. // return error_show(1004,"参数brand_id不能为空");
  309. // }
  310. // $material = isset($this->post['material'])&&$this->post['material']!==""?trim($this->post['material']):"";
  311. // if($material===""){
  312. // return error_show(1004,"参数material不能为空");
  313. // }
  314. // $color = isset($this->post['color'])&&$this->post['color']!==""?trim($this->post['color']):"";
  315. // if($color===""){
  316. // return error_show(1004,"参数color不能为空");
  317. // }
  318. // $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!==""?trim($this->post['cost_desc']):"";
  319. // if($cost_desc===""){
  320. // return error_show(1004,"参数cost_desc不能为空");
  321. // }
  322. // $model = isset($this->post['model'])&&$this->post['model']!==""?trim($this->post['model']):"";
  323. // if($model===""){
  324. // return error_show(1004,"参数model不能为空");
  325. // }
  326. //
  327. // $is_addrs = isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  328. // if($is_addrs===""){
  329. // return error_show(1004,"参数is_addrs不能为空");
  330. // }
  331. //
  332. // $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!==""?trim($this->post['metal_id']):"";
  333. // if($metal_id===""){
  334. // return error_show(1004,"参数metal_id不能为空");
  335. // }
  336. // if($metal_id==0){
  337. // $config = isset($this->post['config'])&&!empty($this->post['config'])?$this->post['config']:"";
  338. // if($config===""){
  339. // return error_show(1004,"参数config不能为空");
  340. // }
  341. // $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""?trim($this->post['other_config'])
  342. // :"";
  343. // if($other_config===""){
  344. // return error_show(1004,"参数other_config不能为空");
  345. // }
  346. // $specs_weight = isset($this->post['specs_weight'])&&$this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  347. // if($specs_weight===""){
  348. // return error_show(1004,"参数specs_weight不能为空");
  349. // }
  350. // $gold_price = isset($this->post['gold_price'])&&$this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  351. // if($gold_price===""){
  352. // return error_show(1004,"参数gold_price不能为空");
  353. // }
  354. //
  355. // }
  356. // $budget_price = isset($this->post['budget_price'])&&$this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  357. // if($budget_price===""){
  358. // return error_show(1004,"参数budget_price不能为空");
  359. // }
  360. // $num = isset($this->post['num'])&&$this->post['num']!==""?intval($this->post['num']):"";
  361. // if($num===""){
  362. // return error_show(1004,"参数num不能为空");
  363. // }
  364. // $use_desc = isset($this->post['use_desc'])&&$this->post['use_desc']!==""?trim($this->post['use_desc']):"";
  365. // if($use_desc===""){
  366. // return error_show(1004,"参数use_desc不能为空");
  367. // }
  368. // $remark = isset($this->post['remark'])&&$this->post['remark']!==""?trim($this->post['remark']):"";
  369. // if($remark===""){
  370. // return error_show(1004,"参数remark不能为空");
  371. // }
  372. //
  373. // Db::startTrans();
  374. // try{
  375. // $infoNo=makeNo("INF");
  376. // $info=[
  377. // "infoNo"=>$infoNo,
  378. // "zxNo"=>$zxNo,
  379. // "spuCode"=>"",
  380. // "good_name"=>$good_name,
  381. // "good_img"=>$good_img,
  382. // "cat_id"=>$cat_id,
  383. // "unit"=>$unit,
  384. // "brand_id"=>$brand_id,
  385. // "arrival_time"=>$arrival_time,
  386. // "model"=>$model,
  387. // "color"=>$color,
  388. // "material"=>$material,
  389. // "cost_desc"=>$cost_desc,
  390. // "is_addrs"=>$is_addrs,
  391. // "is_custom"=>$is_custom,
  392. // "metal_id"=>$metal_id,
  393. // "config"=>isset($config)?$config:"",
  394. // "other_config"=>isset($other_config)?$other_config:"",
  395. // "specs_weight"=>isset($specs_weight)?$specs_weight:0,
  396. // "gold_price"=>isset($gold_price)?$gold_price:0,
  397. // "budget_price"=>$budget_price,
  398. // "num"=>$num,
  399. // "use_desc"=>$use_desc,
  400. // "remark"=>$remark,
  401. // "status"=>0,
  402. // "is_del"=>0,
  403. // "addtime"=>date("Y-m-d H:i:s"),
  404. // "updatetime"=>date("Y-m-d H:i:s")
  405. // ];
  406. // $up = Db::name("consult_info")->insert($info);
  407. // if($up){
  408. // Db::commit();
  409. // return app_show(0,"添加成功",["infoNo"=>$infoNo]);
  410. // }else{
  411. // Db::rollback();
  412. // return error_show(1004,'添加失败');
  413. // }
  414. // }catch (\Exception $e){
  415. // Db::rollback();
  416. // return error_show(1004,$e->getMessage());
  417. // }
  418. // }
  419. public function zxinfo(){
  420. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  421. if($infoNo==""){
  422. return error_show(1004,"参数infoNo不能为空");
  423. }
  424. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  425. if($zxinfo==false){
  426. return error_show(1004,"未找到信息数据");
  427. }
  428. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  429. if($zxorder==false){
  430. return error_show(1004,"未找到咨询信息数据");
  431. }
  432. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  433. $budget = isset($cat['order_rate']) ? $cat['order_rate']:100;
  434. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  435. $zxinfo['khname']="";
  436. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  437. $zxinfo['khNo']="";
  438. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  439. $zxinfo['brand']="";
  440. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  441. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  442. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  443. $zxinfo['company']="";
  444. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  445. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  446. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  447. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  448. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  449. $zxinfo['project_name']="";
  450. $zxinfo['budget_total']="";
  451. $zxinfo['departinfo']=[];
  452. $zxinfo['unit_name']="";
  453. if($zxorder['khNo']!==""){
  454. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  455. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  456. $zxinfo['khNo']= $zxorder['khNo'];
  457. }
  458. if($zxinfo['unit']!==""){
  459. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  460. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  461. }
  462. if($zxinfo['brand_id']!==""){
  463. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  464. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  465. }
  466. if($zxorder['companyNo']!==""){
  467. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  468. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  469. }
  470. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  471. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  472. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  473. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  474. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  475. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['infoNo']])->find();
  476. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  477. }
  478. if($zxorder['depart']>0){
  479. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  480. }
  481. if($zxorder['platform_code']>0){
  482. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  483. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  484. }
  485. return app_show(0,"获取成功",$zxinfo);
  486. }
  487. //** 发布竞标任务 */
  488. public function bargain(){
  489. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  490. if($infoNo==""){
  491. return error_show(1004,"参数infoNo不能为空");
  492. }
  493. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  494. if($zxinfo==false){
  495. return error_show(1004,"未找到信息数据");
  496. }
  497. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  498. if($status===""){
  499. return error_show(1004,"参数status不能为空");
  500. }
  501. if($status==1&&$zxinfo['status']>1){
  502. $zxinfo['bargain_num']=+1;
  503. }
  504. $zxinfo['status']=$status;
  505. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  506. $up = Db::name("consult_info")->save($zxinfo);
  507. if($up){
  508. return app_show(0,"状态更新成功");
  509. }else{
  510. return error_show(1003,"状态更新失败");
  511. }
  512. }
  513. public function feadback(){
  514. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  515. if($infoNo==""){
  516. return error_show(1004,"参数infoNo不能为空");
  517. }
  518. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  519. if($zxinfo==false){
  520. return error_show(1004,"未找到信息数据");
  521. }
  522. if($zxinfo['status']!=1){
  523. return error_show(1004,"任务未进行");
  524. }
  525. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  526. if($pname==""){
  527. return error_show(1004,"参数pname不能为空");
  528. }
  529. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  530. if($brandid==""){
  531. return error_show(1004,"参数brandid不能为空");
  532. }
  533. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  534. if($cat_id==""){
  535. return error_show(1004,"参数cat_id不能为空");
  536. }
  537. $model = isset($this->post['model'])&&$this->post['model']!=""? trim($this->post['model']):"";
  538. //$unit = isset($this->post['model'])&&$this->post['model']!=""? trim($this->post['model']):"";
  539. $material = isset($this->post['material'])&&$this->post['material']!=""? trim($this->post['material']):"";
  540. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  541. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  542. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  543. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  544. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  545. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  546. :"";
  547. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  548. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  549. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  550. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  551. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  552. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"";
  553. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"";
  554. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  555. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"";
  556. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"";
  557. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"";
  558. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"";
  559. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"";
  560. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!=""? floatval($this->post['nake_fee']):"";
  561. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"";
  562. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"";
  563. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"";
  564. $total_fee = isset($this->post['total_fee'])&&$this->post['total_fee']!=""? floatval($this->post['total_fee']):"";
  565. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  566. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  567. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  568. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  569. if($token==''){
  570. return error_show(1005,"参数token不能为空");
  571. }
  572. $user =GetUserInfo($token);
  573. if(empty($user)||$user['code']!=0){
  574. return error_show(1002,"用户数据不存在");
  575. }
  576. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  577. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  578. $bidNo=makeNo("BD");
  579. $spucode=makeNo("SPU");
  580. $data=[
  581. "bidNo"=>$bidNo,
  582. "infoNo"=>$infoNo,
  583. "zxNo"=>$zxinfo['zxNo'],
  584. "spuCode"=>$spucode,
  585. "good_name"=>$pname,
  586. "brand_id"=>$brandid,
  587. "cat_id"=>$cat_id,
  588. "model"=>$model,
  589. "material"=>$material,
  590. "unit_id"=>$unit_id,
  591. "cost_desc"=>$cost_desc,
  592. "work_day"=>$work_day,
  593. "delivery_day"=>$delivery_day,
  594. "good_img"=>$good_img,
  595. "expire_day"=>$expire_day,
  596. "origin_place"=>$origin_place,
  597. "supplierNo"=>$supplierNo,
  598. "pay_way"=>$pay_way,
  599. "tax"=>$tax,
  600. "send_way"=>$send_way,
  601. "metal_id"=>$metal_id,
  602. "is_gold_price"=>$is_gold_price,
  603. "config"=>$config,
  604. "weight"=>$weight,
  605. "is_diff"=>$is_diff,
  606. "demo_fee"=>$demo_fee,
  607. "delivery_fee"=>$delivery_fee,
  608. "open_fee"=>$open_fee,
  609. "pakge_fee"=>$pakge_fee,
  610. "nake_fee"=>$nake_fee,
  611. "mark_fee"=>$mark_fee,
  612. "cert_fee"=>$cert_fee,
  613. "cost_fee"=>$cost_fee,
  614. "total_fee"=>$total_fee,
  615. "supply_area"=>$supply_area,
  616. "remark"=>$remark,
  617. "sale_price"=>0,
  618. "createrid"=>$createrid,
  619. "creater"=>$creater,
  620. "status"=>$zxinfo['status']==1 ?1 :2,
  621. "is_del"=>0,
  622. "addtime"=>date("Y-m-d H:i:s"),
  623. "updatetime"=>date("Y-m-d H:i:s")
  624. ];
  625. Db::startTrans();
  626. try{
  627. $insert= Db::name("consult_bids")->insert($data);
  628. if($insert){
  629. $data=[
  630. "spuCode"=>$spucode,
  631. "good_name"=>$pname,
  632. "brand_id"=>$brandid,
  633. "good_unit"=>$unit_id,
  634. "good_type"=>0,
  635. "moq"=>1,
  636. "customized"=>$work_day,
  637. "tax"=>$tax,
  638. "supplierNo"=>$supplierNo,
  639. "is_auth"=>0,
  640. "craft_desc"=>$cost_desc,
  641. "good_remark"=>$remark,
  642. "good_img"=>$good_img,
  643. "good_thumb_img"=>"",
  644. "good_info_img"=>"",
  645. "status"=>1,
  646. "is_del"=>0,
  647. "createrid"=>$createrid,
  648. "creater"=>$creater,
  649. "addtime"=>date("Y-m-d H:i:s"),
  650. "updatetime"=>date("Y-m-d H:i:s")
  651. ];
  652. $good = Db::name("good_zixun")->insert($data);
  653. if($good){
  654. Db::commit();
  655. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  656. }else{
  657. Db::rollback();
  658. return error_show(1004,"反馈失败");
  659. }
  660. }else{
  661. Db::rollback();
  662. return error_show(1004,"反馈失败");
  663. }
  664. }catch (\Exception $e){
  665. Db::rollback();
  666. return error_show(1004,$e->getMessage());
  667. }
  668. }
  669. public function feadinfo(){
  670. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  671. if($bidNo==""){
  672. return error_show(1004,"参数bidNo不能为空");
  673. }
  674. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  675. if($info==false){
  676. return error_show(1004,"未找到商品数据");
  677. }
  678. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  679. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  680. $info['cat_info'] = made($info['cat_id'],[]);
  681. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  682. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  683. if($info['brand_id']!=0){
  684. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  685. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  686. }else{
  687. $info["brand_name"]="";
  688. $info["brand_id"]="";
  689. }
  690. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  691. $info['bargain'] =$bargain;
  692. return app_show(0,"获取成功",$info);
  693. }
  694. public function bargain_add(){
  695. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  696. if($bidNo===""){
  697. return error_show(1004,"参数bidNo不能为空");
  698. }
  699. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  700. if($info==false){
  701. return error_show(1004,"未找到商品数据");
  702. }
  703. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  704. if($infos==false){
  705. return error_show(1004,"未找到商品数据");
  706. }
  707. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  708. if($token==''){
  709. return error_show(1005,"参数token不能为空");
  710. }
  711. $user =GetUserInfo($token);
  712. if(empty($user)||$user['code']!=0){
  713. return error_show(1002,"用户数据不存在");
  714. }
  715. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  716. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  717. $bargainNo =makeNo("BAR");
  718. Db::startTrans();
  719. try{
  720. $data=[
  721. "bidsNo"=>$bidNo,
  722. "bargainNo"=>$bargainNo,
  723. "bargain_type"=>1,
  724. "sale_price"=>$info['sale_price'],
  725. "cost_before_price"=>$info['cost_fee'],
  726. "cost_after_price"=>$info['cost_fee'],
  727. "before_rate"=>$info['cost_fee'],
  728. "after_rate"=>$info['cost_fee'],
  729. "after_price"=>$infos['budget_price'],
  730. "status"=>1,
  731. "is_del"=>0,
  732. "creater"=>$creater,
  733. "createrid"=>$createrid,
  734. "addtime"=>date("Y-m-d H:i:s"),
  735. "updatetime"=>date("Y-m-d H:i:s")
  736. ];
  737. $int = Db::name("bargain_order")->insert($data);
  738. if($int){
  739. $info['status']=3;
  740. $info['updatetime']=date("Y-m-d H:i:s");
  741. $up =Db::name("consult_bids")->save($info);
  742. if($up){
  743. Db::commit();
  744. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  745. }
  746. }
  747. }catch (\Exception $e){
  748. Db::rollback();
  749. return error_show(1004,$e->getMessage());
  750. }
  751. }
  752. public function bargain_status(){
  753. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  754. if($bargainNo===""){
  755. return error_show(1004,"参数bargainNo不能为空");
  756. }
  757. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  758. if($info==false){
  759. return error_show(1004,"未找到议价数据");
  760. }
  761. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  762. if($bids==false){
  763. return error_show(1004,"未找到商品数据");
  764. }
  765. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  766. if($status==''){
  767. return error_show(1005,"参数status不能为空");
  768. }
  769. Db::startTrans();
  770. try{
  771. $info['status'] =$status;
  772. $info['updatetime'] =date("Y-m-d H:i:s");
  773. $up =Db::name("bargain_order")->save($info);
  774. if($up){
  775. if($status==4){
  776. $bids['status']=4;
  777. $bids['sale_price']=$info['after_price'];
  778. $bids['updatetime']=date("Y-m-d H:i:s");
  779. $up =Db::name("consult_bids")->save($bids);
  780. if($up==false){
  781. Db::rollback();
  782. return error_show(1004,"数据更新失败");
  783. }
  784. }
  785. if($status==5||$status==6||$status==7){
  786. $bids['status']=4;
  787. $bids['updatetime']=date("Y-m-d H:i:s");
  788. $up =Db::name("consult_bids")->save($bids);
  789. if($up==false){
  790. Db::rollback();
  791. return error_show(1004,"数据更新失败");
  792. }
  793. }
  794. Db::commit();
  795. return app_show(0,"更新成功");
  796. }
  797. }catch (\Exception $e){
  798. Db::rollback();
  799. return error_show(1004,$e->getMessage());
  800. }
  801. }
  802. public function bargain_info(){
  803. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  804. if($bargainNo===""){
  805. return error_show(1004,"参数bargainNo不能为空");
  806. }
  807. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  808. if($info==false){
  809. return error_show(1004,"未找到议价数据");
  810. }
  811. return app_show(0,"获取成功",$info);
  812. }
  813. public function bidlist(){
  814. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  815. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  816. $where=[['is_del',"=",0]];
  817. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  818. if ($zxNo !== "") {
  819. $where[] = ['zxNo','=',$zxNo];
  820. }
  821. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  822. if ($infoNo !== "") {
  823. $where[] = ['infoNo','=',$infoNo];
  824. }
  825. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  826. if ($bidNo !== "") {
  827. $where[] = ['bidNo','=',$bidNo];
  828. }
  829. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  830. if ($projectNo !== "") {
  831. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  832. ("zxNo");
  833. $where[] = ['zxNo','in',$zxlist];
  834. }
  835. $count = Db::name('consult_bids')->where($where)->count();
  836. $total = ceil($count / $size);
  837. $page = $page >= $total ? $total : $page;
  838. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select();
  839. $data=[];
  840. foreach ($list as $value){
  841. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  842. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  843. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  844. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  845. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  846. if($value['brand_id']!=0){
  847. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  848. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  849. }else{
  850. $value["brand_name"]="";
  851. $value["brand_id"]="";
  852. }
  853. $data[]=$value;
  854. }
  855. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  856. }
  857. }