Consult.php 149 KB

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