Consult.php 148 KB

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