Consult.php 152 KB

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