Consult.php 140 KB

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