Consult.php 149 KB

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