Consult.php 155 KB

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