Consult.php 146 KB

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