Consult.php 134 KB

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