Consult.php 138 KB

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