Consult.php 118 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216
  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','like','%'.$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. $role=$this->checkRole();
  59. if(!empty($role['write'])){
  60. $where[]=["b.createrid","in",$role['write']];
  61. }
  62. // if(!empty($role['platform']) ){
  63. // $where[]=["b.platform_code","in",$role['platform']];
  64. // }
  65. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  66. ->count();
  67. $total = ceil($count / $size);
  68. $page = $page >= $total ? $total : $page;
  69. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  70. ->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();
  71. $data=[];
  72. foreach ($list as $value){
  73. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  74. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  75. true):[];
  76. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  77. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  78. $value['khname']="";
  79. if($value['khNo']!==""){
  80. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  81. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  82. }
  83. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  84. $data[]=$value;
  85. }
  86. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  87. }
  88. public function info(){
  89. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  90. if($id==""){
  91. return error_show(1002,"咨询单编号不能为空");
  92. }
  93. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  94. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  95. $fo['can']=$in;
  96. if(empty($fo)){
  97. return error_show(1002,"未找到咨询单编号");
  98. }else{
  99. return app_show(0,"获取成功",$fo);
  100. }
  101. }
  102. public function del(){
  103. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  104. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  105. if($de==false){
  106. return error_show(1002,'咨询单信息未找到');
  107. }
  108. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  109. if($dell){
  110. return error_show(0,"删除成功");
  111. }else
  112. return error_show(1002,"删除失败");
  113. }
  114. public function create(){
  115. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  116. if($is_project===""){
  117. return error_show(1002,"参数is_project不能为空");
  118. }
  119. if($is_project==1){
  120. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  121. if($projectNo===""){
  122. return error_show(1002,"参数projectNo不能为空");
  123. }
  124. }
  125. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  126. if($khNo===""){
  127. return error_show(1002,"参数khNo不能为空");
  128. }
  129. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  130. if($companyNo===""){
  131. return error_show(1002,"参数companyNo不能为空");
  132. }
  133. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  134. if($endtime===""){
  135. return error_show(1002,"参数endtime不能为空");
  136. }
  137. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  138. "";
  139. if($platform_code===""){
  140. return error_show(1002,"参数platform_code不能为空");
  141. }
  142. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  143. if($ladder==""){
  144. return error_show(1005,"参数ladder不能为空");
  145. }
  146. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  147. if($token==''){
  148. return error_show(105,"参数token不能为空");
  149. }
  150. $user =GetUserInfo($token);
  151. if(empty($user)||$user['code']!=0){
  152. return error_show(102,"用户数据不存在");
  153. }
  154. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  155. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  156. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  157. $zxNo=makeNo("ZX");
  158. Db::startTrans();
  159. try{
  160. $data=[
  161. "zxNo"=>$zxNo,
  162. "createrid"=>$createrid,
  163. "creater"=>$creater,
  164. "is_project"=>$is_project,
  165. "projectNo"=>isset($projectNo) ? $projectNo:"",
  166. "khNo"=>$khNo,
  167. "companyNo"=>$companyNo,
  168. "endtime"=>$endtime,
  169. "salesman"=>$creater,
  170. "platform_code"=>$platform_code,
  171. "saleid"=>$createrid,
  172. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  173. "status"=>0,
  174. "is_del"=>0,
  175. "addtime"=>date("Y-m-d H:i:s"),
  176. "updatetime"=>date("Y-m-d H:i:s"),
  177. ];
  178. $zx = Db::name("consult_order")->insert($data);
  179. if($zx){
  180. foreach ($ladder as $value){
  181. $infoNo=makeNo("IF");
  182. $specinfo=[];
  183. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  184. foreach ($value["specinfo"] as $v){
  185. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  186. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  187. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  188. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  189. $specinfo[]=$v;
  190. }
  191. }
  192. $info=[
  193. "infoNo"=>$infoNo,
  194. "zxNo"=>$zxNo,
  195. "spuCode"=>"",
  196. "good_name"=>$value['good_name'],
  197. "good_img"=>$value['good_img'],
  198. "cat_id"=>$value['cat_id'],
  199. "unit"=>$value['unit'],
  200. "brand_id"=>$value['brand_id'],
  201. "arrival_time"=>$value['arrival_time'],
  202. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  203. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  204. "is_addrs"=>$value['is_addrs'],
  205. "is_custom"=>$value['is_custom'],
  206. "metal_id"=>$value['metal_id'],
  207. "config"=>isset($value['config'])?$value['config']:"",
  208. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  209. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  210. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  211. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  212. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  213. "budget_price"=>$value['budget_price'],
  214. "num"=>$value['num'],
  215. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  216. "use_desc"=>$value['use_desc'],
  217. "remark"=>$value['remark'],
  218. "status"=>1,
  219. "is_del"=>0,
  220. "addtime"=>date("Y-m-d H:i:s"),
  221. "updatetime"=>date("Y-m-d H:i:s"),
  222. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  223. ];
  224. $up = Db::name("consult_info")->insert($info);
  225. if(!$up){
  226. Db::rollback();
  227. return error_show(1004,'添加失败');
  228. }else{
  229. //修改状态,添加待办
  230. ActionLog::logAdd($this->post['token'], [
  231. "order_code" => $infoNo,//咨询单详情编号
  232. "status" => 1,//这里的status是之前的值
  233. "action_remark" => '',//备注
  234. "action_type" => "create"//新建create,编辑edit,更改状态status
  235. ], "ZXD", 1, $info);
  236. // ProcessOrder::AddProcess($this->post['token'], [
  237. // "order_type" => 'ZXD',
  238. // "order_code" => $infoNo,//咨询单详情编号
  239. // "order_id" => 0,
  240. // "order_status" => 1
  241. // ]);
  242. }
  243. }
  244. Db::commit();
  245. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  246. }else{
  247. Db::rollback();
  248. return error_show(1004,"新建失败");
  249. }
  250. }catch (\Exception $e){
  251. Db::rollback();
  252. return error_show(1003,$e->getMessage());
  253. }
  254. }
  255. public function zxinfo(){
  256. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  257. if($infoNo==""){
  258. return error_show(1004,"参数infoNo不能为空");
  259. }
  260. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  261. if($zxinfo==false){
  262. return error_show(1004,"未找到信息数据");
  263. }
  264. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  265. if($zxorder==false){
  266. return error_show(1004,"未找到咨询信息数据");
  267. }
  268. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  269. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  270. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  271. $zxinfo['khname']="";
  272. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  273. $zxinfo['khNo']="";
  274. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  275. $zxinfo['brand']="";
  276. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  277. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  278. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  279. $zxinfo['company']="";
  280. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  281. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  282. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  283. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  284. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  285. $zxinfo['project_name']="";
  286. $zxinfo['budget_total']="";
  287. $zxinfo['departinfo']=[];
  288. $zxinfo['unit_name']="";
  289. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  290. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  291. if($zxorder['khNo']!==""){
  292. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  293. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  294. $zxinfo['khNo']= $zxorder['khNo'];
  295. }
  296. if($zxinfo['unit']!==""){
  297. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  298. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  299. }
  300. if($zxinfo['brand_id']!==""){
  301. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  302. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  303. }
  304. if($zxorder['companyNo']!==""){
  305. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  306. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  307. }
  308. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  309. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  310. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  311. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  312. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  313. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  314. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  315. }
  316. if($zxorder['depart']>0){
  317. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  318. }
  319. if($zxorder['platform_code']>0){
  320. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  321. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  322. }
  323. return app_show(0,"获取成功",$zxinfo);
  324. }
  325. public function zxedit(){
  326. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  327. if($infoNo==""){
  328. return error_show(1004,"参数infoNo不能为空");
  329. }
  330. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  331. if($zxinfo==false){
  332. return error_show(1004,"未找到信息数据");
  333. }
  334. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  335. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  336. if($good_name==""){
  337. return error_show(1003,"参数good_name不能为空");
  338. }
  339. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  340. if($good_img==""){
  341. return error_show(1003,"参数good_img不能为空");
  342. }
  343. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  344. if($cat_id==""){
  345. return error_show(1003,"参数cat_id不能为空");
  346. }
  347. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  348. if($unit==""){
  349. return error_show(1003,"参数unit不能为空");
  350. }
  351. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  352. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  353. if($arrival_time==""){
  354. return error_show(1003,"参数arrival_time不能为空");
  355. }
  356. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  357. if($specin==""){
  358. return error_show(1003,"参数specinfo不能为空");
  359. }
  360. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  361. // if($cost_desc==""){
  362. // return error_show(1003,"参数cost_desc不能为空");
  363. // }
  364. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  365. if($is_addrs===""){
  366. return error_show(1003,"参数is_addrs不能为空");
  367. }
  368. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  369. if($is_custom===""){
  370. return error_show(1003,"参数is_custom不能为空");
  371. }
  372. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  373. if($metal_id===""){
  374. return error_show(1003,"参数metal_id不能为空");
  375. }
  376. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  377. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  378. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  379. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  380. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  381. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  382. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  383. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  384. if($num===""){
  385. return error_show(1003,"参数num不能为空");
  386. }
  387. if($budget_price===""){
  388. return error_show(1003,"参数budget_price不能为空");
  389. }
  390. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  391. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  392. if($use_desc==""){
  393. return error_show(1003,"参数use_desc不能为空");
  394. }
  395. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  396. if($remark==""){
  397. return error_show(1003,"参数remark不能为空");
  398. }
  399. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  400. if($endtime==""){
  401. return error_show(1003,"参数endtime不能为空");
  402. }
  403. if($metal_id!=0){
  404. if($config==""){
  405. return error_show(1003,"参数config不能为空");
  406. }
  407. if($other_config==""){
  408. return error_show(1003,"参数other_config不能为空");
  409. }
  410. if($specs_weight===""){
  411. return error_show(1003,"参数specs_weight不能为空");
  412. }
  413. if($gold_price===""){
  414. return error_show(1003,"参数gold_price不能为空");
  415. }
  416. }
  417. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  418. if($token==''){
  419. return error_show(102,"参数token不能为空");
  420. }
  421. $user =GetUserInfo($token);
  422. if(empty($user)||$user['code']!=0){
  423. return error_show(105,"用户数据不存在");
  424. }
  425. $specinfo=[];
  426. foreach ($specin as $v){
  427. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  428. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  429. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  430. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  431. $specinfo[]=$v;
  432. }
  433. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  434. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  435. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  436. Db::startTrans();
  437. try{
  438. $innew =makeNo("IF");
  439. $info=[
  440. "infoNo"=>$innew,
  441. "zxNo"=>$zxinfo['zxNo'],
  442. "spuCode"=>"",
  443. "good_name"=>$good_name,
  444. "good_img"=>$good_img,
  445. "cat_id"=>$cat_id,
  446. "unit"=>$unit,
  447. "brand_id"=>$brand_id,
  448. "arrival_time"=>$arrival_time,
  449. "specinfo"=>json_encode($specinfo),
  450. // "color"=>$color,
  451. // "material"=>$material,
  452. "cost_desc"=>$cost_desc,
  453. "is_addrs"=>$is_addrs,
  454. "is_custom"=>$is_custom,
  455. "metal_id"=>$metal_id,
  456. "config"=>$config,
  457. "other_config"=>$other_config,
  458. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  459. "gold_price"=>$gold_price===""? 0 : $gold_price,
  460. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  461. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  462. "budget_price"=>$budget_price,
  463. "num"=>$num,
  464. "pgNo"=>$pgNo,
  465. "use_desc"=>$use_desc,
  466. "remark"=>$remark,
  467. "status"=>1,
  468. "is_del"=>0,
  469. "addtime"=>date("Y-m-d H:i:s"),
  470. "updatetime"=>date("Y-m-d H:i:s"),
  471. 'bargain_status'=>1,
  472. 'enclosure_file'=>$enclosure_file
  473. ];
  474. $up = Db::name("consult_info")->insert($info);
  475. if($up){
  476. //操作记录
  477. ActionLog::logAdd($this->post['token'], [
  478. "order_code" => $innew,//咨询单详情编号
  479. "status" => 1,//这里的status是之前的值
  480. "action_remark" => '',//备注
  481. "action_type" => "edit"//新建create,编辑edit,更改状态status
  482. ], "ZXD", 1, $this->post);
  483. // ProcessOrder::AddProcess($this->post['token'], [
  484. // "order_type" => 'ZXD',
  485. // "order_code" => $innew,//咨询单详情编号
  486. // "order_id" => 0,
  487. // "order_status" => 1
  488. // ]);
  489. if (!empty($bidlist)){
  490. foreach ($bidlist as $value){
  491. unset($value['id']);
  492. $value['infoNo']=$innew;
  493. $value['bidNo']=makeNo("BD");
  494. $value['spuCode']=makeNo("SKU");
  495. $value['status'] =0;
  496. $value['updatetime'] =date("Y-m-d H:i:s");
  497. $in = Db::name("consult_bids")->insert($value);
  498. if($in==false){
  499. Db::rollback();
  500. return error_show(1004,"反馈商品新建失败");
  501. }
  502. ActionLog::logAdd($this->post['token'], [
  503. "order_code" => $innew,//咨询单详情编号
  504. "status" => 1,//这里的status是之前的值
  505. "action_remark" => '',//备注
  506. "action_type" => "edit"//新建create,编辑edit,更改状态status
  507. ], "FKD", 1, $this->post);
  508. }
  509. }
  510. $zxinfo["bargain_status"] =1;
  511. $zxinfo["bargain_code"] =$innew;
  512. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  513. $bar=Db::name("consult_info")->save($zxinfo);
  514. if($bar==false){
  515. Db::rollback();
  516. return error_show(1004,"反馈商品更新失败");
  517. }else{
  518. //修改状态,添加待办
  519. ActionLog::logAdd($this->post['token'], [
  520. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  521. "status" => $zxinfo['status'],//这里的status是之前的值
  522. "action_remark" => '',//备注
  523. "action_type" => "edit"//新建create,编辑edit,更改状态status
  524. ], "ZXD", $zxinfo['status'], $zxinfo);
  525. }
  526. //更新consule_order记录
  527. $op = Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,
  528. 'updatetime'=>date('Y-m-d H:i:s')]);
  529. if($op==false){
  530. Db::rollback();
  531. return error_show(1004,'咨询单结束时间更新失败');
  532. }
  533. Db::commit();
  534. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  535. }
  536. }catch (\Exception $e){
  537. Db::rollback();
  538. return error_show(1004,$e->getMessage());
  539. }
  540. }
  541. //** 发布竞标任务 */
  542. public function bargain(){
  543. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  544. if($infoNo==""){
  545. return error_show(1004,"参数infoNo不能为空");
  546. }
  547. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  548. if($zxinfo==false){
  549. return error_show(1004,"未找到信息数据");
  550. }
  551. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  552. if($status===""){
  553. return error_show(1004,"参数status不能为空");
  554. }
  555. // if($status==1&&$zxinfo['status']>1){
  556. // $zxinfo['bargain_num']=+1;
  557. // }
  558. $old_zxinfo_status = $zxinfo['status'];
  559. $zxinfo['status']=$status;
  560. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  561. $up = Db::name("consult_info")->save($zxinfo);
  562. if($up){
  563. //修改状态,添加待办
  564. ActionLog::logAdd($this->post['token'], [
  565. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  566. "status" => $old_zxinfo_status,//这里的status是之前的值
  567. "action_remark" => '',//备注
  568. "action_type" => "status"//新建create,编辑edit,更改状态status
  569. ], "ZXD", $zxinfo['status'], $zxinfo);
  570. return app_show(0,"状态更新成功");
  571. }else{
  572. return error_show(1003,"状态更新失败");
  573. }
  574. }
  575. //反馈商品添加
  576. public function feadback(){
  577. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  578. if($infoNo==""){
  579. return error_show(1002,"参数infoNo不能为空");
  580. }
  581. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  582. if($zxinfo==false){
  583. return error_show(1003,"未找到信息数据");
  584. }
  585. if($zxinfo['status']!=1){
  586. return error_show(1004,"任务未进行");
  587. }
  588. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  589. if($zx==false){
  590. return error_show(1003,"未找咨询信息数据");
  591. }
  592. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  593. if($pname==""){
  594. return error_show(1002,"参数pname不能为空");
  595. }
  596. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  597. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  598. if($cat_id==""){
  599. return error_show(1002,"参数cat_id不能为空");
  600. }
  601. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  602. if($specin==""){
  603. return error_show(1003,"参数specinfo不能为空");
  604. }
  605. $specinfo=[];
  606. foreach ($specin as $v){
  607. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  608. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  609. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  610. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  611. $specinfo[]=$v;
  612. }
  613. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  614. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  615. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  616. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  617. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  618. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  619. :"";
  620. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  621. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  622. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  623. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  624. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  625. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  626. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  627. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  628. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  629. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"0";
  630. $good_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  631. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  632. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"0";
  633. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  634. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval($this->post['pakge_fee']):"0";
  635. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"0";
  636. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  637. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  638. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  639. if($nake_fee==="" ){
  640. return error_show(1004,"参数nake_fee不能为空");
  641. }
  642. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  643. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  644. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  645. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  646. if($delivery_place==''){
  647. return error_show(1002,"参数delivery_place不能为空");
  648. }
  649. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  650. if($token==''){
  651. return error_show(1002,"参数token不能为空");
  652. }
  653. $user =GetUserInfo($token);
  654. if(empty($user)||$user['code']!=0){
  655. return error_show(1005,"用户数据不存在");
  656. }
  657. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  658. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  659. $bidNo=makeNo("BD");
  660. $spucode=makeNo("SKU");
  661. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  662. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  663. //部分参数的大小校验
  664. $vali = Validate::rule([
  665. 'expire_day|有效时长'=>'require|elt:214748364',
  666. 'delivery_day|物流时长'=>'require|elt:214748364',
  667. 'work_day|生产工期'=>'require|elt:214748364',
  668. 'weight|总重量'=>'require|max:10',
  669. ]);
  670. $temp = [
  671. 'expire_day'=>$expire_day,
  672. 'delivery_day'=>$delivery_day,
  673. 'work_day'=>$work_day,
  674. 'weight'=>$weight,
  675. ];
  676. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  677. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  678. $cat_top_list = made($cat_id);
  679. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  680. if ($is_gold_price == 1 && $cat_top_id == 6) {
  681. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  682. ->find();
  683. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  684. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  685. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $good_weight * $gold["price"] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  686. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  687. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  688. // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  689. $saleprice = $total_fee/ (1 - $budget);
  690. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  691. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) /$good_weight - $gold["price"];
  692. }else{
  693. if($nake_fee){
  694. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight +
  695. $pakge_fee + $mark_fee + $cert_fee +$nake_fee)/ (1 - $budget);
  696. $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  697. }else{
  698. $saleprice = ($demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee) /
  699. (1 - $budget);
  700. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee;
  701. }
  702. }
  703. $data=[
  704. "bidNo"=>$bidNo,
  705. "infoNo"=>$infoNo,
  706. "zxNo"=>$zxinfo['zxNo'],
  707. "spuCode"=>$spucode,
  708. "good_name"=>$pname,
  709. "brand_id"=>$brandid,
  710. "cat_id"=>$cat_id,
  711. "specinfo"=>json_encode($specinfo),
  712. "unit_id"=>$unit_id,
  713. "cost_desc"=>$cost_desc,
  714. "work_day"=>$work_day,
  715. "delivery_day"=>$delivery_day,
  716. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  717. "expire_day"=>$expire_day,
  718. "origin_place"=>$origin_place,
  719. "supplierNo"=>$supplierNo,
  720. "pay_way"=>$pay_way,
  721. "tax"=>$tax,
  722. "send_way"=>$send_way,
  723. "metal_id"=>$metal_id,
  724. "is_gold_price"=>$is_gold_price,
  725. "config"=>$config,
  726. "other_config"=>$other_config,
  727. "weight"=>$weight,
  728. "good_weight"=>$good_weight,
  729. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  730. "is_diff"=>$is_diff,
  731. "demo_fee"=>$demo_fee,
  732. "delivery_fee"=>$delivery_fee,
  733. "open_fee"=>$open_fee,
  734. "pakge_fee"=>$pakge_fee,
  735. "nake_fee"=>$nake_fee,
  736. "mark_fee"=>$mark_fee,
  737. "cert_fee"=>$cert_fee,
  738. "cost_fee"=>$cost_fee,
  739. "total_fee"=>$total_fee,
  740. "supply_area"=>$supply_area,
  741. "remark"=>$remark,
  742. "sale_price"=>$saleprice,
  743. "sale_cost_fee"=>$sale_cost_fee,
  744. "origin_cost_fee"=>$sale_cost_fee,
  745. "origin_price"=>$saleprice,
  746. "createrid"=>$createrid,
  747. "creater"=>$creater,
  748. "status"=>$zxinfo['status']==1 ?1 :2,
  749. "is_del"=>0,
  750. "addtime"=>date("Y-m-d H:i:s"),
  751. "updatetime"=>date("Y-m-d H:i:s"),
  752. 'delivery_place'=>$delivery_place//发货地
  753. ];
  754. Db::startTrans();
  755. try{
  756. $insert= Db::name("consult_bids")->insert($data);
  757. if($insert){
  758. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  759. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  760. if($projectinfo==false){
  761. Db::rollback();
  762. return error_show(1006,"未找到项目信息");
  763. }
  764. $temp=[];
  765. $temp['spuCode']=$spucode;
  766. $temp['skuCode']="";
  767. $temp['pgNo']=$zxinfo['pgNo'];
  768. $temp['projectNo']=$zx['projectNo'];
  769. $temp['good_name']=$pname;
  770. $temp['good_type']=$projectinfo['good_type'];
  771. $temp['data_source']=2;
  772. $temp['cat_id']=$cat_id;
  773. $temp['budget_price']=$projectinfo['budget_price'];
  774. $temp['sale_price']=$saleprice;
  775. $temp['origin_price']=$total_fee;
  776. $temp['num']=$zxinfo['num'];
  777. $temp['status']=0;
  778. $temp['is_del']=0;
  779. $temp['creater']=$creater;
  780. $temp['createrid']=$createrid;
  781. $temp['addtime']=date("Y-m-d H:i:s");
  782. $temp['updatetime']=date("Y-m-d H:i:s");
  783. $nu = Db::name("project_feedback")->insert($temp);
  784. if($nu==false){
  785. Db::rollback();
  786. return error_show(1006,"项目反馈失败");
  787. }else{
  788. $old_projectinfo_status = $projectinfo['status'];
  789. $projectinfo['status']=2;
  790. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  791. $up = Db::name("project_info")->save($projectinfo);
  792. if($up){
  793. //修改状态,添加待办,只记录动作
  794. ActionLog::logAdd($this->post['token'], [
  795. "order_code" => $projectinfo['pgNo'],//编码
  796. "status" => $old_projectinfo_status,//这里的status是之前的值
  797. "action_remark" => '',//备注
  798. "action_type" => "status"//新建create,编辑edit,更改状态status
  799. ], "PRI", 2, $projectinfo);
  800. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  801. ->count();
  802. if($count==0){
  803. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  804. if($projetc!=false){
  805. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  806. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  807. if($proc==false){
  808. Db::rollback();
  809. return error_show(1006,"项目反馈失败");
  810. }else{
  811. //修改状态,添加待办
  812. ActionLog::logAdd($this->post['token'], [
  813. "order_code" => $projetc['projectNo'],//项目编码
  814. "status" => 1,//这里的status是之前的值
  815. "action_remark" => '',//备注
  816. "action_type" => "status"//新建create,编辑edit,更改状态status
  817. ], "PRO", 2, $projetc);
  818. ProcessOrder::AddProcess($this->post['token'], [
  819. "order_type" => 'PRO',
  820. "order_code" => $projetc['projectNo'],
  821. "order_id" => $projetc['id'],
  822. "order_status" => 2,"before_status"=>1
  823. ]);
  824. }
  825. }
  826. }
  827. }
  828. }
  829. }
  830. Db::commit();
  831. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  832. }else{
  833. Db::rollback();
  834. return error_show(1006,"反馈失败");
  835. }
  836. }catch (\Exception $e){
  837. Db::rollback();
  838. return error_show(1006,$e->getMessage());
  839. }
  840. }
  841. //反馈商品详情
  842. public function feadinfo(){
  843. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  844. if($bidNo==""){
  845. return error_show(1004,"参数bidNo不能为空");
  846. }
  847. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  848. if($info==false){
  849. return error_show(1004,"未找到商品数据");
  850. }
  851. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  852. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  853. $info['cat_info'] = made($info['cat_id'],[]);
  854. $info['noble_weight'] = $info['good_weight'];
  855. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  856. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  857. if($info['brand_id']!=0){
  858. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  859. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  860. }else{
  861. $info["brand_name"]="";
  862. $info["brand_id"]="";
  863. }
  864. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  865. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  866. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  867. $god=[
  868. "metal_id"=>$info['metal_id'],
  869. "weight"=>$info["good_weight"],
  870. "demo_fee"=>$info["demo_fee"],
  871. "delivery_fee"=>$info["delivery_fee"],
  872. "open_fee"=>$info["open_fee"],
  873. "packing_fee"=>$info["pakge_fee"],
  874. "mark_fee"=>$info["mark_fee"],
  875. "nake_fee"=>$info["nake_fee"],
  876. "cert_fee"=>$info["cert_fee"],
  877. "cost_fee"=>$info["cost_fee"],
  878. "num"=>$bidinfo["num"],
  879. ];
  880. if($info['is_gold_price']==1){
  881. $price = GoldPrice($god, $budget/100);
  882. $info['sale_price'] =round($price,2);
  883. }
  884. $info['specinfo'] = json_decode($info['specinfo'],true);
  885. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  886. if($info['delivery_place']!=""){
  887. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['delivery_place']);
  888. }
  889. $info['delivery_place_cn']=GetAddr(json_encode($place));
  890. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  891. if($info['origin_place']!=""){
  892. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['origin_place']);
  893. }
  894. $info['origin_place_cn']=GetAddr(json_encode($place));
  895. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  896. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  897. $info['bargain'] =$bargain;
  898. $info['good_img'] = explode(',',$info['good_img']);
  899. return app_show(0,"获取成功",$info);
  900. }
  901. //反馈商品编辑
  902. public function feededit(){
  903. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  904. if($bidNo==""){
  905. return error_show(1002,"参数bidNo不能为空");
  906. }
  907. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  908. if($bidinfo==false){
  909. return error_show(1003,"未找到信息数据");
  910. }
  911. if($bidinfo['status']>=5){
  912. return error_show(1004,"咨询单已确认无法修改");
  913. }
  914. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  915. if($zxinfo==false){
  916. return error_show(1003,"未找到信息数据");
  917. }
  918. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  919. if($zx==false){
  920. return error_show(1003,"未找咨询信息数据");
  921. }
  922. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  923. if($pname==""){
  924. return error_show(1002,"参数pname不能为空");
  925. }
  926. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  927. // if($brandid==""){
  928. // return error_show(1002,"参数brandid不能为空");
  929. // }
  930. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  931. if($cat_id==""){
  932. return error_show(1002,"参数cat_id不能为空");
  933. }
  934. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  935. if($specin==""){
  936. return error_show(1003,"参数specinfo不能为空");
  937. }
  938. $specinfo=[];
  939. foreach ($specin as $v){
  940. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  941. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  942. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  943. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  944. $specinfo[]=$v;
  945. }
  946. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  947. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  948. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  949. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  950. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  951. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  952. :"";
  953. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  954. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  955. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  956. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  957. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"0";
  958. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  959. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  960. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  961. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  962. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"0";
  963. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!=""? floatval($this->post['noble_weight']):"0";
  964. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"0";
  965. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"0";
  966. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"0";
  967. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"0";
  968. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  969. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"0";
  970. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"0";
  971. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"0";
  972. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  973. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  974. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  975. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  976. if($delivery_place==''){
  977. return error_show(1002,"参数delivery_place不能为空");
  978. }
  979. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  980. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  981. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  982. $cat_top_list = made($cat_id);
  983. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  984. if ($is_gold_price == 1 && $cat_top_id == 6) {
  985. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  986. ->find();
  987. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  988. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $noble_weight * $gold["price"] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  989. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  990. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  991. $saleprice = $total_fee / (1 - $budget);
  992. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  993. $sale_cost_fee = ( $saleprice- ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $noble_weight - $gold["price"];
  994. }else{
  995. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee*$noble_weight + $pakge_fee +
  996. $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  997. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee/$zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee+$cert_fee +$nake_fee;
  998. }
  999. Db::startTrans();
  1000. try{
  1001. $data=[
  1002. "good_name"=>$pname,
  1003. "brand_id"=>$brandid,
  1004. "cat_id"=>$cat_id,
  1005. "specinfo"=>json_encode($specinfo),
  1006. // "material"=>$material,
  1007. "unit_id"=>$unit_id,
  1008. "cost_desc"=>$cost_desc,
  1009. "work_day"=>$work_day,
  1010. "delivery_day"=>$delivery_day,
  1011. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  1012. "expire_day"=>$expire_day,
  1013. "origin_place"=>$origin_place,
  1014. "supplierNo"=>$supplierNo,
  1015. "pay_way"=>$pay_way,
  1016. "tax"=>$tax,
  1017. "send_way"=>$send_way,
  1018. "metal_id"=>$metal_id,
  1019. "is_gold_price"=>$is_gold_price,
  1020. "config"=>$config,
  1021. "other_config"=>$other_config,
  1022. "weight"=>$weight,
  1023. "good_weight"=>$noble_weight,
  1024. "is_diff"=>$is_diff,
  1025. "demo_fee"=>$demo_fee,
  1026. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  1027. "delivery_fee"=>$delivery_fee,
  1028. "open_fee"=>$open_fee,
  1029. "pakge_fee"=>$pakge_fee,
  1030. "nake_fee"=>$nake_fee,
  1031. "mark_fee"=>$mark_fee,
  1032. "cert_fee"=>$cert_fee,
  1033. "cost_fee"=>$cost_fee,
  1034. "sale_cost_fee"=>$sale_cost_fee,
  1035. "origin_cost_fee"=>$sale_cost_fee,
  1036. "total_fee"=>$total_fee,
  1037. "sale_price"=>$saleprice,
  1038. "origin_price"=>$saleprice,
  1039. "supply_area"=>$supply_area,
  1040. "remark"=>$remark,
  1041. "status"=>0,
  1042. "updatetime"=>date("Y-m-d H:i:s"),
  1043. 'delivery_place' => $delivery_place
  1044. ];
  1045. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1046. if($insert){
  1047. if($zxinfo['bargain_status']==1){
  1048. $zxinfo['bargain_status']=0;
  1049. $infoip =Db::name("consult_info")->save($zxinfo);
  1050. if($infoip==false){
  1051. Db::rollback();
  1052. return error_show(1006,"咨询信息状态更新失败");
  1053. }
  1054. }
  1055. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1056. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1057. if($projectinfo==false){
  1058. Db::rollback();
  1059. return error_show(1006,"未找到项目信息");
  1060. }
  1061. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1062. if($feed==false){
  1063. Db::rollback();
  1064. return error_show(1006,"未找到项目反馈信息");
  1065. }
  1066. $feed['good_name']=$pname;
  1067. $feed['good_type']=$projectinfo['good_type'];
  1068. $feed['cat_id']=$cat_id;
  1069. $feed['sale_price']=$saleprice;
  1070. $feed['origin_price']=$total_fee;
  1071. $feed['updatetime']=date("Y-m-d H:i:s");
  1072. $temp['updatetime']=date("Y-m-d H:i:s");
  1073. $nu = Db::name("project_feedback")->save($feed);
  1074. if($nu==false){
  1075. Db::rollback();
  1076. return error_show(1006,"项目反馈失败");
  1077. }else{
  1078. $old_projectinfo_status = $projectinfo['status'];
  1079. $projectinfo['status']=2;
  1080. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1081. $up = Db::name("project_info")->save($projectinfo);
  1082. if($up){
  1083. //修改状态,添加待办,只记录动作
  1084. ActionLog::logAdd($this->post['token'], [
  1085. "order_code" => $projectinfo['pgNo'],//编码
  1086. "status" => $old_projectinfo_status,//这里的status是之前的值
  1087. "action_remark" => '',//备注
  1088. "action_type" => "status"//新建create,编辑edit,更改状态status
  1089. ], "PRI", 2, $projectinfo);
  1090. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->count();
  1091. if ($count == 0) {
  1092. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1093. $project_id = Db::name("project")->where(["projectNo" => $projectinfo['projectNo'], "status" => 1])->value('id', 0);
  1094. if ($project_id) {
  1095. $proc = Db::name("project")->where(["id" => $project_id])->update(["status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  1096. if ($proc == false) {
  1097. Db::rollback();
  1098. return error_show(1006, "项目反馈失败");
  1099. }else{
  1100. //修改状态,添加待办
  1101. ActionLog::logAdd($this->post['token'], [
  1102. "order_code" => $projectinfo['projectNo'],//项目编码
  1103. "status" => 1,//这里的status是之前的值
  1104. "action_remark" => '',//备注
  1105. "action_type" => "status"//新建create,编辑edit,更改状态status
  1106. ], "PRO", 2, $this->post);
  1107. ProcessOrder::AddProcess($this->post['token'], [
  1108. "order_type" => 'PRO',
  1109. "order_code" => $projectinfo['projectNo'],
  1110. "order_id" => $project_id,
  1111. "order_status" => 2,"before_status"=>1
  1112. ]);
  1113. }
  1114. }
  1115. }
  1116. }
  1117. }
  1118. }
  1119. Db::commit();
  1120. return app_show(0,"编辑成功");
  1121. }else{
  1122. Db::rollback();
  1123. return error_show(1004,"编辑失败");
  1124. }
  1125. }catch (\Exception $e){
  1126. Db::rollback();
  1127. return error_show(1004,$e->getMessage());
  1128. }
  1129. }
  1130. public function bargain_add(){
  1131. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1132. if($bidNo===""){
  1133. return error_show(1004,"参数bidNo不能为空");
  1134. }
  1135. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1136. if($info==false){
  1137. return error_show(1004,"未找到商品数据");
  1138. }
  1139. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1140. if($consult==false){
  1141. return error_show(1004,"未找到咨询数据");
  1142. }
  1143. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1144. if($bargain_price===""){
  1145. return error_show(1004,"参数bargain_price不能为空");
  1146. }
  1147. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1148. if($info['is_gold_price']==1){
  1149. if($cost_price==""){
  1150. return error_show(1004,"参数cost_price不能为空");
  1151. }
  1152. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1153. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1154. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1155. ->find();
  1156. $bargain_price = ($info['demo_fee']/$consult['num']+$info['delivery_fee']+$info['open_fee']/$consult['num']+$info['good_weight'] * $gold["price"] + $cost_price *$info['good_weight']+$info['pakge_fee']+$info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1157. }
  1158. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1159. // if($bargain_reason===""){
  1160. // return error_show(1004,"参数bargain_reason不能为空");
  1161. // }
  1162. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1163. if($infos==false){
  1164. return error_show(1004,"未找到商品数据");
  1165. }
  1166. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1167. return error_show(1004,"咨询单招标未结束或已确认商品");
  1168. }
  1169. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1170. if($token==''){
  1171. return error_show(105,"参数token不能为空");
  1172. }
  1173. $user =GetUserInfo($token);
  1174. if(empty($user)||$user['code']!=0){
  1175. return error_show(1002,"用户数据不存在");
  1176. }
  1177. //新增两个字段
  1178. //议价备注
  1179. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1180. //议价原因id
  1181. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1182. if ($result_info_id != '') {
  1183. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1184. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1185. }
  1186. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1187. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1188. $bargainNo =makeNo("BA");
  1189. Db::startTrans();//::todo 金价 毛利计算
  1190. try{
  1191. $data=[
  1192. "bidsNo"=>$bidNo,
  1193. "infoNo"=>$info['infoNo'],
  1194. "zxNo"=>$info['zxNo'],
  1195. "bargainNo"=>$bargainNo,
  1196. "bargain_type"=>1,
  1197. "bargain_reason"=>$bargain_reason,
  1198. "sale_price"=>$info['sale_price'],
  1199. "cost_before_price"=>$info['sale_cost_fee'],
  1200. "cost_after_price"=>$cost_price,
  1201. "before_rate"=>round(($info['origin_price']-$info['total_fee'])/$info['origin_price'],2),
  1202. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1203. "after_price"=>$bargain_price,
  1204. "exam_info"=>"",
  1205. "status"=>0,
  1206. "is_del"=>0,
  1207. "creater"=>$creater,
  1208. "createrid"=>$createrid,
  1209. "addtime"=>date("Y-m-d H:i:s"),
  1210. "updatetime"=>date("Y-m-d H:i:s"),
  1211. 'bargain_remark'=>$bargain_remark,
  1212. 'result_info_id'=>$result_info_id,
  1213. ];
  1214. $int = Db::name("bargain_order")->insert($data);
  1215. if($int){
  1216. //修改状态,添加待办
  1217. ActionLog::logAdd($this->post['token'], [
  1218. "order_code" => $bargainNo,//咨询单详情编号
  1219. "status" => 0,//这里的status是之前的值
  1220. "action_remark" => '',//备注
  1221. "action_type" => "status"//新建create,编辑edit,更改状态status
  1222. ], "YJD", $data['status'], $data);
  1223. ProcessOrder::AddProcess($this->post['token'], [
  1224. "order_type" => 'YJD',
  1225. "order_code" => $bargainNo,
  1226. "order_id" =>Db::name("bargain_order")->getLastInsID(),
  1227. "order_status" =>0,"before_status"=>0
  1228. ]);
  1229. $odlstatus=$info['status'];
  1230. $info['status']=3;
  1231. $info['updatetime']=date("Y-m-d H:i:s");
  1232. $up =Db::name("consult_bids")->save($info);
  1233. if($up){
  1234. //修改状态,添加待办
  1235. ActionLog::logAdd($this->post['token'], [
  1236. "order_code" => $bidNo,//咨询单详情编号
  1237. "status" => $odlstatus,//这里的status是之前的值
  1238. "action_remark" => '',//备注
  1239. "action_type" => "status"//新建create,编辑edit,更改状态status
  1240. ], "FKD", $info['status'], $info);
  1241. $old_infos_status = $infos['status'];
  1242. $infos['status']=3;
  1243. $infos['updatetime']=date("Y-m-d H:i:s");
  1244. $ups =Db::name("consult_info")->save($infos);
  1245. if($ups){
  1246. //修改状态,添加待办
  1247. ActionLog::logAdd($this->post['token'], [
  1248. "order_code" => $infos['infoNo'],//咨询单详情编号
  1249. "status" => $old_infos_status,//这里的status是之前的值
  1250. "action_remark" => '',//备注
  1251. "action_type" => "status"//新建create,编辑edit,更改状态status
  1252. ], "ZXD", $infos['status'], $infos);
  1253. Db::commit();
  1254. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1255. }
  1256. }
  1257. }
  1258. Db::rollback();
  1259. return error_show(1004,"议价单新建失败");
  1260. }catch (\Exception $e){
  1261. Db::rollback();
  1262. return error_show(1004,$e->getMessage());
  1263. }
  1264. }
  1265. //选择商品
  1266. public function bids_check(){
  1267. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1268. if($bidNo===""){
  1269. return error_show(1004,"参数bidNo不能为空");
  1270. }
  1271. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1272. if($info==false){
  1273. return error_show(1004,"未找到商品数据");
  1274. }
  1275. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1276. if($infos==false){
  1277. return error_show(1004,"未找到商品数据");
  1278. }
  1279. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1280. return error_show(1004,"咨询单招标未结束或已确认商品");
  1281. }
  1282. Db::startTrans();
  1283. try {
  1284. $oldstattus=$info['status'];
  1285. $info['status']=6;
  1286. $info['updatetime']=date("Y-m-d H:i:s");
  1287. $bids = Db::name("consult_bids")->save($info);
  1288. if($bids){
  1289. //修改状态,添加待办
  1290. ActionLog::logAdd($this->post['token'], [
  1291. "order_code" =>$bidNo,//咨询单详情编号
  1292. "status" => $oldstattus,//这里的status是之前的值
  1293. "action_remark" => '',//备注
  1294. "action_type" => "status"//新建create,编辑edit,更改状态status
  1295. ], "FKD", $info['status'], $info);
  1296. $old_infos_status = $infos['status'];
  1297. $infos['status']=4;
  1298. $infos['updatetime']=date("Y-m-d H:i:s");
  1299. $se = Db::name("consult_info")->save($infos);
  1300. if($se){
  1301. //修改状态,添加待办
  1302. ActionLog::logAdd($this->post['token'], [
  1303. "order_code" => $infos['infoNo'],//咨询单详情编号
  1304. "status" => $old_infos_status,//这里的status是之前的值
  1305. "action_remark" => '',//备注
  1306. "action_type" => "status"//新建create,编辑edit,更改状态status
  1307. ], "ZXD", $infos['status'], $infos);
  1308. Db::commit();
  1309. return app_show(0,"商品确定成功");
  1310. }
  1311. }
  1312. Db::rollback();
  1313. return error_show(1004,"商品确认失败");
  1314. }catch (\Exception $e){
  1315. Db::rollback();
  1316. return error_show(1004,$e->getMessage());
  1317. }
  1318. }
  1319. //议价审核
  1320. /**
  1321. * status:
  1322. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1323. */
  1324. public function bargain_status(){
  1325. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1326. if($bargainNo===""){
  1327. return error_show(1004,"参数bargainNo不能为空");
  1328. }
  1329. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1330. if($info==false){
  1331. return error_show(1004,"未找到议价数据");
  1332. }
  1333. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1334. if($bids==false){
  1335. return error_show(1004,"未找到商品数据");
  1336. }
  1337. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1338. if($coninfo==false){
  1339. return error_show(1004,"未找到咨询单数据");
  1340. }
  1341. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1342. if($status===''){
  1343. return error_show(1005,"参数status不能为空");
  1344. }
  1345. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1346. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1347. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1348. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1349. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1350. if($bids['is_gold_price']==1){
  1351. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1352. ->find();
  1353. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1354. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1355. $total_fe= $bids['demo_fee'] / $coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] / $coninfo['num'] +
  1356. $bids['good_weight']*$gold["price"] +$bids['cost_fee']*$bids['good_weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee'];
  1357. $saleprice =$total_fe / (1 - $budget);
  1358. $rate_price = $total_fe / (1 - $rate);
  1359. $money_price =$total_fe / (1 - $money_rate);
  1360. $lower_price =$total_fe / (1 - $lower_rate);
  1361. }else{
  1362. $total_fe= $bids['demo_fee']/$coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] /
  1363. $coninfo['num']+$bids['cost_fee']*$bids['good_weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'];
  1364. if($bids['nake_fee']!=0){
  1365. $saleprice = ($total_fe)/ (1 - $budget);
  1366. $rate_price = ($total_fe)/ (1 - $rate);
  1367. $money_price =($total_fe)/ (1 - $money_rate);
  1368. $lower_price = ($total_fe) / (1 - $lower_rate);
  1369. }else{
  1370. $saleprice = $total_fe / (1 - $budget);
  1371. $rate_price =$total_fe/ (1 - $rate);
  1372. $money_price =$total_fe / (1 - $money_rate);
  1373. $lower_price = $total_fe/ (1 - $lower_rate);
  1374. }
  1375. }
  1376. $ra_status = $info['status'];
  1377. if($status==1){
  1378. if($info['status']==0){
  1379. if($info['after_price']<$rate_price){
  1380. $info['status']=2;
  1381. }else{
  1382. $info['status']=1;
  1383. }
  1384. }elseif($info['status']==2){
  1385. $info['status']=4;
  1386. }elseif($info['status']==4||$info['status']==5){
  1387. if($info['after_price']<$money_price){
  1388. $info['status']=7;
  1389. }else{
  1390. $info['status']=6;
  1391. }
  1392. }elseif($info['status']==7){
  1393. $info['lower_price'] =$lower_price;
  1394. if($info['after_price']<$lower_price){
  1395. $info['status']=10;
  1396. }else{
  1397. $info['status']=9;
  1398. }
  1399. }
  1400. }else{
  1401. if($info['status']==0){
  1402. $info['status']=3;
  1403. }elseif($info['status']==2){
  1404. $info['status']=4;
  1405. }elseif($info['status']==4||$info['status']==5){
  1406. $info['status']=8;
  1407. }elseif($info['status']==7){
  1408. $info['lower_price'] =$lower_price;
  1409. $info['status']=11;
  1410. }
  1411. }
  1412. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1413. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1414. if($token==''){
  1415. return error_show(105,"参数token不能为空");
  1416. }
  1417. $user =GetUserInfo($token);
  1418. if(empty($user)||$user['code']!=0){
  1419. return error_show(1002,"用户数据不存在");
  1420. }
  1421. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1422. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1423. Db::startTrans();
  1424. try{
  1425. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1426. $examinfo[]=["status"=>$status,"info_status"=>$ra_status,"remark"=>$remark,"createrid"=>$createrid,
  1427. "creater"=>$creater];
  1428. // $info['status'] =$status;
  1429. $info['remark'] =$remark;
  1430. $info['exam_info']=json_encode($examinfo) ;
  1431. $info['updatetime'] =date("Y-m-d H:i:s");
  1432. $up =Db::name("bargain_order")->save($info);
  1433. if($up){
  1434. //修改状态,添加待办
  1435. ActionLog::logAdd($this->post['token'], [
  1436. "order_code" => $bargainNo,//咨询单详情编号
  1437. "status" =>$ra_status,//这里的status是之前的值
  1438. "action_remark" => '',//备注
  1439. "action_type" => "status"//新建create,编辑edit,更改状态status
  1440. ], "YJD", $info['status'], $info);
  1441. $process=["order_code"=>$bargainNo,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'YJD',"before_status"=>$ra_status];
  1442. ProcessOrder::AddProcess($token,$process);
  1443. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1444. $bidstatus=$bids['status'];
  1445. $bids['status']=5;
  1446. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1447. $bids['sale_price']=$info['after_price'];
  1448. if($bids['is_gold_price']==1){
  1449. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1450. // ->find();
  1451. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1452. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1453. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1454. $bids['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1455. }
  1456. }
  1457. $bids['updatetime']=date("Y-m-d H:i:s");
  1458. $up =Db::name("consult_bids")->save($bids);
  1459. if($up==false){
  1460. Db::rollback();
  1461. return error_show(1004,"数据更新失败");
  1462. }
  1463. ActionLog::logAdd($this->post['token'], [
  1464. "order_code" => $info["bidsNo"],//咨询单详情编号
  1465. "status" => $bidstatus,//这里的status是之前的值
  1466. "action_remark" => '',//备注
  1467. "action_type" => "status"//新建create,编辑edit,更改状态status
  1468. ], "FKD", $bids['status'], $bids);
  1469. }
  1470. Db::commit();
  1471. return app_show(0,"更新成功");
  1472. }
  1473. }catch (\Exception $e){
  1474. Db::rollback();
  1475. return error_show(1004,$e->getMessage());
  1476. }
  1477. }
  1478. public function bargain_info(){
  1479. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1480. if($bargainNo===""){
  1481. return error_show(1004,"参数bargainNo不能为空");
  1482. }
  1483. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1484. if($info==false){
  1485. return error_show(1004,"未找到议价数据");
  1486. }
  1487. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1488. if($bidinfos==false){
  1489. return error_show(1004,"未找到商品数据");
  1490. }
  1491. $consultinfos = Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])
  1492. ->find();
  1493. if($consultinfos==false){
  1494. return error_show(1004,"未找到咨询商品数据");
  1495. }
  1496. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1497. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1498. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1499. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1500. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1501. $info['before_rate'] =round($info['before_rate']*100,2);
  1502. $info['sale_price'] =round($bidinfos['origin_price'],2);
  1503. $info['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1504. $info['after_rate'] = round($info['after_rate']*100,2);
  1505. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
  1506. if($bidinfos['brand_id']!=0){
  1507. $info['brand_id'] = $bidinfos['brand_id'];
  1508. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1509. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1510. }else{
  1511. $info["brand_name"]="";
  1512. $info["brand_id"]="";
  1513. }
  1514. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1515. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1516. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1517. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1518. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1519. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1520. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1521. $info['budget'] =$budget;
  1522. $god=[
  1523. "metal_id"=>$bidinfos['metal_id'],
  1524. "weight"=>$bidinfos["good_weight"],
  1525. "demo_fee"=>$bidinfos["demo_fee"],
  1526. "delivery_fee"=>$bidinfos["delivery_fee"],
  1527. "open_fee"=>$bidinfos["open_fee"],
  1528. "packing_fee"=>$bidinfos["pakge_fee"],
  1529. "mark_fee"=>$bidinfos["mark_fee"],
  1530. "nake_fee"=>$bidinfos["nake_fee"],
  1531. "cert_fee"=>$bidinfos["cert_fee"],
  1532. "cost_fee"=>$bidinfos["cost_fee"],
  1533. "num"=>$bidinfoe["num"],
  1534. ];
  1535. $info['gold_price']=0;
  1536. $info['noble_weight']=$bidinfos['good_weight'];
  1537. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1538. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1539. ->find();
  1540. $info['gold_price'] =$gold['price'];
  1541. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num'] + $bidinfos['good_weight']* $gold["price"] +$bidinfos['cost_fee']*$bidinfos['good_weight'] + $bidinfos['pakge_fee'] +$bidinfos['mark_fee'] + $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1542. }else{
  1543. if($bidinfos['nake_fee']!=0){
  1544. $lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1545. }else{
  1546. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'])/ (1 - $lower_rate);
  1547. }
  1548. }
  1549. $info['cost_desc'] =$bidinfos['cost_desc'];
  1550. $info['work_day'] =$bidinfos['work_day'];
  1551. $info['delivery_day'] =$bidinfos['delivery_day'];
  1552. $info['expire_day'] =$bidinfos['expire_day'];
  1553. $info['origin_place'] =$bidinfos['origin_place'];
  1554. $info['origin_addr'] ="";
  1555. if($bidinfos['origin_place']!=''){
  1556. $code = explode(",",$bidinfos['origin_place']);
  1557. $temp=[];
  1558. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1559. $temp['city_code']=isset($code[1])?$code[1]:"";
  1560. $temp['area_code']=isset($code[2])?$code[2]:"";
  1561. $addr= GetAddr(json_encode($temp));
  1562. $info['origin_addr'] = $addr;
  1563. }
  1564. $info['supplierNo'] =$bidinfos['supplierNo'];
  1565. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1566. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1567. $info['pay_way'] =$bidinfos['pay_way'];
  1568. $info['tax'] =$bidinfos['tax'];
  1569. $info['send_way'] =$bidinfos['send_way'];
  1570. $info['metal_id'] =$bidinfos['metal_id'];
  1571. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1572. $info['config'] =$bidinfos['config'];
  1573. $info['other_config'] =$bidinfos['other_config'];
  1574. $info['weight'] =$bidinfos['weight'];
  1575. $info['good_weight'] =$bidinfos['good_weight'];
  1576. $info['is_diff'] =$bidinfos['is_diff'];
  1577. $info['demo_fee'] =$bidinfos['demo_fee'];
  1578. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1579. $info['open_fee'] =$bidinfos['open_fee'];
  1580. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1581. $info['nake_fee'] =$bidinfos['nake_fee'];
  1582. $info['mark_fee'] =$bidinfos['mark_fee'];
  1583. $info['cert_fee'] =$bidinfos['cert_fee'];
  1584. $info['cost_fee'] =$bidinfos['cost_fee'];
  1585. $info['total_fee'] =$bidinfos['total_fee'];
  1586. $info['supply_area'] =$bidinfos['supply_area'];
  1587. $info['remark'] =$bidinfos['remark'];
  1588. $info['is_addrs'] =$consultinfos['is_addrs'];
  1589. $info['is_custom'] =$consultinfos['is_custom'];
  1590. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1591. // $info['sale_price'] =round($bidinfos['sale_price'],2);//议价前价格
  1592. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1593. if($info['status']==7){
  1594. $info['lower_price'] =round($lower_price,2);
  1595. }
  1596. //获取议价原因
  1597. if ($info['result_info_id'] != 0) {
  1598. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1599. } else {
  1600. $info['result_info'] = '';
  1601. }
  1602. return app_show(0,"获取成功",$info);
  1603. }
  1604. public function bidlist(){
  1605. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1606. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1607. $where=[['is_del',"=",0]];
  1608. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1609. if ($zxNo !== "") {
  1610. $where[] = ['zxNo','like','%'.$zxNo.'%'];
  1611. }
  1612. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1613. if ($infoNo !== "") {
  1614. $where[] = ['infoNo','like','%'.$infoNo.'%'];
  1615. }
  1616. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1617. if ($bidNo !== "") {
  1618. $where[] = ['bidNo','like','%'.$bidNo.'%'];
  1619. }
  1620. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1621. if ($pgNo !== "") {
  1622. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1623. $where[] = ['infoNo','in',$bidinfo];
  1624. }
  1625. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1626. if ($bargain_status !== "") {
  1627. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1628. $where[] = ['infoNo','in',$bidinfo];
  1629. }
  1630. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1631. if ($projectNo !== "") {
  1632. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1633. ("zxNo");
  1634. $where[] = ['zxNo','in',$zxlist];
  1635. }
  1636. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1637. if($is_own==1){
  1638. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1639. if($token==""){
  1640. return error_show(101,'token不能为空');
  1641. }
  1642. $apply_id =GetUserInfo($token);
  1643. if(empty($apply_id)||$apply_id['code']!=0){
  1644. return error_show(1002,"申请人数据不存在");
  1645. }
  1646. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1647. $where[]=['createrid',"=",$rm];
  1648. }
  1649. $count = Db::name('consult_bids')->where($where)->count();
  1650. $total = ceil($count / $size);
  1651. $page = $page >= $total ? $total : $page;
  1652. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1653. $data=[];
  1654. foreach ($list as $value){
  1655. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1656. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1657. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1658. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1659. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1660. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1661. if($value['brand_id']!=0){
  1662. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1663. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1664. }else{
  1665. $value["brand_name"]="";
  1666. $value["brand_id"]="";
  1667. }
  1668. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1669. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1670. $god=[
  1671. "metal_id"=>$value['metal_id'],
  1672. "weight"=>$value["good_weight"],
  1673. "demo_fee"=>$value["demo_fee"],
  1674. "delivery_fee"=>$value["delivery_fee"],
  1675. "open_fee"=>$value["open_fee"],
  1676. "packing_fee"=>$value["pakge_fee"],
  1677. "mark_fee"=>$value["mark_fee"],
  1678. "nake_fee"=>$value["nake_fee"],
  1679. "cert_fee"=>$value["cert_fee"],
  1680. // "cost_fee"=>$value["cost_fee"],
  1681. "cost_fee"=>$value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_cost_fee"]: $value["cost_fee"],
  1682. //暂时注掉,搞不清楚原因@吴广广
  1683. "num"=>$bidinfo["num"],
  1684. ];
  1685. $top_cat = made($value['cat_id']);
  1686. $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:0;
  1687. if($value['is_gold_price']==1 && $top_cat_id==6 ){
  1688. $price = GoldPrice($god, $budget/100);
  1689. $value['sale_price'] = round($price,2);
  1690. }
  1691. $value['cost_fee'] =$value['origin_cost_fee'];
  1692. $value['specinfo'] = json_decode($value['specinfo'],true);
  1693. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1694. $value['bargain_status']=$bidinfo['bargain_status'];
  1695. //reject驳回原因,status==5表示驳回
  1696. $value['reject']=[];
  1697. if ($value['status'] >=5) {
  1698. $value['reject'] = Db::name('bargain_order')
  1699. ->field('id,remark,status')
  1700. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1701. ->whereIn('status', [3,8,11])->order("id desc")
  1702. ->find();
  1703. }
  1704. //产地
  1705. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1706. if($value['delivery_place']!=""){
  1707. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['delivery_place']);
  1708. }
  1709. $value['delivery_place_cn']=GetAddr(json_encode($place));
  1710. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1711. if($value['origin_place']!=""){
  1712. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['origin_place']);
  1713. }
  1714. $value['origin_addr']=GetAddr(json_encode($place));
  1715. // if($value['origin_place']!=''){
  1716. // $code = explode(",",$value['origin_place']);
  1717. // $temp=[];
  1718. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  1719. // $temp['city_code']=isset($code[1])?$code[1]:"";
  1720. // $temp['area_code']=isset($code[2])?$code[2]:"";
  1721. // $addr= GetAddr(json_encode($temp));
  1722. // $value['origin_addr'] = $addr;
  1723. // }
  1724. $data[] = $value;
  1725. }
  1726. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1727. }
  1728. public function feedlist(){
  1729. $where=[['is_del',"=",0]];
  1730. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1731. if ($zxNo !== "") {
  1732. $where[] = ['zxNo','=',$zxNo];
  1733. }
  1734. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1735. if ($infoNo !== "") {
  1736. $where[] = ['infoNo','=',$infoNo];
  1737. }
  1738. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1739. if ($bidNo !== "") {
  1740. $where[] = ['bidNo','=',$bidNo];
  1741. }
  1742. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1743. if ($projectNo !== "") {
  1744. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1745. ("zxNo");
  1746. $where[] = ['zxNo','in',$zxlist];
  1747. }
  1748. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1749. if($token==''){
  1750. return error_show(102,"参数token不能为空");
  1751. }
  1752. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1753. if($is_own==1){
  1754. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1755. if($token==""){
  1756. return error_show(101,'token不能为空');
  1757. }
  1758. $apply_id =GetUserInfo($token);
  1759. if(empty($apply_id)||$apply_id['code']!=0){
  1760. return error_show(1002,"申请人数据不存在");
  1761. }
  1762. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1763. $where[]=['createrid',"=",$rm];
  1764. }
  1765. $list =Db::name('consult_bids')->where($where)->select();
  1766. $data=[];
  1767. foreach ($list as $value){
  1768. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1769. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1770. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1771. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1772. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1773. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1774. if($value['brand_id']!=0){
  1775. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1776. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1777. }else{
  1778. $value["brand_name"]="";
  1779. $value["brand_id"]="";
  1780. }
  1781. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1782. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1783. $god=[
  1784. "metal_id"=>$value['metal_id'],
  1785. "weight"=>$value["good_weight"],
  1786. "demo_fee"=>$value["demo_fee"],
  1787. "delivery_fee"=>$value["delivery_fee"],
  1788. "open_fee"=>$value["open_fee"],
  1789. "packing_fee"=>$value["pakge_fee"],
  1790. "mark_fee"=>$value["mark_fee"],
  1791. "nake_fee"=>$value["nake_fee"],
  1792. "cert_fee"=>$value["cert_fee"],
  1793. "cost_fee"=>$value["cost_fee"],
  1794. "num"=>$bidinfo["num"],
  1795. ];
  1796. if ($value['is_gold_price'] == 1 ) {
  1797. $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1798. ->find();
  1799. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1800. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1801. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num'] +$value["good_weight"] *$gold["price"] +
  1802. $value["cost_fee"] * $value["good_weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
  1803. // //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1804. // $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  1805. }else{
  1806. if($value["nake_fee"]){
  1807. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"])/ (1 - $budget);
  1808. }else{
  1809. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) /
  1810. (1 - $budget);
  1811. }
  1812. }
  1813. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1814. $value['specinfo'] = json_decode($value['specinfo'],true);
  1815. $value['bargain_status']=$bidinfo['bargain_status'];
  1816. $data[]=$value;
  1817. }
  1818. return app_show(0,"获取成功",$data);
  1819. }
  1820. public function bragain_list(){
  1821. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1822. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1823. $where=[['is_del',"=",0]];
  1824. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1825. if($bidsNo!=""){
  1826. $where[]=["bidsNo","=",$bidsNo];
  1827. }
  1828. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1829. if ($zxNo !== "") {
  1830. $where[] = ['zxNo','=',$zxNo];
  1831. }
  1832. $bargainNo = isset($this->post['bargainNo']) && $this->post['bargainNo'] !== "" ? trim($this->post['bargainNo']) : "";
  1833. if ($bargainNo !== "") {
  1834. $where[] = ['bargainNo','=',$bargainNo];
  1835. }
  1836. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1837. if ($status!== "") {
  1838. $where[] = ['status','=',$status];
  1839. }
  1840. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1841. if ($infoNo !== "") {
  1842. $where[] = ['infoNo','=',$infoNo];
  1843. }
  1844. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1845. if ($projectNo !== "") {
  1846. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1847. ("zxNo");
  1848. $where[] = ['zxNo','in',$zxlist];
  1849. }
  1850. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1851. if ($pgNo !== "") {
  1852. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1853. $where[] = ['infoNo','in',$bidinfo];
  1854. }
  1855. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1856. $end= isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1857. if($start!=""){
  1858. $where[]=["addtime",">=",date("Y-m-d H:i:s",strtotime($start))];
  1859. }
  1860. if($end!=""){
  1861. $where[]=["addtime","<=",date("Y-m-d H:i:s",strtotime($end))];
  1862. }
  1863. $role=$this->checkRole();
  1864. if(!empty($role['write'])){
  1865. $where[]=["createrid","in",$role['write']];
  1866. }
  1867. $count=Db::name("bargain_order")->where($where)->count();
  1868. $total = ceil($count / $size);
  1869. $page = $page >= $total ? $total : $page;
  1870. $list =Db::name('bargain_order')->where($where)->page($page,$size)->order('addtime','desc')->select();
  1871. $data=[];
  1872. foreach ($list as $value){
  1873. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1874. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1875. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1876. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1877. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1878. if($bidinfos['brand_id']!=0){
  1879. $value['brand_id'] = $bidinfos['brand_id'];
  1880. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1881. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1882. }else{
  1883. $value["brand_name"]="";
  1884. $value["brand_id"]="";
  1885. }
  1886. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1887. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1888. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1889. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1890. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1891. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1892. $value['budget'] =$budget;
  1893. $god=[
  1894. "metal_id"=>$bidinfos['metal_id'],
  1895. "weight"=>$bidinfos["good_weight"],
  1896. "demo_fee"=>$bidinfos["demo_fee"],
  1897. "delivery_fee"=>$bidinfos["delivery_fee"],
  1898. "open_fee"=>$bidinfos["open_fee"],
  1899. "packing_fee"=>$bidinfos["pakge_fee"],
  1900. "mark_fee"=>$bidinfos["mark_fee"],
  1901. "nake_fee"=>$bidinfos["nake_fee"],
  1902. "cert_fee"=>$bidinfos["cert_fee"],
  1903. "cost_fee"=>$bidinfos["cost_fee"],
  1904. "num"=>$bidinfoe["num"],
  1905. ];
  1906. // if($bidinfos['is_gold_price']==1){
  1907. // $price = GoldPrice($god, $budget/100);
  1908. // }else{
  1909. // $price = GoodPrice($god, $budget/100);
  1910. // }
  1911. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1912. $value['sale_price'] =round($bidinfos['origin_price'],2);
  1913. $value['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1914. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1915. $data[]=$value;
  1916. }
  1917. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  1918. }
  1919. public function crontablist(){
  1920. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1921. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1922. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  1923. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1924. if ($zxNo !== "") {
  1925. $where[] = ['a.zxNo','=',$zxNo];
  1926. }
  1927. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  1928. if ($salesman !== "") {
  1929. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  1930. $where[]= ["b.salesman",'like',"%$salesman%"];
  1931. }
  1932. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  1933. if ($cpName !== "") {
  1934. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  1935. $where[]= ["a.good_Name",'like',"%$cpName%"];
  1936. }
  1937. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  1938. if ($khNo !== "") {
  1939. // $where['khNo'] = $khNo;
  1940. $where[]= ["b.khNo",'like',"%$khNo%"];
  1941. }
  1942. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  1943. if ($start !="") {
  1944. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  1945. $where[]= ["a.addtime",'>=',$start];
  1946. }
  1947. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  1948. if($end !=""){
  1949. $where[]= ["a.addtime",'<=',$end];
  1950. }
  1951. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  1952. if ($status !== "") {
  1953. $where[]= ["a.status",'=',$status];
  1954. }
  1955. // $role=$this->checkRole();
  1956. // if(!empty($role['platform']) ){
  1957. // $where[]=["b.platform_code","in",$role['platform']];
  1958. // }
  1959. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  1960. ->count();
  1961. $total = ceil($count / $size);
  1962. $page = $page >= $total ? $total : $page;
  1963. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  1964. ->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();
  1965. $data=[];
  1966. foreach ($list as $value){
  1967. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1968. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  1969. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  1970. $value['khname']="";
  1971. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  1972. true):[];
  1973. if($value['khNo']!==""){
  1974. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  1975. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  1976. }
  1977. $consult =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"createrid"=>$this->uid,"is_del"=>0])
  1978. ->find();
  1979. $value['is_feed'] =$consult==false?0:1;
  1980. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1981. $data[]=$value;
  1982. }
  1983. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1984. }
  1985. //复制上面的bidlist方法,只更改排序方式
  1986. public function bidlistCopy()
  1987. {
  1988. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  1989. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  1990. $where = [['is_del', "=", 0]];
  1991. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1992. if ($zxNo !== "") {
  1993. $where[] = ['zxNo', 'like', '%' . $zxNo . '%'];
  1994. }
  1995. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1996. if ($infoNo !== "") {
  1997. $where[] = ['infoNo', 'like', '%' . $infoNo . '%'];
  1998. }
  1999. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  2000. if ($bidNo !== "") {
  2001. $where[] = ['bidNo', 'like', '%' . $bidNo . '%'];
  2002. }
  2003. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  2004. if ($pgNo !== "") {
  2005. $bidinfo = Db::name("consult_info")->where([["pgNo", "=", $pgNo], ["is_del", "=", 0]])->column("infoNo");
  2006. $where[] = ['infoNo', 'in', $bidinfo];
  2007. }
  2008. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  2009. if ($bargain_status !== "") {
  2010. $bidinfo = Db::name("consult_info")->where([["bargain_status", "=", $bargain_status], ["is_del", "=", 0]])->column("infoNo");
  2011. $where[] = ['infoNo', 'in', $bidinfo];
  2012. }
  2013. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  2014. if ($projectNo !== "") {
  2015. $zxlist = Db::name("consult_order")->where(["projectNo" => $projectNo, "is_del" => 0, "is_project" => 1])->column
  2016. ("zxNo");
  2017. $where[] = ['zxNo', 'in', $zxlist];
  2018. }
  2019. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  2020. if ($is_own == 1) {
  2021. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  2022. if ($token == "") {
  2023. return error_show(101, 'token不能为空');
  2024. }
  2025. $apply_id = GetUserInfo($token);
  2026. if (empty($apply_id) || $apply_id['code'] != 0) {
  2027. return error_show(1002, "申请人数据不存在");
  2028. }
  2029. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2030. $where[] = ['createrid', "=", $rm];
  2031. }
  2032. $count = Db::name('consult_bids')->where($where)->count();
  2033. $total = ceil($count / $size);
  2034. $page = $page >= $total ? $total : $page;
  2035. $list = Db::name('consult_bids')->where($where)->page($page, $size)->order('addtime', 'desc')->select()->toArray();
  2036. $data = [];
  2037. foreach ($list as $value) {
  2038. $catinfo = Db::name("cat")->where(["id" => $value['cat_id']])->find();
  2039. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  2040. $unit = Db::name("unit")->where(["id" => $value['unit_id']])->find();
  2041. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  2042. $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  2043. $value['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  2044. if ($value['brand_id'] != 0) {
  2045. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  2046. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  2047. } else {
  2048. $value["brand_name"] = "";
  2049. $value["brand_id"] = "";
  2050. }
  2051. $bidinfo = Db::name("consult_info")->where(["infoNo" => $value["infoNo"]])->find();
  2052. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] : 0;
  2053. $god = [
  2054. "metal_id" => $value['metal_id'],
  2055. "weight" => $value["good_weight"],
  2056. "demo_fee" => $value["demo_fee"],
  2057. "delivery_fee" => $value["delivery_fee"],
  2058. "open_fee" => $value["open_fee"],
  2059. "packing_fee" => $value["pakge_fee"],
  2060. "mark_fee" => $value["mark_fee"],
  2061. "nake_fee" => $value["nake_fee"],
  2062. "cert_fee" => $value["cert_fee"],
  2063. "cost_fee" => $value["sale_cost_fee"]!=$value["origin_cost_fee"] ? $value["sale_cost_fee"] : $value["cost_fee"],
  2064. "num" => $bidinfo["num"],
  2065. ];
  2066. if ($value['is_gold_price'] == 1) {
  2067. $price = GoldPrice($god, $budget / 100);
  2068. $value['sale_price'] = round($price, 2);
  2069. }
  2070. $value['cost_fee'] = $value['origin_cost_fee'];
  2071. $value['specinfo'] = json_decode($value['specinfo'], true);
  2072. $value['metal_name'] = isset($value['metal_id']) && $value['metal_id'] != 0 ? $this->noble[$value['metal_id']] : "";
  2073. $value['bargain_status'] = $bidinfo['bargain_status'];
  2074. //reject驳回原因,status==5表示驳回
  2075. $value['reject'] = [];
  2076. if ($value['status'] >= 5) {
  2077. $value['reject'] = Db::name('bargain_order')
  2078. ->field('id,remark,status')
  2079. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  2080. ->whereIn('status', [3, 8, 11])->order("id desc")
  2081. ->find();
  2082. }
  2083. //产地
  2084. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2085. if ($value['delivery_place'] != "") {
  2086. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['delivery_place']);
  2087. }
  2088. $value['delivery_place_cn'] = GetAddr(json_encode($place));
  2089. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2090. if ($value['origin_place'] != "") {
  2091. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['origin_place']);
  2092. }
  2093. $value['origin_addr'] = GetAddr(json_encode($place));
  2094. // if($value['origin_place']!=''){
  2095. // $code = explode(",",$value['origin_place']);
  2096. // $temp=[];
  2097. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  2098. // $temp['city_code']=isset($code[1])?$code[1]:"";
  2099. // $temp['area_code']=isset($code[2])?$code[2]:"";
  2100. // $addr= GetAddr(json_encode($temp));
  2101. // $value['origin_addr'] = $addr;
  2102. // }
  2103. $data[] = $value;
  2104. }
  2105. return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  2106. }
  2107. }