Consult.php 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628
  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("IF");
  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. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  380. if($endtime==""){
  381. return error_show(1003,"参数endtime不能为空");
  382. }
  383. if($metal_id!=0){
  384. if($config==""){
  385. return error_show(1003,"参数config不能为空");
  386. }
  387. if($other_config==""){
  388. return error_show(1003,"参数other_config不能为空");
  389. }
  390. if($specs_weight===""){
  391. return error_show(1003,"参数specs_weight不能为空");
  392. }
  393. if($gold_price===""){
  394. return error_show(1003,"参数gold_price不能为空");
  395. }
  396. }
  397. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  398. if($token==''){
  399. return error_show(102,"参数token不能为空");
  400. }
  401. $user =GetUserInfo($token);
  402. if(empty($user)||$user['code']!=0){
  403. return error_show(105,"用户数据不存在");
  404. }
  405. $specinfo=[];
  406. foreach ($specin as $v){
  407. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  408. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  409. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  410. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  411. $specinfo[]=$v;
  412. }
  413. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  414. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  415. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  416. Db::startTrans();
  417. try{
  418. $innew =makeNo("IF");
  419. $info=[
  420. "infoNo"=>$innew,
  421. "zxNo"=>$zxinfo['zxNo'],
  422. "spuCode"=>"",
  423. "good_name"=>$good_name,
  424. "good_img"=>$good_img,
  425. "cat_id"=>$cat_id,
  426. "unit"=>$unit,
  427. "brand_id"=>$brand_id,
  428. "arrival_time"=>$arrival_time,
  429. "specinfo"=>json_encode($specinfo),
  430. // "color"=>$color,
  431. // "material"=>$material,
  432. "cost_desc"=>$cost_desc,
  433. "is_addrs"=>$is_addrs,
  434. "is_custom"=>$is_custom,
  435. "metal_id"=>$metal_id,
  436. "config"=>$config,
  437. "other_config"=>$other_config,
  438. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  439. "gold_price"=>$gold_price===""? 0 : $gold_price,
  440. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  441. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  442. "budget_price"=>$budget_price,
  443. "num"=>$num,
  444. "pgNo"=>$pgNo,
  445. "use_desc"=>$use_desc,
  446. "remark"=>$remark,
  447. "status"=>1,
  448. "is_del"=>0,
  449. "addtime"=>date("Y-m-d H:i:s"),
  450. "updatetime"=>date("Y-m-d H:i:s"),
  451. 'bargain_status'=>1
  452. ];
  453. $up = Db::name("consult_info")->insert($info);
  454. if($up){
  455. if (!empty($bidlist)){
  456. foreach ($bidlist as $value){
  457. unset($value['id']);
  458. $value['infoNo']=$innew;
  459. $value['bidNo']=makeNo("BD");
  460. $value['spuCode']=makeNo("SKU");
  461. $value['status'] =0;
  462. $value['updatetime'] =date("Y-m-d H:i:s");
  463. $in = Db::name("consult_bids")->insert($value);
  464. if($in==false){
  465. Db::rollback();
  466. return error_show(1004,"反馈商品新建失败");
  467. }
  468. }
  469. }
  470. $zxinfo["bargain_status"] =1;
  471. $zxinfo["bargain_code"] =$innew;
  472. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  473. $bar=Db::name("consult_info")->save($zxinfo);
  474. if($bar==false){
  475. Db::rollback();
  476. return error_show(1004,"反馈商品更新失败");
  477. }
  478. //更新consule_order记录
  479. Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,'updatetime'=>date('Y-m-d H:i:s')]);
  480. Db::commit();
  481. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  482. }
  483. }catch (\Exception $e){
  484. Db::rollback();
  485. return error_show(1004,$e->getMessage());
  486. }
  487. }
  488. //** 发布竞标任务 */
  489. public function bargain(){
  490. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  491. if($infoNo==""){
  492. return error_show(1004,"参数infoNo不能为空");
  493. }
  494. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  495. if($zxinfo==false){
  496. return error_show(1004,"未找到信息数据");
  497. }
  498. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  499. if($status===""){
  500. return error_show(1004,"参数status不能为空");
  501. }
  502. if($status==1&&$zxinfo['status']>1){
  503. $zxinfo['bargain_num']=+1;
  504. }
  505. $zxinfo['status']=$status;
  506. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  507. $up = Db::name("consult_info")->save($zxinfo);
  508. if($up){
  509. return app_show(0,"状态更新成功");
  510. }else{
  511. return error_show(1003,"状态更新失败");
  512. }
  513. }
  514. public function feadback(){
  515. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  516. if($infoNo==""){
  517. return error_show(1002,"参数infoNo不能为空");
  518. }
  519. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  520. if($zxinfo==false){
  521. return error_show(1003,"未找到信息数据");
  522. }
  523. if($zxinfo['status']!=1){
  524. return error_show(1004,"任务未进行");
  525. }
  526. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  527. if($zx==false){
  528. return error_show(1003,"未找咨询信息数据");
  529. }
  530. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  531. if($pname==""){
  532. return error_show(1002,"参数pname不能为空");
  533. }
  534. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  535. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  536. if($cat_id==""){
  537. return error_show(1002,"参数cat_id不能为空");
  538. }
  539. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  540. if($specin==""){
  541. return error_show(1003,"参数specinfo不能为空");
  542. }
  543. $specinfo=[];
  544. foreach ($specin as $v){
  545. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  546. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  547. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  548. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  549. $specinfo[]=$v;
  550. }
  551. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  552. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  553. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  554. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  555. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  556. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  557. :"";
  558. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  559. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  560. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  561. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  562. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  563. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"";
  564. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"";
  565. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  566. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  567. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  568. $good_weight = isset($this->post['good_weight'])&&$this->post['good_weight']!==""? floatval($this->post['good_weight']):"";
  569. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"";
  570. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"";
  571. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"";
  572. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval
  573. ($this->post['pakge_fee']):"";
  574. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"";
  575. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"";
  576. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"";
  577. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"";
  578. if($nake_fee==="" ||$nake_fee==0 ){
  579. return error_show(1004,"参数nake_fee不能为空或零");
  580. }
  581. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  582. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  583. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  584. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  585. if($token==''){
  586. return error_show(1002,"参数token不能为空");
  587. }
  588. $user =GetUserInfo($token);
  589. if(empty($user)||$user['code']!=0){
  590. return error_show(1005,"用户数据不存在");
  591. }
  592. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  593. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  594. $bidNo=makeNo("BD");
  595. $spucode=makeNo("SKU");
  596. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  597. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  598. //部分参数的大小校验
  599. $vali = Validate::rule([
  600. 'expire_day|有效时长'=>'require|elt:214748364',
  601. 'delivery_day|物流时长'=>'require|elt:214748364',
  602. 'work_day|生产工期'=>'require|elt:214748364',
  603. 'weight|总重量'=>'require|max:10',
  604. ]);
  605. $temp = [
  606. 'expire_day'=>$expire_day,
  607. 'delivery_day'=>$delivery_day,
  608. 'work_day'=>$work_day,
  609. 'weight'=>$weight,
  610. ];
  611. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  612. if($is_gold_price==1){
  613. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  614. ->find();
  615. $total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*
  616. $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  617. $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)*
  618. $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  619. }else{
  620. $saleprice = $open_fee/$zxinfo['num'] +
  621. $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee/(1-$budget);
  622. $total_fee = $open_fee/$zxinfo['num'] +
  623. $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  624. }
  625. $data=[
  626. "bidNo"=>$bidNo,
  627. "infoNo"=>$infoNo,
  628. "zxNo"=>$zxinfo['zxNo'],
  629. "spuCode"=>$spucode,
  630. "good_name"=>$pname,
  631. "brand_id"=>$brandid,
  632. "cat_id"=>$cat_id,
  633. "specinfo"=>json_encode($specinfo),
  634. "unit_id"=>$unit_id,
  635. "cost_desc"=>$cost_desc,
  636. "work_day"=>$work_day,
  637. "delivery_day"=>$delivery_day,
  638. "good_img"=>$good_img,
  639. "expire_day"=>$expire_day,
  640. "origin_place"=>$origin_place,
  641. "supplierNo"=>$supplierNo,
  642. "pay_way"=>$pay_way,
  643. "tax"=>$tax,
  644. "send_way"=>$send_way,
  645. "metal_id"=>$metal_id,
  646. "is_gold_price"=>$is_gold_price,
  647. "config"=>$config,
  648. "other_config"=>$other_config,
  649. "weight"=>$weight,
  650. "good_weight"=>$good_weight,
  651. "is_diff"=>$is_diff,
  652. "demo_fee"=>$demo_fee,
  653. "delivery_fee"=>$delivery_fee,
  654. "open_fee"=>$open_fee,
  655. "pakge_fee"=>$pakge_fee,
  656. "nake_fee"=>$nake_fee,
  657. "mark_fee"=>$mark_fee,
  658. "cert_fee"=>$cert_fee,
  659. "cost_fee"=>$cost_fee,
  660. "total_fee"=>$total_fee,
  661. "supply_area"=>$supply_area,
  662. "remark"=>$remark,
  663. "sale_price"=>$saleprice,
  664. "origin_price"=>$saleprice,
  665. "createrid"=>$createrid,
  666. "creater"=>$creater,
  667. "status"=>$zxinfo['status']==1 ?1 :2,
  668. "is_del"=>0,
  669. "addtime"=>date("Y-m-d H:i:s"),
  670. "updatetime"=>date("Y-m-d H:i:s")
  671. ];
  672. Db::startTrans();
  673. try{
  674. $insert= Db::name("consult_bids")->insert($data);
  675. if($insert){
  676. // $data=[
  677. // "spuCode"=>$spucode,
  678. // "good_name"=>$pname,
  679. // "brand_id"=>$brandid,
  680. // "good_unit"=>$unit_id,
  681. // "good_type"=>0,
  682. // "moq"=>1,
  683. // "customized"=>$work_day,
  684. // "tax"=>$tax,
  685. // "supplierNo"=>$supplierNo,
  686. // "is_auth"=>0,
  687. // "craft_desc"=>$cost_desc,
  688. // "good_remark"=>$remark,
  689. // "good_img"=>$good_img,
  690. // "good_thumb_img"=>"",
  691. // "good_info_img"=>"",
  692. // "status"=>1,
  693. // "is_del"=>0,
  694. // "createrid"=>$createrid,
  695. // "creater"=>$creater,
  696. // "addtime"=>date("Y-m-d H:i:s"),
  697. // "updatetime"=>date("Y-m-d H:i:s")
  698. // ];
  699. // $good = Db::name("good_zixun")->insert($data);
  700. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  701. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  702. if($projectinfo==false){
  703. Db::rollback();
  704. return error_show(1006,"未找到项目信息");
  705. }
  706. $temp=[];
  707. $temp['spuCode']=$spucode;
  708. $temp['skuCode']="";
  709. $temp['pgNo']=$zxinfo['pgNo'];
  710. $temp['projectNo']=$zx['projectNo'];
  711. $temp['good_name']=$pname;
  712. $temp['good_type']=$projectinfo['good_type'];
  713. $temp['data_source']=2;
  714. $temp['cat_id']=$cat_id;
  715. $temp['budget_price']=$projectinfo['budget_price'];
  716. $temp['sale_price']=$saleprice;
  717. $temp['origin_price']=$total_fee;
  718. $temp['num']=$zxinfo['num'];
  719. $temp['status']=0;
  720. $temp['is_del']=0;
  721. $temp['creater']=$creater;
  722. $temp['createrid']=$createrid;
  723. $temp['addtime']=date("Y-m-d H:i:s");
  724. $temp['updatetime']=date("Y-m-d H:i:s");
  725. $nu = Db::name("project_feedback")->insert($temp);
  726. if($nu==false){
  727. Db::rollback();
  728. return error_show(1006,"项目反馈失败");
  729. }else{
  730. $projectinfo['status']=2;
  731. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  732. $up = Db::name("project_info")->save($projectinfo);
  733. if($up){
  734. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  735. ->count();
  736. if($count==0){
  737. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  738. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  739. if($proc==false){
  740. Db::rollback();
  741. return error_show(1006,"项目反馈失败");
  742. }
  743. }
  744. }
  745. }
  746. }
  747. Db::commit();
  748. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  749. }else{
  750. Db::rollback();
  751. return error_show(1006,"反馈失败");
  752. }
  753. }catch (\Exception $e){
  754. Db::rollback();
  755. return error_show(1006,$e->getMessage());
  756. }
  757. }
  758. public function feadinfo(){
  759. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  760. if($bidNo==""){
  761. return error_show(1004,"参数bidNo不能为空");
  762. }
  763. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  764. if($info==false){
  765. return error_show(1004,"未找到商品数据");
  766. }
  767. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  768. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  769. $info['cat_info'] = made($info['cat_id'],[]);
  770. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  771. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  772. if($info['brand_id']!=0){
  773. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  774. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  775. }else{
  776. $info["brand_name"]="";
  777. $info["brand_id"]="";
  778. }
  779. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  780. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  781. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  782. $god=[
  783. "metal_id"=>$info['metal_id'],
  784. "weight"=>$info["weight"],
  785. "demo_fee"=>$info["demo_fee"],
  786. "delivery_fee"=>$info["delivery_fee"],
  787. "open_fee"=>$info["open_fee"],
  788. "packing_fee"=>$info["pakge_fee"],
  789. "mark_fee"=>$info["mark_fee"],
  790. "nake_fee"=>$info["nake_fee"],
  791. "cert_fee"=>$info["cert_fee"],
  792. "cost_fee"=>$info["cost_fee"],
  793. "num"=>$bidinfo["num"],
  794. ];
  795. if($info['is_gold_price']==1){
  796. $price = GoldPrice($god, $budget/100);
  797. $info['sale_price'] =round($price,2);
  798. }
  799. $info['specinfo'] = json_decode($info['specinfo'],true);
  800. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  801. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  802. $info['bargain'] =$bargain;
  803. return app_show(0,"获取成功",$info);
  804. }
  805. public function feededit(){
  806. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  807. if($bidNo==""){
  808. return error_show(1002,"参数bidNo不能为空");
  809. }
  810. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  811. if($bidinfo==false){
  812. return error_show(1003,"未找到信息数据");
  813. }
  814. if($bidinfo['status']>=5){
  815. return error_show(1004,"咨询单已确认无法修改");
  816. }
  817. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  818. if($zxinfo==false){
  819. return error_show(1003,"未找到信息数据");
  820. }
  821. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  822. if($zx==false){
  823. return error_show(1003,"未找咨询信息数据");
  824. }
  825. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  826. if($pname==""){
  827. return error_show(1002,"参数pname不能为空");
  828. }
  829. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  830. // if($brandid==""){
  831. // return error_show(1002,"参数brandid不能为空");
  832. // }
  833. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  834. if($cat_id==""){
  835. return error_show(1002,"参数cat_id不能为空");
  836. }
  837. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  838. if($specin==""){
  839. return error_show(1003,"参数specinfo不能为空");
  840. }
  841. $specinfo=[];
  842. foreach ($specin as $v){
  843. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  844. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  845. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  846. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  847. $specinfo[]=$v;
  848. }
  849. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  850. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  851. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  852. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  853. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  854. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  855. :"";
  856. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  857. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  858. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  859. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  860. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  861. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"";
  862. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"";
  863. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  864. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  865. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"";
  866. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"";
  867. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"";
  868. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"";
  869. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"";
  870. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"";
  871. if($nake_fee==="" ||$nake_fee==0 ){
  872. return error_show(1004,"参数nake_fee不能为空或零");
  873. }
  874. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"";
  875. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"";
  876. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"";
  877. $total_fee = isset($this->post['total_fee'])&&$this->post['total_fee']!=""? floatval($this->post['total_fee']):"";
  878. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  879. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  880. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  881. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  882. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  883. if($is_gold_price==1){
  884. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  885. ->find();
  886. $total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*
  887. $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  888. $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)*
  889. $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  890. }else{
  891. $saleprice = $open_fee/$zxinfo['num'] +
  892. $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee/(1-$budget);
  893. $total_fee = $open_fee/$zxinfo['num'] +
  894. $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  895. }
  896. Db::startTrans();
  897. try{
  898. $data=[
  899. "good_name"=>$pname,
  900. "brand_id"=>$brandid,
  901. "cat_id"=>$cat_id,
  902. "specinfo"=>json_encode($specinfo),
  903. // "material"=>$material,
  904. "unit_id"=>$unit_id,
  905. "cost_desc"=>$cost_desc,
  906. "work_day"=>$work_day,
  907. "delivery_day"=>$delivery_day,
  908. "good_img"=>$good_img,
  909. "expire_day"=>$expire_day,
  910. "origin_place"=>$origin_place,
  911. "supplierNo"=>$supplierNo,
  912. "pay_way"=>$pay_way,
  913. "tax"=>$tax,
  914. "send_way"=>$send_way,
  915. "metal_id"=>$metal_id,
  916. "is_gold_price"=>$is_gold_price,
  917. "config"=>$config,
  918. "other_config"=>$other_config,
  919. "weight"=>$weight,
  920. "is_diff"=>$is_diff,
  921. "demo_fee"=>$demo_fee,
  922. "delivery_fee"=>$delivery_fee,
  923. "open_fee"=>$open_fee,
  924. "pakge_fee"=>$pakge_fee,
  925. "nake_fee"=>$nake_fee,
  926. "mark_fee"=>$mark_fee,
  927. "cert_fee"=>$cert_fee,
  928. "cost_fee"=>$cost_fee,
  929. "total_fee"=>$total_fee,
  930. "sale_price"=>$saleprice,
  931. "supply_area"=>$supply_area,
  932. "remark"=>$remark,
  933. "updatetime"=>date("Y-m-d H:i:s")
  934. ];
  935. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  936. if($insert){
  937. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  938. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  939. if($projectinfo==false){
  940. Db::rollback();
  941. return error_show(1006,"未找到项目信息");
  942. }
  943. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  944. if($feed==false){
  945. Db::rollback();
  946. return error_show(1006,"未找到项目反馈信息");
  947. }
  948. $feed['good_name']=$pname;
  949. $feed['good_type']=$projectinfo['good_type'];
  950. $feed['cat_id']=$cat_id;
  951. $feed['sale_price']=$saleprice;
  952. $feed['origin_price']=$total_fee;
  953. $temp['updatetime']=date("Y-m-d H:i:s");
  954. $nu = Db::name("project_feedback")->save($feed);
  955. if($nu==false){
  956. Db::rollback();
  957. return error_show(1006,"项目反馈失败");
  958. }else{
  959. $projectinfo['status']=2;
  960. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  961. $up = Db::name("project_info")->save($projectinfo);
  962. if($up){
  963. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  964. ->count();
  965. if($count==0){
  966. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  967. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  968. if($proc==false){
  969. Db::rollback();
  970. return error_show(1006,"项目反馈失败");
  971. }
  972. }
  973. }
  974. }
  975. }
  976. Db::commit();
  977. return app_show(0,"编辑成功");
  978. }else{
  979. Db::rollback();
  980. return error_show(1004,"编辑失败");
  981. }
  982. }catch (\Exception $e){
  983. Db::rollback();
  984. return error_show(1004,$e->getMessage());
  985. }
  986. }
  987. public function bargain_add(){
  988. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  989. if($bidNo===""){
  990. return error_show(1004,"参数bidNo不能为空");
  991. }
  992. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  993. if($info==false){
  994. return error_show(1004,"未找到商品数据");
  995. }
  996. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  997. if($bargain_price===""){
  998. return error_show(1004,"参数bargain_price不能为空");
  999. }
  1000. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1001. // if($bargain_reason===""){
  1002. // return error_show(1004,"参数bargain_reason不能为空");
  1003. // }
  1004. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1005. if($infos==false){
  1006. return error_show(1004,"未找到商品数据");
  1007. }
  1008. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1009. return error_show(1004,"咨询单招标未结束或已确认商品");
  1010. }
  1011. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1012. if($token==''){
  1013. return error_show(105,"参数token不能为空");
  1014. }
  1015. $user =GetUserInfo($token);
  1016. if(empty($user)||$user['code']!=0){
  1017. return error_show(1002,"用户数据不存在");
  1018. }
  1019. //新增两个字段
  1020. //议价备注
  1021. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1022. //议价原因id
  1023. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1024. if ($result_info_id != '') {
  1025. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1026. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1027. }
  1028. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1029. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1030. $bargainNo =makeNo("BA");
  1031. Db::startTrans();//::todo 金价 毛利计算
  1032. try{
  1033. $data=[
  1034. "bidsNo"=>$bidNo,
  1035. "infoNo"=>$info['infoNo'],
  1036. "zxNo"=>$info['zxNo'],
  1037. "bargainNo"=>$bargainNo,
  1038. "bargain_type"=>1,
  1039. "bargain_reason"=>$bargain_reason,
  1040. "sale_price"=>$info['sale_price'],
  1041. "cost_before_price"=>$info['cost_fee'],
  1042. "cost_after_price"=>$info['cost_fee'],
  1043. "before_rate"=>$info['cost_fee'],
  1044. "after_rate"=>$info['cost_fee'],
  1045. "after_price"=>$bargain_price,
  1046. "exam_info"=>"",
  1047. "status"=>1,
  1048. "is_del"=>0,
  1049. "creater"=>$creater,
  1050. "createrid"=>$createrid,
  1051. "addtime"=>date("Y-m-d H:i:s"),
  1052. "updatetime"=>date("Y-m-d H:i:s"),
  1053. 'bargain_remark'=>$bargain_remark,
  1054. 'result_info_id'=>$result_info_id,
  1055. ];
  1056. $int = Db::name("bargain_order")->insert($data);
  1057. if($int){
  1058. $info['status']=3;
  1059. $info['updatetime']=date("Y-m-d H:i:s");
  1060. $up =Db::name("consult_bids")->save($info);
  1061. if($up){
  1062. $infos['status']=3;
  1063. $infos['updatetime']=date("Y-m-d H:i:s");
  1064. $ups =Db::name("consult_info")->save($infos);
  1065. if($ups){
  1066. Db::commit();
  1067. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1068. }
  1069. }
  1070. }
  1071. Db::rollback();
  1072. return error_show(1004,"议价单新建失败");
  1073. }catch (\Exception $e){
  1074. Db::rollback();
  1075. return error_show(1004,$e->getMessage());
  1076. }
  1077. }
  1078. public function bids_check(){
  1079. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1080. if($bidNo===""){
  1081. return error_show(1004,"参数bidNo不能为空");
  1082. }
  1083. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1084. if($info==false){
  1085. return error_show(1004,"未找到商品数据");
  1086. }
  1087. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1088. if($infos==false){
  1089. return error_show(1004,"未找到商品数据");
  1090. }
  1091. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1092. return error_show(1004,"咨询单招标未结束或已确认商品");
  1093. }
  1094. Db::startTrans();
  1095. try {
  1096. $info['status']=6;
  1097. $info['updatetime']=date("Y-m-d H:i:s");
  1098. $bids = Db::name("consult_bids")->save($info);
  1099. if($bids){
  1100. $infos['status']=4;
  1101. $infos['updatetime']=date("Y-m-d H:i:s");
  1102. $se = Db::name("consult_info")->save($infos);
  1103. if($se){
  1104. Db::commit();
  1105. return app_show(0,"商品确定成功");
  1106. }
  1107. }
  1108. Db::rollback();
  1109. return error_show(1004,"商品确认失败");
  1110. }catch (\Exception $e){
  1111. Db::rollback();
  1112. return error_show(1004,$e->getMessage());
  1113. }
  1114. }
  1115. public function bargain_status(){
  1116. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1117. if($bargainNo===""){
  1118. return error_show(1004,"参数bargainNo不能为空");
  1119. }
  1120. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1121. if($info==false){
  1122. return error_show(1004,"未找到议价数据");
  1123. }
  1124. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1125. if($bids==false){
  1126. return error_show(1004,"未找到商品数据");
  1127. }
  1128. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1129. if($coninfo==false){
  1130. return error_show(1004,"未找到咨询单数据");
  1131. }
  1132. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1133. if($status==''){
  1134. return error_show(1005,"参数status不能为空");
  1135. }
  1136. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1137. // if($remark==""){
  1138. // return error_show(1004,"参数remark不能为空");
  1139. // }
  1140. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1141. if($token==''){
  1142. return error_show(105,"参数token不能为空");
  1143. }
  1144. $user =GetUserInfo($token);
  1145. if(empty($user)||$user['code']!=0){
  1146. return error_show(1002,"用户数据不存在");
  1147. }
  1148. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1149. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1150. Db::startTrans();
  1151. try{
  1152. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1153. $examinfo[]=["status"=>$status,"remark"=>$remark,"createrid"=>$createrid,"creater"=>$creater];
  1154. $info['status'] =$status;
  1155. $info['remark'] =$remark;
  1156. $info['exam_info']=json_encode($examinfo) ;
  1157. $info['updatetime'] =date("Y-m-d H:i:s");
  1158. $up =Db::name("bargain_order")->save($info);
  1159. if($up){
  1160. if($status==4||$status==5||$status==6||$status==7){
  1161. $bids['status']=5;
  1162. if($status==4){
  1163. $bids['sale_price']=$info['after_price'];
  1164. }
  1165. $bids['updatetime']=date("Y-m-d H:i:s");
  1166. $up =Db::name("consult_bids")->save($bids);
  1167. if($up==false){
  1168. Db::rollback();
  1169. return error_show(1004,"数据更新失败");
  1170. }
  1171. }
  1172. Db::commit();
  1173. return app_show(0,"更新成功");
  1174. }
  1175. }catch (\Exception $e){
  1176. Db::rollback();
  1177. return error_show(1004,$e->getMessage());
  1178. }
  1179. }
  1180. public function bargain_info(){
  1181. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1182. if($bargainNo===""){
  1183. return error_show(1004,"参数bargainNo不能为空");
  1184. }
  1185. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1186. if($info==false){
  1187. return error_show(1004,"未找到议价数据");
  1188. }
  1189. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1190. if($bidinfos==false){
  1191. return error_show(1004,"未找到商品数据");
  1192. }
  1193. $consultinfos = Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])
  1194. ->find();
  1195. if($consultinfos==false){
  1196. return error_show(1004,"未找到咨询商品数据");
  1197. }
  1198. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1199. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1200. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1201. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1202. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1203. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_encode($info['exam_info']):"";
  1204. if($bidinfos['brand_id']!=0){
  1205. $info['brand_id'] = $bidinfos['brand_id'];
  1206. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1207. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1208. }else{
  1209. $info["brand_name"]="";
  1210. $info["brand_id"]="";
  1211. }
  1212. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1213. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1214. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1215. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1216. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1217. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1218. $info['budget'] =$budget;
  1219. $god=[
  1220. "metal_id"=>$bidinfos['metal_id'],
  1221. "weight"=>$bidinfos["weight"],
  1222. "demo_fee"=>$bidinfos["demo_fee"],
  1223. "delivery_fee"=>$bidinfos["delivery_fee"],
  1224. "open_fee"=>$bidinfos["open_fee"],
  1225. "packing_fee"=>$bidinfos["pakge_fee"],
  1226. "mark_fee"=>$bidinfos["mark_fee"],
  1227. "nake_fee"=>$bidinfos["nake_fee"],
  1228. "cert_fee"=>$bidinfos["cert_fee"],
  1229. "cost_fee"=>$bidinfos["cost_fee"],
  1230. "num"=>$bidinfoe["num"],
  1231. ];
  1232. $info['gold_price']=0;
  1233. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1234. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1235. ->find();
  1236. $info['gold_price'] =$gold['price'];
  1237. }
  1238. $info['cost_desc'] =$bidinfos['cost_desc'];
  1239. $info['work_day'] =$bidinfos['work_day'];
  1240. $info['delivery_day'] =$bidinfos['delivery_day'];
  1241. $info['expire_day'] =$bidinfos['expire_day'];
  1242. $info['origin_place'] =$bidinfos['origin_place'];
  1243. $info['origin_addr'] ="";
  1244. if($bidinfos['origin_place']!=''){
  1245. $code = explode(",",$bidinfos['origin_place']);
  1246. $temp=[];
  1247. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1248. $temp['city_code']=isset($code[1])?$code[1]:"";
  1249. $temp['area_code']=isset($code[2])?$code[2]:"";
  1250. $addr= GetAddr(json_encode($temp));
  1251. $info['origin_addr'] = $addr;
  1252. }
  1253. $info['supplierNo'] =$bidinfos['supplierNo'];
  1254. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1255. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1256. $info['pay_way'] =$bidinfos['pay_way'];
  1257. $info['tax'] =$bidinfos['tax'];
  1258. $info['send_way'] =$bidinfos['send_way'];
  1259. $info['metal_id'] =$bidinfos['metal_id'];
  1260. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1261. $info['config'] =$bidinfos['config'];
  1262. $info['other_config'] =$bidinfos['other_config'];
  1263. $info['weight'] =$bidinfos['weight'];
  1264. $info['is_diff'] =$bidinfos['is_diff'];
  1265. $info['demo_fee'] =$bidinfos['demo_fee'];
  1266. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1267. $info['open_fee'] =$bidinfos['open_fee'];
  1268. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1269. $info['nake_fee'] =$bidinfos['nake_fee'];
  1270. $info['mark_fee'] =$bidinfos['mark_fee'];
  1271. $info['cert_fee'] =$bidinfos['cert_fee'];
  1272. $info['cost_fee'] =$bidinfos['cost_fee'];
  1273. $info['total_fee'] =$bidinfos['total_fee'];
  1274. $info['supply_area'] =$bidinfos['supply_area'];
  1275. $info['remark'] =$bidinfos['remark'];
  1276. $info['is_addrs'] =$consultinfos['is_addrs'];
  1277. $info['is_custom'] =$consultinfos['is_custom'];
  1278. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1279. $info['sale_price'] =round($bidinfos['sale_price'],2);
  1280. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1281. //获取议价原因
  1282. if ($info['result_info_id'] != 0) {
  1283. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1284. } else {
  1285. $info['result_info'] = '';
  1286. }
  1287. return app_show(0,"获取成功",$info);
  1288. }
  1289. public function bidlist(){
  1290. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1291. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1292. $where=[['is_del',"=",0]];
  1293. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1294. if ($zxNo !== "") {
  1295. $where[] = ['zxNo','=',$zxNo];
  1296. }
  1297. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1298. if ($infoNo !== "") {
  1299. $where[] = ['infoNo','=',$infoNo];
  1300. }
  1301. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1302. if ($bidNo !== "") {
  1303. $where[] = ['bidNo','=',$bidNo];
  1304. }
  1305. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1306. if ($pgNo !== "") {
  1307. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1308. $where[] = ['infoNo','in',$bidinfo];
  1309. }
  1310. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1311. if ($bargain_status !== "") {
  1312. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1313. $where[] = ['infoNo','in',$bidinfo];
  1314. }
  1315. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1316. if ($projectNo !== "") {
  1317. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1318. ("zxNo");
  1319. $where[] = ['zxNo','in',$zxlist];
  1320. }
  1321. $count = Db::name('consult_bids')->where($where)->count();
  1322. $total = ceil($count / $size);
  1323. $page = $page >= $total ? $total : $page;
  1324. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select();
  1325. $data=[];
  1326. foreach ($list as $value){
  1327. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1328. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1329. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1330. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1331. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1332. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1333. if($value['brand_id']!=0){
  1334. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1335. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1336. }else{
  1337. $value["brand_name"]="";
  1338. $value["brand_id"]="";
  1339. }
  1340. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1341. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1342. $god=[
  1343. "metal_id"=>$value['metal_id'],
  1344. "weight"=>$value["weight"],
  1345. "demo_fee"=>$value["demo_fee"],
  1346. "delivery_fee"=>$value["delivery_fee"],
  1347. "open_fee"=>$value["open_fee"],
  1348. "packing_fee"=>$value["pakge_fee"],
  1349. "mark_fee"=>$value["mark_fee"],
  1350. "nake_fee"=>$value["nake_fee"],
  1351. "cert_fee"=>$value["cert_fee"],
  1352. "cost_fee"=>$value["cost_fee"],
  1353. "num"=>$bidinfo["num"],
  1354. ];
  1355. if($value['is_gold_price']==1){
  1356. $price = GoldPrice($god, $budget/100);
  1357. $value['sale_price'] = round($price,2);
  1358. }
  1359. $value['specinfo'] = json_decode($value['specinfo'],true);
  1360. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1361. $value['bargain_status']=$bidinfo['bargain_status'];
  1362. $data[]=$value;
  1363. }
  1364. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1365. }
  1366. public function feedlist(){
  1367. $where=[['is_del',"=",0]];
  1368. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1369. if ($zxNo !== "") {
  1370. $where[] = ['zxNo','=',$zxNo];
  1371. }
  1372. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1373. if ($infoNo !== "") {
  1374. $where[] = ['infoNo','=',$infoNo];
  1375. }
  1376. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1377. if ($bidNo !== "") {
  1378. $where[] = ['bidNo','=',$bidNo];
  1379. }
  1380. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1381. if ($projectNo !== "") {
  1382. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1383. ("zxNo");
  1384. $where[] = ['zxNo','in',$zxlist];
  1385. }
  1386. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1387. if($token==''){
  1388. return error_show(102,"参数token不能为空");
  1389. }
  1390. $user =GetUserInfo($token);
  1391. if(empty($user)||$user['code']!=0){
  1392. return error_show(105,"用户数据不存在");
  1393. }
  1394. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1395. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1396. $where[] = ["createrid","=",$createrid];
  1397. $list =Db::name('consult_bids')->where($where)->select();
  1398. $data=[];
  1399. foreach ($list as $value){
  1400. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1401. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1402. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1403. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1404. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1405. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1406. if($value['brand_id']!=0){
  1407. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1408. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1409. }else{
  1410. $value["brand_name"]="";
  1411. $value["brand_id"]="";
  1412. }
  1413. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1414. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1415. $god=[
  1416. "metal_id"=>$value['metal_id'],
  1417. "weight"=>$value["weight"],
  1418. "demo_fee"=>$value["demo_fee"],
  1419. "delivery_fee"=>$value["delivery_fee"],
  1420. "open_fee"=>$value["open_fee"],
  1421. "packing_fee"=>$value["pakge_fee"],
  1422. "mark_fee"=>$value["mark_fee"],
  1423. "nake_fee"=>$value["nake_fee"],
  1424. "cert_fee"=>$value["cert_fee"],
  1425. "cost_fee"=>$value["cost_fee"],
  1426. "num"=>$bidinfo["num"],
  1427. ];
  1428. if($value['is_gold_price']==1){
  1429. $price = GoldPrice($god, $budget/100);
  1430. $value['sale_price'] =round($price,2);
  1431. }
  1432. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1433. $value['specinfo'] = json_decode($value['specinfo'],true);
  1434. $value['bargain_status']=$bidinfo['bargain_status'];
  1435. $data[]=$value;
  1436. }
  1437. return app_show(0,"获取成功",$data);
  1438. }
  1439. public function bragain_list(){
  1440. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1441. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1442. $where=[['is_del',"=",0]];
  1443. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1444. if($bidsNo!=""){
  1445. $where[]=["bidsNo","=",$bidsNo];
  1446. }
  1447. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1448. if ($zxNo !== "") {
  1449. $where[] = ['zxNo','=',$zxNo];
  1450. }
  1451. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1452. if ($infoNo !== "") {
  1453. $where[] = ['infoNo','=',$infoNo];
  1454. }
  1455. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1456. if ($projectNo !== "") {
  1457. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1458. ("zxNo");
  1459. $where[] = ['zxNo','in',$zxlist];
  1460. }
  1461. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1462. if ($pgNo !== "") {
  1463. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1464. $where[] = ['infoNo','in',$bidinfo];
  1465. }
  1466. $count=Db::name("bargain_order")->where($where)->count();
  1467. $total = ceil($count / $size);
  1468. $page = $page >= $total ? $total : $page;
  1469. $list =Db::name('bargain_order')->where($where)->page($page,$size)->order('addtime','desc')->select();
  1470. $data=[];
  1471. foreach ($list as $value){
  1472. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1473. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1474. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1475. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1476. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1477. if($bidinfos['brand_id']!=0){
  1478. $value['brand_id'] = $bidinfos['brand_id'];
  1479. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1480. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1481. }else{
  1482. $value["brand_name"]="";
  1483. $value["brand_id"]="";
  1484. }
  1485. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1486. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1487. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1488. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1489. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1490. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1491. $value['budget'] =$budget;
  1492. $god=[
  1493. "metal_id"=>$bidinfos['metal_id'],
  1494. "weight"=>$bidinfos["weight"],
  1495. "demo_fee"=>$bidinfos["demo_fee"],
  1496. "delivery_fee"=>$bidinfos["delivery_fee"],
  1497. "open_fee"=>$bidinfos["open_fee"],
  1498. "packing_fee"=>$bidinfos["pakge_fee"],
  1499. "mark_fee"=>$bidinfos["mark_fee"],
  1500. "nake_fee"=>$bidinfos["nake_fee"],
  1501. "cert_fee"=>$bidinfos["cert_fee"],
  1502. "cost_fee"=>$bidinfos["cost_fee"],
  1503. "num"=>$bidinfoe["num"],
  1504. ];
  1505. // if($bidinfos['is_gold_price']==1){
  1506. // $price = GoldPrice($god, $budget/100);
  1507. // }else{
  1508. // $price = GoodPrice($god, $budget/100);
  1509. // }
  1510. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1511. $value['sale_price'] =round($bidinfos['sale_price'],2);
  1512. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1513. $data[]=$value;
  1514. }
  1515. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  1516. }
  1517. public function crontablist(){
  1518. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1519. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1520. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  1521. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1522. if ($zxNo !== "") {
  1523. $where[] = ['a.zxNo','=',$zxNo];
  1524. }
  1525. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  1526. if ($salesman !== "") {
  1527. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  1528. $where[]= ["b.salesman",'like',"%$salesman%"];
  1529. }
  1530. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  1531. if ($cpName !== "") {
  1532. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  1533. $where[]= ["a.good_Name",'like',"%$cpName%"];
  1534. }
  1535. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  1536. if ($khNo !== "") {
  1537. // $where['khNo'] = $khNo;
  1538. $where[]= ["b.khNo",'like',"%$khNo%"];
  1539. }
  1540. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  1541. if ($start !="") {
  1542. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  1543. $where[]= ["a.addtime",'>=',$start];
  1544. }
  1545. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  1546. if($end !=""){
  1547. $where[]= ["a.addtime",'<=',$end];
  1548. }
  1549. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  1550. if ($status !== "") {
  1551. $where[]= ["a.status",'=',$status];
  1552. }
  1553. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  1554. ->count();
  1555. $total = ceil($count / $size);
  1556. $page = $page >= $total ? $total : $page;
  1557. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  1558. ->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();
  1559. $data=[];
  1560. foreach ($list as $value){
  1561. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1562. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  1563. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  1564. $value['khname']="";
  1565. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  1566. true):[];
  1567. if($value['khNo']!==""){
  1568. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  1569. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  1570. }
  1571. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1572. $data[]=$value;
  1573. }
  1574. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1575. }
  1576. }