Consult.php 146 KB

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