Consult.php 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ProcessOrder;
  5. use think\App;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. class Consult extends Base
  9. {
  10. public $noble=[];
  11. public function __construct(App $app)
  12. {
  13. parent::__construct($app);
  14. $this->noble =\think\facade\Config::get("noble");
  15. }
  16. public function conlist(){
  17. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  18. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  19. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  20. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  21. if ($infoNo !== "") {
  22. $where[] = ['a.infoNo','=',$infoNo];
  23. }
  24. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  25. if ($salesman !== "") {
  26. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  27. $where[]= ["b.salesman",'like',"%$salesman%"];
  28. }
  29. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  30. if ($cpName !== "") {
  31. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  32. $where[]= ["a.good_Name",'like',"%$cpName%"];
  33. }
  34. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  35. if ($khNo !== "") {
  36. // $where['khNo'] = $khNo;
  37. $where[]= ["b.khNo",'like',"%$khNo%"];
  38. }
  39. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  40. if ($companyNo !== "") {
  41. // $where['khNo'] = $khNo;
  42. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  43. }
  44. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  45. if ($start !="") {
  46. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  47. $where[]= ["a.addtime",'>=',$start];
  48. }
  49. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  50. if($end !=""){
  51. $where[]= ["a.addtime",'<=',$end];
  52. }
  53. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  54. if ($status !== "") {
  55. $where[]= ["a.status",'=',$status];
  56. }
  57. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  58. ->count();
  59. $total = ceil($count / $size);
  60. $page = $page >= $total ? $total : $page;
  61. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  62. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->order("a.id desc")->select();
  63. $data=[];
  64. foreach ($list as $value){
  65. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  66. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  67. true):[];
  68. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  69. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  70. $value['khname']="";
  71. if($value['khNo']!==""){
  72. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  73. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  74. }
  75. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  76. $data[]=$value;
  77. }
  78. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  79. }
  80. public function info(){
  81. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  82. if($id==""){
  83. return error_show(1002,"咨询单编号不能为空");
  84. }
  85. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  86. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  87. $fo['can']=$in;
  88. if(empty($fo)){
  89. return error_show(1002,"未找到咨询单编号");
  90. }else{
  91. return app_show(0,"获取成功",$fo);
  92. }
  93. }
  94. public function del(){
  95. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  96. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  97. if($de==false){
  98. return error_show(1002,'咨询单信息未找到');
  99. }
  100. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  101. if($dell){
  102. return error_show(0,"删除成功");
  103. }else
  104. return error_show(1002,"删除失败");
  105. }
  106. public function create(){
  107. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  108. if($is_project===""){
  109. return error_show(1002,"参数is_project不能为空");
  110. }
  111. if($is_project==1){
  112. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  113. if($projectNo===""){
  114. return error_show(1002,"参数projectNo不能为空");
  115. }
  116. }
  117. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  118. if($khNo===""){
  119. return error_show(1002,"参数khNo不能为空");
  120. }
  121. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  122. if($companyNo===""){
  123. return error_show(1002,"参数companyNo不能为空");
  124. }
  125. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  126. if($endtime===""){
  127. return error_show(1002,"参数endtime不能为空");
  128. }
  129. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  130. "";
  131. if($platform_code===""){
  132. return error_show(1002,"参数platform_code不能为空");
  133. }
  134. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  135. if($ladder==""){
  136. return error_show(1005,"参数ladder不能为空");
  137. }
  138. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  139. if($token==''){
  140. return error_show(105,"参数token不能为空");
  141. }
  142. $user =GetUserInfo($token);
  143. if(empty($user)||$user['code']!=0){
  144. return error_show(102,"用户数据不存在");
  145. }
  146. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  147. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  148. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  149. $zxNo=makeNo("ZX");
  150. Db::startTrans();
  151. try{
  152. $data=[
  153. "zxNo"=>$zxNo,
  154. "createrid"=>$createrid,
  155. "creater"=>$creater,
  156. "is_project"=>$is_project,
  157. "projectNo"=>isset($projectNo) ? $projectNo:"",
  158. "khNo"=>$khNo,
  159. "companyNo"=>$companyNo,
  160. "endtime"=>$endtime,
  161. "salesman"=>$creater,
  162. "platform_code"=>$platform_code,
  163. "saleid"=>$createrid,
  164. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  165. "status"=>0,
  166. "is_del"=>0,
  167. "addtime"=>date("Y-m-d H:i:s"),
  168. "updatetime"=>date("Y-m-d H:i:s"),
  169. ];
  170. $zx = Db::name("consult_order")->insert($data);
  171. if($zx){
  172. foreach ($ladder as $value){
  173. $infoNo=makeNo("INF");
  174. $specinfo=[];
  175. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  176. foreach ($value["specinfo"] as $v){
  177. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  178. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  179. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  180. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  181. $specinfo[]=$v;
  182. }
  183. }
  184. $info=[
  185. "infoNo"=>$infoNo,
  186. "zxNo"=>$zxNo,
  187. "spuCode"=>"",
  188. "good_name"=>$value['good_name'],
  189. "good_img"=>$value['good_img'],
  190. "cat_id"=>$value['cat_id'],
  191. "unit"=>$value['unit'],
  192. "brand_id"=>$value['brand_id'],
  193. "arrival_time"=>$value['arrival_time'],
  194. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  195. "cost_desc"=>$value['cost_desc'],
  196. "is_addrs"=>$value['is_addrs'],
  197. "is_custom"=>$value['is_custom'],
  198. "metal_id"=>$value['metal_id'],
  199. "config"=>isset($value['config'])?$value['config']:"",
  200. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  201. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  202. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  203. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  204. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  205. "budget_price"=>$value['budget_price'],
  206. "num"=>$value['num'],
  207. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  208. "use_desc"=>$value['use_desc'],
  209. "remark"=>$value['remark'],
  210. "status"=>1,
  211. "is_del"=>0,
  212. "addtime"=>date("Y-m-d H:i:s"),
  213. "updatetime"=>date("Y-m-d H:i:s")
  214. ];
  215. $up = Db::name("consult_info")->insert($info);
  216. if(!$up){
  217. Db::rollback();
  218. return error_show(1004,'添加失败');
  219. }
  220. }
  221. $stn = ["order_code"=>$zxNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  222. ActionLog::logAdd($this->post['token'],$stn,"ZXD",2,$info);
  223. $process=["order_code"=>$zxNo,"order_id"=>Db::name("consult_order")->getLastInsID(),"order_status"=>1,"order_type"=>'ZXD'];
  224. ProcessOrder::AddProcess($this->post['token'],$process);
  225. Db::commit();
  226. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  227. }else{
  228. Db::rollback();
  229. return error_show(1004,"新建失败");
  230. }
  231. }catch (\Exception $e){
  232. Db::rollback();
  233. return error_show(1003,$e->getMessage());
  234. }
  235. }
  236. public function zxinfo(){
  237. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  238. if($infoNo==""){
  239. return error_show(1004,"参数infoNo不能为空");
  240. }
  241. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  242. if($zxinfo==false){
  243. return error_show(1004,"未找到信息数据");
  244. }
  245. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  246. if($zxorder==false){
  247. return error_show(1004,"未找到咨询信息数据");
  248. }
  249. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  250. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  251. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  252. $zxinfo['khname']="";
  253. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  254. $zxinfo['khNo']="";
  255. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  256. $zxinfo['brand']="";
  257. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  258. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  259. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  260. $zxinfo['company']="";
  261. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  262. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  263. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  264. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  265. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  266. $zxinfo['project_name']="";
  267. $zxinfo['budget_total']="";
  268. $zxinfo['departinfo']=[];
  269. $zxinfo['unit_name']="";
  270. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  271. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  272. if($zxorder['khNo']!==""){
  273. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  274. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  275. $zxinfo['khNo']= $zxorder['khNo'];
  276. }
  277. if($zxinfo['unit']!==""){
  278. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  279. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  280. }
  281. if($zxinfo['brand_id']!==""){
  282. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  283. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  284. }
  285. if($zxorder['companyNo']!==""){
  286. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  287. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  288. }
  289. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  290. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  291. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  292. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  293. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  294. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  295. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  296. }
  297. if($zxorder['depart']>0){
  298. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  299. }
  300. if($zxorder['platform_code']>0){
  301. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  302. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  303. }
  304. return app_show(0,"获取成功",$zxinfo);
  305. }
  306. public function zxedit(){
  307. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  308. if($infoNo==""){
  309. return error_show(1004,"参数infoNo不能为空");
  310. }
  311. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  312. if($zxinfo==false){
  313. return error_show(1004,"未找到信息数据");
  314. }
  315. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  316. if($good_name==""){
  317. return error_show(1003,"参数good_name不能为空");
  318. }
  319. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  320. if($good_img==""){
  321. return error_show(1003,"参数good_img不能为空");
  322. }
  323. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  324. if($cat_id==""){
  325. return error_show(1003,"参数cat_id不能为空");
  326. }
  327. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  328. if($unit==""){
  329. return error_show(1003,"参数unit不能为空");
  330. }
  331. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  332. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  333. if($arrival_time==""){
  334. return error_show(1003,"参数arrival_time不能为空");
  335. }
  336. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  337. if($specin==""){
  338. return error_show(1003,"参数specinfo不能为空");
  339. }
  340. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  341. if($cost_desc==""){
  342. return error_show(1003,"参数cost_desc不能为空");
  343. }
  344. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  345. if($is_addrs===""){
  346. return error_show(1003,"参数is_addrs不能为空");
  347. }
  348. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  349. if($is_custom===""){
  350. return error_show(1003,"参数is_custom不能为空");
  351. }
  352. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  353. if($metal_id===""){
  354. return error_show(1003,"参数metal_id不能为空");
  355. }
  356. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  357. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  358. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  359. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  360. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  361. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  362. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  363. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  364. if($num===""){
  365. return error_show(1003,"参数num不能为空");
  366. }
  367. if($budget_price===""){
  368. return error_show(1003,"参数budget_price不能为空");
  369. }
  370. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  371. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  372. if($use_desc==""){
  373. return error_show(1003,"参数use_desc不能为空");
  374. }
  375. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  376. if($remark==""){
  377. return error_show(1003,"参数remark不能为空");
  378. }
  379. if($metal_id!=0){
  380. if($config==""){
  381. return error_show(1003,"参数config不能为空");
  382. }
  383. if($other_config==""){
  384. return error_show(1003,"参数other_config不能为空");
  385. }
  386. if($specs_weight===""){
  387. return error_show(1003,"参数specs_weight不能为空");
  388. }
  389. if($gold_price===""){
  390. return error_show(1003,"参数gold_price不能为空");
  391. }
  392. }
  393. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  394. if($token==''){
  395. return error_show(102,"参数token不能为空");
  396. }
  397. $user =GetUserInfo($token);
  398. if(empty($user)||$user['code']!=0){
  399. return error_show(105,"用户数据不存在");
  400. }
  401. $specinfo=[];
  402. foreach ($specin as $v){
  403. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  404. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  405. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  406. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  407. $specinfo[]=$v;
  408. }
  409. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  410. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  411. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  412. try{
  413. $innew =makeNo("INF");
  414. $info=[
  415. "infoNo"=>$innew,
  416. "zxNo"=>$zxinfo['zxNo'],
  417. "spuCode"=>"",
  418. "good_name"=>$good_name,
  419. "good_img"=>$good_img,
  420. "cat_id"=>$cat_id,
  421. "unit"=>$unit,
  422. "brand_id"=>$brand_id,
  423. "arrival_time"=>$arrival_time,
  424. "specinfo"=>json_encode($specinfo),
  425. // "color"=>$color,
  426. // "material"=>$material,
  427. "cost_desc"=>$cost_desc,
  428. "is_addrs"=>$is_addrs,
  429. "is_custom"=>$is_custom,
  430. "metal_id"=>$metal_id,
  431. "config"=>$config,
  432. "other_config"=>$other_config,
  433. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  434. "gold_price"=>$gold_price===""? 0 : $gold_price,
  435. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  436. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  437. "budget_price"=>$budget_price,
  438. "num"=>$num,
  439. "pgNo"=>$pgNo,
  440. "use_desc"=>$use_desc,
  441. "remark"=>$remark,
  442. "status"=>1,
  443. "is_del"=>0,
  444. "addtime"=>date("Y-m-d H:i:s"),
  445. "updatetime"=>date("Y-m-d H:i:s")
  446. ];
  447. $up = Db::name("consult_info")->insert($info);
  448. if($up){
  449. if (!empty($bidlist)){
  450. foreach ($bidlist as $value){
  451. unset($value['id']);
  452. $value['infoNo']=$innew;
  453. $value['bidNo']=makeNo("BD");
  454. $value['spuCode']=makeNo("SPU");
  455. $value['status'] =1;
  456. $value['updatetime'] =date("Y-m-d H:i:s");
  457. $in = Db::name("consult_bids")->insert($value);
  458. if($in==false){
  459. Db::rollback();
  460. return error_show(1004,"反馈商品新建失败");
  461. }
  462. }
  463. }
  464. $zxinfo["bargain_status"] =1;
  465. $zxinfo["bargain_code"] =$innew;
  466. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  467. $bar=Db::name("consult_info")->save($zxinfo);
  468. if($bar==false){
  469. Db::rollback();
  470. return error_show(1004,"反馈商品更新失败");
  471. }
  472. Db::commit();
  473. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  474. }
  475. }catch (\Exception $e){
  476. Db::rollback();
  477. return error_show(1004,$e->getMessage());
  478. }
  479. }
  480. //** 发布竞标任务 */
  481. public function bargain(){
  482. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  483. if($infoNo==""){
  484. return error_show(1004,"参数infoNo不能为空");
  485. }
  486. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  487. if($zxinfo==false){
  488. return error_show(1004,"未找到信息数据");
  489. }
  490. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  491. if($status===""){
  492. return error_show(1004,"参数status不能为空");
  493. }
  494. if($status==1&&$zxinfo['status']>1){
  495. $zxinfo['bargain_num']=+1;
  496. }
  497. $zxinfo['status']=$status;
  498. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  499. $up = Db::name("consult_info")->save($zxinfo);
  500. if($up){
  501. return app_show(0,"状态更新成功");
  502. }else{
  503. return error_show(1003,"状态更新失败");
  504. }
  505. }
  506. public function feadback(){
  507. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  508. if($infoNo==""){
  509. return error_show(1002,"参数infoNo不能为空");
  510. }
  511. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  512. if($zxinfo==false){
  513. return error_show(1003,"未找到信息数据");
  514. }
  515. if($zxinfo['status']!=1){
  516. return error_show(1004,"任务未进行");
  517. }
  518. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  519. if($zx==false){
  520. return error_show(1003,"未找咨询信息数据");
  521. }
  522. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  523. if($pname==""){
  524. return error_show(1002,"参数pname不能为空");
  525. }
  526. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  527. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  528. if($cat_id==""){
  529. return error_show(1002,"参数cat_id不能为空");
  530. }
  531. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  532. if($specin==""){
  533. return error_show(1003,"参数specinfo不能为空");
  534. }
  535. $specinfo=[];
  536. foreach ($specin as $v){
  537. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  538. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  539. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  540. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  541. $specinfo[]=$v;
  542. }
  543. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  544. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  545. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  546. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  547. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  548. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  549. :"";
  550. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  551. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  552. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  553. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  554. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  555. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"";
  556. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"";
  557. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  558. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  559. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  560. $good_weight = isset($this->post['good_weight'])&&$this->post['good_weight']!==""? floatval($this->post['good_weight']):"";
  561. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"";
  562. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"";
  563. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"";
  564. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval
  565. ($this->post['pakge_fee']):"";
  566. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"";
  567. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"";
  568. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"";
  569. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"";
  570. if($nake_fee==="" ||$nake_fee==0 ){
  571. return error_show(1004,"参数nake_fee不能为空或零");
  572. }
  573. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  574. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  575. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  576. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  577. if($token==''){
  578. return error_show(1002,"参数token不能为空");
  579. }
  580. $user =GetUserInfo($token);
  581. if(empty($user)||$user['code']!=0){
  582. return error_show(1005,"用户数据不存在");
  583. }
  584. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  585. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  586. $bidNo=makeNo("BD");
  587. $spucode=makeNo("SPU");
  588. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  589. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  590. //部分参数的大小校验
  591. $vali = Validate::rule([
  592. 'expire_day|有效时长'=>'require|elt:214748364',
  593. 'delivery_day|物流时长'=>'require|elt:214748364',
  594. 'work_day|生产工期'=>'require|elt:214748364',
  595. 'weight|总重量'=>'require|max:10',
  596. ]);
  597. $temp = [
  598. 'expire_day'=>$expire_day,
  599. 'delivery_day'=>$delivery_day,
  600. 'work_day'=>$work_day,
  601. 'weight'=>$weight,
  602. ];
  603. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  604. if($is_gold_price==1){
  605. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  606. ->find();
  607. $total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*
  608. $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  609. $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)*
  610. $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  611. }else{
  612. $saleprice = $open_fee/$zxinfo['num'] +
  613. $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee/(1-$budget);
  614. $total_fee = $open_fee/$zxinfo['num'] +
  615. $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  616. }
  617. $data=[
  618. "bidNo"=>$bidNo,
  619. "infoNo"=>$infoNo,
  620. "zxNo"=>$zxinfo['zxNo'],
  621. "spuCode"=>$spucode,
  622. "good_name"=>$pname,
  623. "brand_id"=>$brandid,
  624. "cat_id"=>$cat_id,
  625. "specinfo"=>json_encode($specinfo),
  626. "unit_id"=>$unit_id,
  627. "cost_desc"=>$cost_desc,
  628. "work_day"=>$work_day,
  629. "delivery_day"=>$delivery_day,
  630. "good_img"=>$good_img,
  631. "expire_day"=>$expire_day,
  632. "origin_place"=>$origin_place,
  633. "supplierNo"=>$supplierNo,
  634. "pay_way"=>$pay_way,
  635. "tax"=>$tax,
  636. "send_way"=>$send_way,
  637. "metal_id"=>$metal_id,
  638. "is_gold_price"=>$is_gold_price,
  639. "config"=>$config,
  640. "other_config"=>$other_config,
  641. "weight"=>$weight,
  642. "good_weight"=>$good_weight,
  643. "is_diff"=>$is_diff,
  644. "demo_fee"=>$demo_fee,
  645. "delivery_fee"=>$delivery_fee,
  646. "open_fee"=>$open_fee,
  647. "pakge_fee"=>$pakge_fee,
  648. "nake_fee"=>$nake_fee,
  649. "mark_fee"=>$mark_fee,
  650. "cert_fee"=>$cert_fee,
  651. "cost_fee"=>$cost_fee,
  652. "total_fee"=>$total_fee,
  653. "supply_area"=>$supply_area,
  654. "remark"=>$remark,
  655. "sale_price"=>$saleprice,
  656. "origin_price"=>$saleprice,
  657. "createrid"=>$createrid,
  658. "creater"=>$creater,
  659. "status"=>$zxinfo['status']==1 ?1 :2,
  660. "is_del"=>0,
  661. "addtime"=>date("Y-m-d H:i:s"),
  662. "updatetime"=>date("Y-m-d H:i:s")
  663. ];
  664. Db::startTrans();
  665. try{
  666. $insert= Db::name("consult_bids")->insert($data);
  667. if($insert){
  668. // $data=[
  669. // "spuCode"=>$spucode,
  670. // "good_name"=>$pname,
  671. // "brand_id"=>$brandid,
  672. // "good_unit"=>$unit_id,
  673. // "good_type"=>0,
  674. // "moq"=>1,
  675. // "customized"=>$work_day,
  676. // "tax"=>$tax,
  677. // "supplierNo"=>$supplierNo,
  678. // "is_auth"=>0,
  679. // "craft_desc"=>$cost_desc,
  680. // "good_remark"=>$remark,
  681. // "good_img"=>$good_img,
  682. // "good_thumb_img"=>"",
  683. // "good_info_img"=>"",
  684. // "status"=>1,
  685. // "is_del"=>0,
  686. // "createrid"=>$createrid,
  687. // "creater"=>$creater,
  688. // "addtime"=>date("Y-m-d H:i:s"),
  689. // "updatetime"=>date("Y-m-d H:i:s")
  690. // ];
  691. // $good = Db::name("good_zixun")->insert($data);
  692. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  693. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  694. if($projectinfo==false){
  695. Db::rollback();
  696. return error_show(1006,"未找到项目信息");
  697. }
  698. $temp=[];
  699. $temp['spuCode']=$spucode;
  700. $temp['skuCode']="";
  701. $temp['pgNo']=$zxinfo['pgNo'];
  702. $temp['projectNo']=$zx['projectNo'];
  703. $temp['good_name']=$pname;
  704. $temp['good_type']=$projectinfo['good_type'];
  705. $temp['data_source']=2;
  706. $temp['cat_id']=$cat_id;
  707. $temp['budget_price']=$projectinfo['budget_price'];
  708. $temp['sale_price']=$saleprice;
  709. $temp['origin_price']=$total_fee;
  710. $temp['num']=$zxinfo['num'];
  711. $temp['status']=0;
  712. $temp['is_del']=0;
  713. $temp['creater']=$creater;
  714. $temp['createrid']=$createrid;
  715. $temp['addtime']=date("Y-m-d H:i:s");
  716. $temp['updatetime']=date("Y-m-d H:i:s");
  717. $nu = Db::name("project_feedback")->insert($temp);
  718. if($nu==false){
  719. Db::rollback();
  720. return error_show(1006,"项目反馈失败");
  721. }else{
  722. $projectinfo['status']=2;
  723. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  724. $up = Db::name("project_info")->save($projectinfo);
  725. if($up){
  726. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  727. ->count();
  728. if($count==0){
  729. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  730. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  731. if($proc==false){
  732. Db::rollback();
  733. return error_show(1006,"项目反馈失败");
  734. }
  735. }
  736. }
  737. }
  738. }
  739. Db::commit();
  740. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  741. }else{
  742. Db::rollback();
  743. return error_show(1006,"反馈失败");
  744. }
  745. }catch (\Exception $e){
  746. Db::rollback();
  747. return error_show(1006,$e->getMessage());
  748. }
  749. }
  750. public function feadinfo(){
  751. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  752. if($bidNo==""){
  753. return error_show(1004,"参数bidNo不能为空");
  754. }
  755. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  756. if($info==false){
  757. return error_show(1004,"未找到商品数据");
  758. }
  759. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  760. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  761. $info['cat_info'] = made($info['cat_id'],[]);
  762. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  763. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  764. if($info['brand_id']!=0){
  765. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  766. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  767. }else{
  768. $info["brand_name"]="";
  769. $info["brand_id"]="";
  770. }
  771. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  772. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  773. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  774. $god=[
  775. "metal_id"=>$info['metal_id'],
  776. "weight"=>$info["weight"],
  777. "demo_fee"=>$info["demo_fee"],
  778. "delivery_fee"=>$info["delivery_fee"],
  779. "open_fee"=>$info["open_fee"],
  780. "packing_fee"=>$info["pakge_fee"],
  781. "mark_fee"=>$info["mark_fee"],
  782. "nake_fee"=>$info["nake_fee"],
  783. "cert_fee"=>$info["cert_fee"],
  784. "cost_fee"=>$info["cost_fee"],
  785. "num"=>$bidinfo["num"],
  786. ];
  787. if($info['is_gold_price']==1){
  788. $price = GoldPrice($god, $budget/100);
  789. $info['sale_price'] =round($price,2);
  790. }
  791. $info['specinfo'] = json_decode($info['specinfo'],true);
  792. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  793. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  794. $info['bargain'] =$bargain;
  795. return app_show(0,"获取成功",$info);
  796. }
  797. public function feededit(){
  798. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  799. if($bidNo==""){
  800. return error_show(1002,"参数bidNo不能为空");
  801. }
  802. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  803. if($bidinfo==false){
  804. return error_show(1003,"未找到信息数据");
  805. }
  806. if($bidinfo['status']>=5){
  807. return error_show(1004,"咨询单已确认无法修改");
  808. }
  809. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  810. if($zxinfo==false){
  811. return error_show(1003,"未找到信息数据");
  812. }
  813. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  814. if($zx==false){
  815. return error_show(1003,"未找咨询信息数据");
  816. }
  817. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  818. if($pname==""){
  819. return error_show(1002,"参数pname不能为空");
  820. }
  821. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  822. // if($brandid==""){
  823. // return error_show(1002,"参数brandid不能为空");
  824. // }
  825. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  826. if($cat_id==""){
  827. return error_show(1002,"参数cat_id不能为空");
  828. }
  829. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  830. if($specin==""){
  831. return error_show(1003,"参数specinfo不能为空");
  832. }
  833. $specinfo=[];
  834. foreach ($specin as $v){
  835. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  836. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  837. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  838. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  839. $specinfo[]=$v;
  840. }
  841. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  842. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  843. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  844. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  845. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  846. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  847. :"";
  848. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  849. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  850. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  851. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  852. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  853. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"";
  854. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"";
  855. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  856. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  857. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"";
  858. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"";
  859. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"";
  860. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"";
  861. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"";
  862. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"";
  863. if($nake_fee==="" ||$nake_fee==0 ){
  864. return error_show(1004,"参数nake_fee不能为空或零");
  865. }
  866. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"";
  867. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"";
  868. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"";
  869. $total_fee = isset($this->post['total_fee'])&&$this->post['total_fee']!=""? floatval($this->post['total_fee']):"";
  870. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  871. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  872. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  873. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  874. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  875. if($is_gold_price==1){
  876. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  877. ->find();
  878. $total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*
  879. $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  880. $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)*
  881. $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  882. }else{
  883. $saleprice = $open_fee/$zxinfo['num'] +
  884. $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee/(1-$budget);
  885. $total_fee = $open_fee/$zxinfo['num'] +
  886. $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  887. }
  888. Db::startTrans();
  889. try{
  890. $data=[
  891. "good_name"=>$pname,
  892. "brand_id"=>$brandid,
  893. "cat_id"=>$cat_id,
  894. "specinfo"=>json_encode($specinfo),
  895. // "material"=>$material,
  896. "unit_id"=>$unit_id,
  897. "cost_desc"=>$cost_desc,
  898. "work_day"=>$work_day,
  899. "delivery_day"=>$delivery_day,
  900. "good_img"=>$good_img,
  901. "expire_day"=>$expire_day,
  902. "origin_place"=>$origin_place,
  903. "supplierNo"=>$supplierNo,
  904. "pay_way"=>$pay_way,
  905. "tax"=>$tax,
  906. "send_way"=>$send_way,
  907. "metal_id"=>$metal_id,
  908. "is_gold_price"=>$is_gold_price,
  909. "config"=>$config,
  910. "other_config"=>$other_config,
  911. "weight"=>$weight,
  912. "is_diff"=>$is_diff,
  913. "demo_fee"=>$demo_fee,
  914. "delivery_fee"=>$delivery_fee,
  915. "open_fee"=>$open_fee,
  916. "pakge_fee"=>$pakge_fee,
  917. "nake_fee"=>$nake_fee,
  918. "mark_fee"=>$mark_fee,
  919. "cert_fee"=>$cert_fee,
  920. "cost_fee"=>$cost_fee,
  921. "total_fee"=>$total_fee,
  922. "sale_price"=>$saleprice,
  923. "supply_area"=>$supply_area,
  924. "remark"=>$remark,
  925. "updatetime"=>date("Y-m-d H:i:s")
  926. ];
  927. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  928. if($insert){
  929. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  930. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  931. if($projectinfo==false){
  932. Db::rollback();
  933. return error_show(1006,"未找到项目信息");
  934. }
  935. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  936. if($feed==false){
  937. Db::rollback();
  938. return error_show(1006,"未找到项目反馈信息");
  939. }
  940. $feed['good_name']=$pname;
  941. $feed['good_type']=$projectinfo['good_type'];
  942. $feed['cat_id']=$cat_id;
  943. $feed['sale_price']=$saleprice;
  944. $feed['origin_price']=$total_fee;
  945. $temp['updatetime']=date("Y-m-d H:i:s");
  946. $nu = Db::name("project_feedback")->save($feed);
  947. if($nu==false){
  948. Db::rollback();
  949. return error_show(1006,"项目反馈失败");
  950. }else{
  951. $projectinfo['status']=2;
  952. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  953. $up = Db::name("project_info")->save($projectinfo);
  954. if($up){
  955. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  956. ->count();
  957. if($count==0){
  958. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  959. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  960. if($proc==false){
  961. Db::rollback();
  962. return error_show(1006,"项目反馈失败");
  963. }
  964. }
  965. }
  966. }
  967. }
  968. Db::commit();
  969. return app_show(0,"编辑成功");
  970. }else{
  971. Db::rollback();
  972. return error_show(1004,"编辑失败");
  973. }
  974. }catch (\Exception $e){
  975. Db::rollback();
  976. return error_show(1004,$e->getMessage());
  977. }
  978. }
  979. public function bargain_add(){
  980. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  981. if($bidNo===""){
  982. return error_show(1004,"参数bidNo不能为空");
  983. }
  984. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  985. if($info==false){
  986. return error_show(1004,"未找到商品数据");
  987. }
  988. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  989. if($bargain_price===""){
  990. return error_show(1004,"参数bargain_price不能为空");
  991. }
  992. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  993. // if($bargain_reason===""){
  994. // return error_show(1004,"参数bargain_reason不能为空");
  995. // }
  996. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  997. if($infos==false){
  998. return error_show(1004,"未找到商品数据");
  999. }
  1000. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1001. return error_show(1004,"咨询单招标未结束或已确认商品");
  1002. }
  1003. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1004. if($token==''){
  1005. return error_show(105,"参数token不能为空");
  1006. }
  1007. $user =GetUserInfo($token);
  1008. if(empty($user)||$user['code']!=0){
  1009. return error_show(1002,"用户数据不存在");
  1010. }
  1011. //新增两个字段
  1012. //议价备注
  1013. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1014. //议价原因id
  1015. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1016. if ($result_info_id != '') {
  1017. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1018. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1019. }
  1020. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1021. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1022. $bargainNo =makeNo("BA");
  1023. Db::startTrans();//::todo 金价 毛利计算
  1024. try{
  1025. $data=[
  1026. "bidsNo"=>$bidNo,
  1027. "infoNo"=>$info['infoNo'],
  1028. "zxNo"=>$info['zxNo'],
  1029. "bargainNo"=>$bargainNo,
  1030. "bargain_type"=>1,
  1031. "bargain_reason"=>$bargain_reason,
  1032. "sale_price"=>$info['sale_price'],
  1033. "cost_before_price"=>$info['cost_fee'],
  1034. "cost_after_price"=>$info['cost_fee'],
  1035. "before_rate"=>$info['cost_fee'],
  1036. "after_rate"=>$info['cost_fee'],
  1037. "after_price"=>$bargain_price,
  1038. "exam_info"=>"",
  1039. "status"=>1,
  1040. "is_del"=>0,
  1041. "creater"=>$creater,
  1042. "createrid"=>$createrid,
  1043. "addtime"=>date("Y-m-d H:i:s"),
  1044. "updatetime"=>date("Y-m-d H:i:s"),
  1045. 'bargain_remark'=>$bargain_remark,
  1046. 'result_info_id'=>$result_info_id,
  1047. ];
  1048. $int = Db::name("bargain_order")->insert($data);
  1049. if($int){
  1050. $info['status']=3;
  1051. $info['updatetime']=date("Y-m-d H:i:s");
  1052. $up =Db::name("consult_bids")->save($info);
  1053. if($up){
  1054. $infos['status']=3;
  1055. $infos['updatetime']=date("Y-m-d H:i:s");
  1056. $ups =Db::name("consult_info")->save($infos);
  1057. if($ups){
  1058. Db::commit();
  1059. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1060. }
  1061. }
  1062. }
  1063. Db::rollback();
  1064. return error_show(1004,"议价单新建失败");
  1065. }catch (\Exception $e){
  1066. Db::rollback();
  1067. return error_show(1004,$e->getMessage());
  1068. }
  1069. }
  1070. public function bids_check(){
  1071. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1072. if($bidNo===""){
  1073. return error_show(1004,"参数bidNo不能为空");
  1074. }
  1075. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1076. if($info==false){
  1077. return error_show(1004,"未找到商品数据");
  1078. }
  1079. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1080. if($infos==false){
  1081. return error_show(1004,"未找到商品数据");
  1082. }
  1083. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1084. return error_show(1004,"咨询单招标未结束或已确认商品");
  1085. }
  1086. Db::startTrans();
  1087. try {
  1088. $info['status']=6;
  1089. $info['updatetime']=date("Y-m-d H:i:s");
  1090. $bids = Db::name("consult_bids")->save($info);
  1091. if($bids){
  1092. $infos['status']=4;
  1093. $infos['updatetime']=date("Y-m-d H:i:s");
  1094. $se = Db::name("consult_info")->save($infos);
  1095. if($se){
  1096. Db::commit();
  1097. return app_show(0,"商品确定成功");
  1098. }
  1099. }
  1100. Db::rollback();
  1101. return error_show(1004,"商品确认失败");
  1102. }catch (\Exception $e){
  1103. Db::rollback();
  1104. return error_show(1004,$e->getMessage());
  1105. }
  1106. }
  1107. public function bargain_status(){
  1108. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1109. if($bargainNo===""){
  1110. return error_show(1004,"参数bargainNo不能为空");
  1111. }
  1112. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1113. if($info==false){
  1114. return error_show(1004,"未找到议价数据");
  1115. }
  1116. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1117. if($bids==false){
  1118. return error_show(1004,"未找到商品数据");
  1119. }
  1120. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1121. if($coninfo==false){
  1122. return error_show(1004,"未找到咨询单数据");
  1123. }
  1124. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1125. if($status==''){
  1126. return error_show(1005,"参数status不能为空");
  1127. }
  1128. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1129. // if($remark==""){
  1130. // return error_show(1004,"参数remark不能为空");
  1131. // }
  1132. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1133. if($token==''){
  1134. return error_show(105,"参数token不能为空");
  1135. }
  1136. $user =GetUserInfo($token);
  1137. if(empty($user)||$user['code']!=0){
  1138. return error_show(1002,"用户数据不存在");
  1139. }
  1140. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1141. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1142. Db::startTrans();
  1143. try{
  1144. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1145. $examinfo[]=["status"=>$status,"remark"=>$remark,"createrid"=>$createrid,"creater"=>$creater];
  1146. $info['status'] =$status;
  1147. $info['remark'] =$remark;
  1148. $info['exam_info']=json_encode($examinfo) ;
  1149. $info['updatetime'] =date("Y-m-d H:i:s");
  1150. $up =Db::name("bargain_order")->save($info);
  1151. if($up){
  1152. if($status==4||$status==5||$status==6||$status==7){
  1153. $bids['status']=5;
  1154. if($status==4){
  1155. $bids['sale_price']=$info['after_price'];
  1156. }
  1157. $bids['updatetime']=date("Y-m-d H:i:s");
  1158. $up =Db::name("consult_bids")->save($bids);
  1159. if($up==false){
  1160. Db::rollback();
  1161. return error_show(1004,"数据更新失败");
  1162. }
  1163. }
  1164. Db::commit();
  1165. return app_show(0,"更新成功");
  1166. }
  1167. }catch (\Exception $e){
  1168. Db::rollback();
  1169. return error_show(1004,$e->getMessage());
  1170. }
  1171. }
  1172. public function bargain_info(){
  1173. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1174. if($bargainNo===""){
  1175. return error_show(1004,"参数bargainNo不能为空");
  1176. }
  1177. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1178. if($info==false){
  1179. return error_show(1004,"未找到议价数据");
  1180. }
  1181. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1182. if($bidinfos==false){
  1183. return error_show(1004,"未找到商品数据");
  1184. }
  1185. $consultinfos = Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])
  1186. ->find();
  1187. if($consultinfos==false){
  1188. return error_show(1004,"未找到咨询商品数据");
  1189. }
  1190. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1191. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1192. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1193. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1194. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1195. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_encode($info['exam_info']):"";
  1196. if($bidinfos['brand_id']!=0){
  1197. $info['brand_id'] = $bidinfos['brand_id'];
  1198. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1199. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1200. }else{
  1201. $info["brand_name"]="";
  1202. $info["brand_id"]="";
  1203. }
  1204. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1205. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1206. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1207. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1208. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1209. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1210. $info['budget'] =$budget;
  1211. $god=[
  1212. "metal_id"=>$bidinfos['metal_id'],
  1213. "weight"=>$bidinfos["weight"],
  1214. "demo_fee"=>$bidinfos["demo_fee"],
  1215. "delivery_fee"=>$bidinfos["delivery_fee"],
  1216. "open_fee"=>$bidinfos["open_fee"],
  1217. "packing_fee"=>$bidinfos["pakge_fee"],
  1218. "mark_fee"=>$bidinfos["mark_fee"],
  1219. "nake_fee"=>$bidinfos["nake_fee"],
  1220. "cert_fee"=>$bidinfos["cert_fee"],
  1221. "cost_fee"=>$bidinfos["cost_fee"],
  1222. "num"=>$bidinfoe["num"],
  1223. ];
  1224. $info['gold_price']=0;
  1225. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1226. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1227. ->find();
  1228. $info['gold_price'] =$gold['price'];
  1229. }
  1230. $info['cost_desc'] =$bidinfos['cost_desc'];
  1231. $info['work_day'] =$bidinfos['work_day'];
  1232. $info['delivery_day'] =$bidinfos['delivery_day'];
  1233. $info['expire_day'] =$bidinfos['expire_day'];
  1234. $info['origin_place'] =$bidinfos['origin_place'];
  1235. $info['origin_addr'] ="";
  1236. if($bidinfos['origin_place']!=''){
  1237. $code = explode(",",$bidinfos['origin_place']);
  1238. $temp=[];
  1239. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1240. $temp['city_code']=isset($code[1])?$code[1]:"";
  1241. $temp['area_code']=isset($code[2])?$code[2]:"";
  1242. $addr= GetAddr(json_encode($temp));
  1243. $info['origin_addr'] = $addr;
  1244. }
  1245. $info['supplierNo'] =$bidinfos['supplierNo'];
  1246. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1247. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1248. $info['pay_way'] =$bidinfos['pay_way'];
  1249. $info['tax'] =$bidinfos['tax'];
  1250. $info['send_way'] =$bidinfos['send_way'];
  1251. $info['metal_id'] =$bidinfos['metal_id'];
  1252. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1253. $info['config'] =$bidinfos['config'];
  1254. $info['other_config'] =$bidinfos['other_config'];
  1255. $info['weight'] =$bidinfos['weight'];
  1256. $info['is_diff'] =$bidinfos['is_diff'];
  1257. $info['demo_fee'] =$bidinfos['demo_fee'];
  1258. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1259. $info['open_fee'] =$bidinfos['open_fee'];
  1260. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1261. $info['nake_fee'] =$bidinfos['nake_fee'];
  1262. $info['mark_fee'] =$bidinfos['mark_fee'];
  1263. $info['cert_fee'] =$bidinfos['cert_fee'];
  1264. $info['cost_fee'] =$bidinfos['cost_fee'];
  1265. $info['total_fee'] =$bidinfos['total_fee'];
  1266. $info['supply_area'] =$bidinfos['supply_area'];
  1267. $info['remark'] =$bidinfos['remark'];
  1268. $info['is_addrs'] =$consultinfos['is_addrs'];
  1269. $info['is_custom'] =$consultinfos['is_custom'];
  1270. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1271. $info['sale_price'] =round($bidinfos['sale_price'],2);
  1272. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1273. //获取议价原因
  1274. if ($info['result_info_id'] != 0) {
  1275. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1276. } else {
  1277. $info['result_info'] = '';
  1278. }
  1279. return app_show(0,"获取成功",$info);
  1280. }
  1281. public function bidlist(){
  1282. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1283. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1284. $where=[['is_del',"=",0]];
  1285. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1286. if ($zxNo !== "") {
  1287. $where[] = ['zxNo','=',$zxNo];
  1288. }
  1289. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1290. if ($infoNo !== "") {
  1291. $where[] = ['infoNo','=',$infoNo];
  1292. }
  1293. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1294. if ($bidNo !== "") {
  1295. $where[] = ['bidNo','=',$bidNo];
  1296. }
  1297. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1298. if ($pgNo !== "") {
  1299. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1300. $where[] = ['infoNo','in',$bidinfo];
  1301. }
  1302. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1303. if ($bargain_status !== "") {
  1304. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1305. $where[] = ['infoNo','in',$bidinfo];
  1306. }
  1307. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1308. if ($projectNo !== "") {
  1309. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1310. ("zxNo");
  1311. $where[] = ['zxNo','in',$zxlist];
  1312. }
  1313. $count = Db::name('consult_bids')->where($where)->count();
  1314. $total = ceil($count / $size);
  1315. $page = $page >= $total ? $total : $page;
  1316. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select();
  1317. $data=[];
  1318. foreach ($list as $value){
  1319. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1320. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1321. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1322. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1323. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1324. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1325. if($value['brand_id']!=0){
  1326. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1327. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1328. }else{
  1329. $value["brand_name"]="";
  1330. $value["brand_id"]="";
  1331. }
  1332. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1333. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1334. $god=[
  1335. "metal_id"=>$value['metal_id'],
  1336. "weight"=>$value["weight"],
  1337. "demo_fee"=>$value["demo_fee"],
  1338. "delivery_fee"=>$value["delivery_fee"],
  1339. "open_fee"=>$value["open_fee"],
  1340. "packing_fee"=>$value["pakge_fee"],
  1341. "mark_fee"=>$value["mark_fee"],
  1342. "nake_fee"=>$value["nake_fee"],
  1343. "cert_fee"=>$value["cert_fee"],
  1344. "cost_fee"=>$value["cost_fee"],
  1345. "num"=>$bidinfo["num"],
  1346. ];
  1347. if($value['is_gold_price']==1){
  1348. $price = GoldPrice($god, $budget/100);
  1349. $value['sale_price'] = round($price,2);
  1350. }
  1351. $value['specinfo'] = json_decode($value['specinfo'],true);
  1352. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1353. $value['bargain_status']=$bidinfo['bargain_status'];
  1354. $data[]=$value;
  1355. }
  1356. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1357. }
  1358. public function feedlist(){
  1359. $where=[['is_del',"=",0]];
  1360. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1361. if ($zxNo !== "") {
  1362. $where[] = ['zxNo','=',$zxNo];
  1363. }
  1364. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1365. if ($infoNo !== "") {
  1366. $where[] = ['infoNo','=',$infoNo];
  1367. }
  1368. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1369. if ($bidNo !== "") {
  1370. $where[] = ['bidNo','=',$bidNo];
  1371. }
  1372. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1373. if ($projectNo !== "") {
  1374. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1375. ("zxNo");
  1376. $where[] = ['zxNo','in',$zxlist];
  1377. }
  1378. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1379. if($token==''){
  1380. return error_show(102,"参数token不能为空");
  1381. }
  1382. $user =GetUserInfo($token);
  1383. if(empty($user)||$user['code']!=0){
  1384. return error_show(105,"用户数据不存在");
  1385. }
  1386. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1387. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1388. $where[] = ["createrid","=",$createrid];
  1389. $list =Db::name('consult_bids')->where($where)->select();
  1390. $data=[];
  1391. foreach ($list as $value){
  1392. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1393. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1394. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1395. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1396. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1397. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1398. if($value['brand_id']!=0){
  1399. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1400. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1401. }else{
  1402. $value["brand_name"]="";
  1403. $value["brand_id"]="";
  1404. }
  1405. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1406. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1407. $god=[
  1408. "metal_id"=>$value['metal_id'],
  1409. "weight"=>$value["weight"],
  1410. "demo_fee"=>$value["demo_fee"],
  1411. "delivery_fee"=>$value["delivery_fee"],
  1412. "open_fee"=>$value["open_fee"],
  1413. "packing_fee"=>$value["pakge_fee"],
  1414. "mark_fee"=>$value["mark_fee"],
  1415. "nake_fee"=>$value["nake_fee"],
  1416. "cert_fee"=>$value["cert_fee"],
  1417. "cost_fee"=>$value["cost_fee"],
  1418. "num"=>$bidinfo["num"],
  1419. ];
  1420. if($value['is_gold_price']==1){
  1421. $price = GoldPrice($god, $budget/100);
  1422. $value['sale_price'] =round($price,2);
  1423. }
  1424. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1425. $value['specinfo'] = json_decode($value['specinfo'],true);
  1426. $value['bargain_status']=$bidinfo['bargain_status'];
  1427. $data[]=$value;
  1428. }
  1429. return app_show(0,"获取成功",$data);
  1430. }
  1431. public function bragain_list(){
  1432. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1433. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1434. $where=[['is_del',"=",0]];
  1435. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1436. if($bidsNo!=""){
  1437. $where[]=["bidsNo","=",$bidsNo];
  1438. }
  1439. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1440. if ($zxNo !== "") {
  1441. $where[] = ['zxNo','=',$zxNo];
  1442. }
  1443. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1444. if ($infoNo !== "") {
  1445. $where[] = ['infoNo','=',$infoNo];
  1446. }
  1447. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1448. if ($projectNo !== "") {
  1449. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1450. ("zxNo");
  1451. $where[] = ['zxNo','in',$zxlist];
  1452. }
  1453. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1454. if ($pgNo !== "") {
  1455. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1456. $where[] = ['infoNo','in',$bidinfo];
  1457. }
  1458. $count=Db::name("bargain_order")->where($where)->count();
  1459. $total = ceil($count / $size);
  1460. $page = $page >= $total ? $total : $page;
  1461. $list =Db::name('bargain_order')->where($where)->page($page,$size)->order('addtime','desc')->select();
  1462. $data=[];
  1463. foreach ($list as $value){
  1464. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1465. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1466. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1467. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1468. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1469. if($bidinfos['brand_id']!=0){
  1470. $value['brand_id'] = $bidinfos['brand_id'];
  1471. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1472. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1473. }else{
  1474. $value["brand_name"]="";
  1475. $value["brand_id"]="";
  1476. }
  1477. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1478. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1479. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1480. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1481. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1482. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1483. $value['budget'] =$budget;
  1484. $god=[
  1485. "metal_id"=>$bidinfos['metal_id'],
  1486. "weight"=>$bidinfos["weight"],
  1487. "demo_fee"=>$bidinfos["demo_fee"],
  1488. "delivery_fee"=>$bidinfos["delivery_fee"],
  1489. "open_fee"=>$bidinfos["open_fee"],
  1490. "packing_fee"=>$bidinfos["pakge_fee"],
  1491. "mark_fee"=>$bidinfos["mark_fee"],
  1492. "nake_fee"=>$bidinfos["nake_fee"],
  1493. "cert_fee"=>$bidinfos["cert_fee"],
  1494. "cost_fee"=>$bidinfos["cost_fee"],
  1495. "num"=>$bidinfoe["num"],
  1496. ];
  1497. // if($bidinfos['is_gold_price']==1){
  1498. // $price = GoldPrice($god, $budget/100);
  1499. // }else{
  1500. // $price = GoodPrice($god, $budget/100);
  1501. // }
  1502. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1503. $value['sale_price'] =round($bidinfos['sale_price'],2);
  1504. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1505. $data[]=$value;
  1506. }
  1507. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  1508. }
  1509. public function crontablist(){
  1510. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1511. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1512. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  1513. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1514. if ($zxNo !== "") {
  1515. $where[] = ['a.zxNo','=',$zxNo];
  1516. }
  1517. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  1518. if ($salesman !== "") {
  1519. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  1520. $where[]= ["b.salesman",'like',"%$salesman%"];
  1521. }
  1522. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  1523. if ($cpName !== "") {
  1524. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  1525. $where[]= ["a.good_Name",'like',"%$cpName%"];
  1526. }
  1527. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  1528. if ($khNo !== "") {
  1529. // $where['khNo'] = $khNo;
  1530. $where[]= ["b.khNo",'like',"%$khNo%"];
  1531. }
  1532. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  1533. if ($start !="") {
  1534. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  1535. $where[]= ["a.addtime",'>=',$start];
  1536. }
  1537. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  1538. if($end !=""){
  1539. $where[]= ["a.addtime",'<=',$end];
  1540. }
  1541. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  1542. if ($status !== "") {
  1543. $where[]= ["a.status",'=',$status];
  1544. }
  1545. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  1546. ->count();
  1547. $total = ceil($count / $size);
  1548. $page = $page >= $total ? $total : $page;
  1549. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  1550. ->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();
  1551. $data=[];
  1552. foreach ($list as $value){
  1553. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1554. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  1555. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  1556. $value['khname']="";
  1557. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  1558. true):[];
  1559. if($value['khNo']!==""){
  1560. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  1561. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  1562. }
  1563. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1564. $data[]=$value;
  1565. }
  1566. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1567. }
  1568. }