Consult.php 84 KB

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