Consult.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  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['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  440. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  441. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  442. $zxinfo['company']="";
  443. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  444. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  445. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  446. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  447. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  448. $zxinfo['project_name']="";
  449. $zxinfo['budget_total']="";
  450. $zxinfo['departinfo']=[];
  451. $zxinfo['unit_name']="";
  452. if($zxorder['khNo']!==""){
  453. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  454. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  455. $zxinfo['khNo']= $zxorder['khNo'];
  456. }
  457. if($zxinfo['unit']!==""){
  458. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  459. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  460. }
  461. if($zxorder['companyNo']!==""){
  462. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  463. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  464. }
  465. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  466. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  467. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  468. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  469. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  470. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['infoNo']])->find();
  471. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  472. }
  473. if($zxorder['depart']>0){
  474. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  475. }
  476. if($zxorder['platform_code']>0){
  477. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  478. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  479. }
  480. return app_show(0,"获取成功",$zxinfo);
  481. }
  482. //** 发布竞标任务 */
  483. public function bargain(){
  484. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  485. if($infoNo==""){
  486. return error_show(1004,"参数infoNo不能为空");
  487. }
  488. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  489. if($zxinfo==false){
  490. return error_show(1004,"未找到信息数据");
  491. }
  492. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  493. if($status===""){
  494. return error_show(1004,"参数status不能为空");
  495. }
  496. if($status==1&&$zxinfo['status']>1){
  497. $zxinfo['bargain_num']=+1;
  498. }
  499. $zxinfo['status']=$status;
  500. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  501. $up = Db::name("consult_info")->save($zxinfo);
  502. if($up){
  503. return app_show(0,"状态更新成功");
  504. }else{
  505. return error_show(1003,"状态更新失败");
  506. }
  507. }
  508. public function feadback(){
  509. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  510. if($infoNo==""){
  511. return error_show(1004,"参数infoNo不能为空");
  512. }
  513. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  514. if($zxinfo==false){
  515. return error_show(1004,"未找到信息数据");
  516. }
  517. if($zxinfo['status']!==1){
  518. return error_show(1004,"任务未进行");
  519. }
  520. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  521. if($pname==""){
  522. return error_show(1004,"参数pname不能为空");
  523. }
  524. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  525. if($brandid==""){
  526. return error_show(1004,"参数brandid不能为空");
  527. }
  528. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  529. if($cat_id==""){
  530. return error_show(1004,"参数cat_id不能为空");
  531. }
  532. $model = isset($this->post['model'])&&$this->post['model']!=""? trim($this->post['model']):"";
  533. //$unit = isset($this->post['model'])&&$this->post['model']!=""? trim($this->post['model']):"";
  534. $material = isset($this->post['material'])&&$this->post['material']!=""? trim($this->post['material']):"";
  535. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  536. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  537. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  538. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  539. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  540. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  541. :"";
  542. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  543. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  544. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  545. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  546. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  547. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"";
  548. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"";
  549. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  550. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"";
  551. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"";
  552. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"";
  553. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"";
  554. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"";
  555. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!=""? floatval($this->post['nake_fee']):"";
  556. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"";
  557. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"";
  558. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"";
  559. $total_fee = isset($this->post['total_fee'])&&$this->post['total_fee']!=""? floatval($this->post['total_fee']):"";
  560. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  561. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  562. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  563. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  564. if($token==''){
  565. return error_show(1005,"参数token不能为空");
  566. }
  567. $user =GetUserInfo($token);
  568. if(empty($user)||$user['code']!=0){
  569. return error_show(1002,"用户数据不存在");
  570. }
  571. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  572. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  573. $bidNo=makeNo("BD");
  574. $spucode=makeNo("SPU");
  575. $data=[
  576. "bidNo"=>$bidNo,
  577. "infoNo"=>$infoNo,
  578. "zxNo"=>$zxinfo['zxNo'],
  579. "spuCode"=>$spucode,
  580. "good_name"=>$pname,
  581. "brand_id"=>$brandid,
  582. "cat_id"=>$cat_id,
  583. "model"=>$model,
  584. "material"=>$material,
  585. "unit_id"=>$unit_id,
  586. "cost_desc"=>$cost_desc,
  587. "work_day"=>$work_day,
  588. "delivery_day"=>$delivery_day,
  589. "good_img"=>$good_img,
  590. "expire_day"=>$expire_day,
  591. "origin_place"=>$origin_place,
  592. "supplierNo"=>$supplierNo,
  593. "pay_way"=>$pay_way,
  594. "tax"=>$tax,
  595. "send_way"=>$send_way,
  596. "metal_id"=>$metal_id,
  597. "is_gold_price"=>$is_gold_price,
  598. "config"=>$config,
  599. "weight"=>$weight,
  600. "is_diff"=>$is_diff,
  601. "demo_fee"=>$demo_fee,
  602. "delivery_fee"=>$delivery_fee,
  603. "open_fee"=>$open_fee,
  604. "pakge_fee"=>$pakge_fee,
  605. "nake_fee"=>$nake_fee,
  606. "mark_fee"=>$mark_fee,
  607. "cert_fee"=>$cert_fee,
  608. "cost_fee"=>$cost_fee,
  609. "total_fee"=>$total_fee,
  610. "supply_area"=>$supply_area,
  611. "remark"=>$remark,
  612. "sale_price"=>0,
  613. "createrid"=>$createrid,
  614. "creater"=>$creater,
  615. "status"=>$zxinfo['status']==1 ?1 :2,
  616. "is_del"=>0,
  617. "addtime"=>date("Y-m-d H:i:s"),
  618. "updatetime"=>date("Y-m-d H:i:s")
  619. ];
  620. Db::startTrans();
  621. try{
  622. $insert= Db::name("consult_bids")->insert($data);
  623. if($insert){
  624. $data=[
  625. "spuCode"=>$spucode,
  626. "good_name"=>$pname,
  627. "brand_id"=>$brandid,
  628. "good_unit"=>$unit_id,
  629. "good_type"=>0,
  630. "moq"=>1,
  631. "customized"=>$work_day,
  632. "tax"=>$tax,
  633. "supplierNo"=>$supplierNo,
  634. "is_auth"=>0,
  635. "craft_desc"=>$cost_desc,
  636. "good_remark"=>$remark,
  637. "good_img"=>$good_img,
  638. "good_thumb_img"=>"",
  639. "good_info_img"=>"",
  640. "status"=>1,
  641. "is_del"=>0,
  642. "createrid"=>$createrid,
  643. "creater"=>$creater,
  644. "addtime"=>date("Y-m-d H:i:s"),
  645. "updatetime"=>date("Y-m-d H:i:s")
  646. ];
  647. $good = Db::name("good_zixun")->insert($data);
  648. if($good){
  649. Db::commit();
  650. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  651. }else{
  652. Db::rollback();
  653. return error_show(1004,"反馈失败");
  654. }
  655. }else{
  656. Db::rollback();
  657. return error_show(1004,"反馈失败");
  658. }
  659. }catch (\Exception $e){
  660. Db::rollback();
  661. return error_show(1004,$e->getMessage());
  662. }
  663. }
  664. public function feadinfo(){
  665. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  666. if($bidNo==""){
  667. return error_show(1004,"参数bidNo不能为空");
  668. }
  669. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  670. if($info==false){
  671. return error_show(1004,"未找到商品数据");
  672. }
  673. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  674. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  675. $info['cat_info'] = made($info['cat_id'],[]);
  676. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  677. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  678. if($info['brand_id']!=0){
  679. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  680. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  681. }else{
  682. $info["brand_name"]="";
  683. $info["brand_id"]="";
  684. }
  685. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  686. $info['bargain'] =$bargain;
  687. return app_show(0,"获取成功",$info);
  688. }
  689. public function bargain_add(){
  690. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  691. if($bidNo===""){
  692. return error_show(1004,"参数bidNo不能为空");
  693. }
  694. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  695. if($info==false){
  696. return error_show(1004,"未找到商品数据");
  697. }
  698. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  699. if($infos==false){
  700. return error_show(1004,"未找到商品数据");
  701. }
  702. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  703. if($token==''){
  704. return error_show(1005,"参数token不能为空");
  705. }
  706. $user =GetUserInfo($token);
  707. if(empty($user)||$user['code']!=0){
  708. return error_show(1002,"用户数据不存在");
  709. }
  710. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  711. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  712. $bargainNo =makeNo("BAR");
  713. Db::startTrans();
  714. try{
  715. $data=[
  716. "bidsNo"=>$bidNo,
  717. "bargainNo"=>$bargainNo,
  718. "bargain_type"=>1,
  719. "sale_price"=>$info['sale_price'],
  720. "cost_before_price"=>$info['cost_fee'],
  721. "cost_after_price"=>$info['cost_fee'],
  722. "before_rate"=>$info['cost_fee'],
  723. "after_rate"=>$info['cost_fee'],
  724. "after_price"=>$infos['budget_price'],
  725. "status"=>1,
  726. "is_del"=>0,
  727. "creater"=>$creater,
  728. "createrid"=>$createrid,
  729. "addtime"=>date("Y-m-d H:i:s"),
  730. "updatetime"=>date("Y-m-d H:i:s")
  731. ];
  732. $int = Db::name("bargain_order")->insert($data);
  733. if($int){
  734. $info['status']=3;
  735. $info['updatetime']=date("Y-m-d H:i:s");
  736. $up =Db::name("consult_bids")->save($info);
  737. if($up){
  738. Db::commit();
  739. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  740. }
  741. }
  742. }catch (\Exception $e){
  743. Db::rollback();
  744. return error_show(1004,$e->getMessage());
  745. }
  746. }
  747. public function bargain_status(){
  748. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  749. if($bargainNo===""){
  750. return error_show(1004,"参数bargainNo不能为空");
  751. }
  752. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  753. if($info==false){
  754. return error_show(1004,"未找到议价数据");
  755. }
  756. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  757. if($bids==false){
  758. return error_show(1004,"未找到商品数据");
  759. }
  760. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  761. if($status==''){
  762. return error_show(1005,"参数status不能为空");
  763. }
  764. Db::startTrans();
  765. try{
  766. $info['status'] =$status;
  767. $info['updatetime'] =date("Y-m-d H:i:s");
  768. $up =Db::name("bargain_order")->save($info);
  769. if($up){
  770. if($status==4){
  771. $bids['status']=4;
  772. $bids['sale_price']=$info['after_price'];
  773. $bids['updatetime']=date("Y-m-d H:i:s");
  774. $up =Db::name("consult_bids")->save($bids);
  775. if($up==false){
  776. Db::rollback();
  777. return error_show(1004,"数据更新失败");
  778. }
  779. }
  780. if($status==5||$status==6||$status==7){
  781. $bids['status']=4;
  782. $bids['updatetime']=date("Y-m-d H:i:s");
  783. $up =Db::name("consult_bids")->save($bids);
  784. if($up==false){
  785. Db::rollback();
  786. return error_show(1004,"数据更新失败");
  787. }
  788. }
  789. Db::commit();
  790. return app_show(0,"更新成功");
  791. }
  792. }catch (\Exception $e){
  793. Db::rollback();
  794. return error_show(1004,$e->getMessage());
  795. }
  796. }
  797. public function bargain_info(){
  798. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  799. if($bargainNo===""){
  800. return error_show(1004,"参数bargainNo不能为空");
  801. }
  802. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  803. if($info==false){
  804. return error_show(1004,"未找到议价数据");
  805. }
  806. return app_show(0,"获取成功",$info);
  807. }
  808. public function bidlist(){
  809. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  810. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  811. $where=[['is_del',"=",0]];
  812. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  813. if ($zxNo !== "") {
  814. $where[] = ['zxNo','=',$zxNo];
  815. }
  816. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  817. if ($infoNo !== "") {
  818. $where[] = ['infoNo','=',$infoNo];
  819. }
  820. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  821. if ($bidNo !== "") {
  822. $where[] = ['bidNo','=',$bidNo];
  823. }
  824. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  825. if ($projectNo !== "") {
  826. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  827. ("zxNo");
  828. $where[] = ['zxNo','in',$zxlist];
  829. }
  830. $count = Db::name('consult_bids')->where($where)->count();
  831. $total = ceil($count / $size);
  832. $page = $page >= $total ? $total : $page;
  833. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select();
  834. $data=[];
  835. foreach ($list as $value){
  836. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  837. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  838. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  839. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  840. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  841. if($value['brand_id']!=0){
  842. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  843. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  844. }else{
  845. $value["brand_name"]="";
  846. $value["brand_id"]="";
  847. }
  848. $data[]=$value;
  849. }
  850. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  851. }
  852. }