Consult.php 148 KB

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