Consult.php 153 KB

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