Consult.php 139 KB

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