Consult.php 148 KB

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