Consult.php 152 KB

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