1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\ActionLog;
- use app\admin\model\ConsultBids;use app\admin\model\ConsultInfo;use app\admin\model\ConsultTemp;use app\admin\model\DataGroup as DataGroupModel;
- use app\admin\model\GoodTax;use app\admin\model\ProcessOrder;
- use app\model\TaxCategory;use think\App;
- use think\facade\Db;
- use think\facade\Validate;
- //竞价单(咨询单)
- class Consult extends Base
- {
- public $noble=[];
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->noble =\think\facade\Config::get("noble");
- }
- public function conlist(){
- $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
- $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
- $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
- $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
- if ($infoNo !== "") {
- $where[] = ['a.infoNo','like','%'.$infoNo.'%'];
- }
- $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
- if ($salesman !== "") {
- //$where["salesman"] =Db::Raw("like '%$salesman%'");
- $where[]= ["b.salesman",'like',"%$salesman%"];
- }
- $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
- if ($cpName !== "") {
- //$where["cpName"]= Db::Raw("like '%$cpName%'");
- $where[]= ["a.good_Name",'like',"%$cpName%"];
- }
- $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
- if ($khNo !== "") {
- // $where['khNo'] = $khNo;
- $where[]= ["b.khNo",'like',"%$khNo%"];
- }
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
- if ($companyNo !== "") {
- // $where['khNo'] = $khNo;
- $where[]= ["b.companyNo",'like',"%$companyNo%"];
- }
- $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] !== "" ? trim($this->post['relaComNo']) : "";
- if ($relaComNo !== "") $where[]= ['b.companyNo','=',$relaComNo];
- $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
- if ($start !="") {
- //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
- $where[]= ["a.addtime",'>=',$start.' 00:00:00'];
- }
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
- if($end !=""){
- $where[]= ["a.addtime",'<=',$end." 23:59:59"];
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
- if ($status !== "") {
- $where[]= ["a.status",'=',$status];
- }
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
- if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
- $role = $this->checkDataShare();
- $hand = resign_hand_user($this->uid,0);
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部]));
- $where[] = ['b.createrid', 'in',$arr];
- }
- $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('consult_info')
- ->alias("a")
- ->leftJoin("consult_order b", "a.zxNo=b.zxNo")
- ->where($where)
- ->page($page, $size)
- ->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")
- ->order("a.id desc")
- ->select()
- ->toArray();
- $all_createrid = array_column($list,'createrid');
- $item = get_company_name_by_uid($all_createrid);
- $userCommon = \app\admin\common\User::getIns();
- $names = $userCommon->handle('getCodeAndName', ['code' =>array_unique(array_merge(array_column($list,"khNo"),array_column($list,"companyNo")))]);
- $brand = Db::name("brand")
- ->where(['id'=>array_column($list,'brand_id')])
- ->column('brand_name','id');
- $data=[];
- foreach ($list as $value){
- $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
- $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'], true):[];
- $value['brand_name']= $brand[$value['brand_id']]??'';//isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
- $value['khname']="";
- if($value['khNo']!==""){
- $value['khname']=$names['data'][$value['khNo']]??"";
- }
- $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
- $value['company_name'] = $item[$value['createrid']]??'';
- //是否具有编辑权限
- $value['is_allow_update'] = 0;
- if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
- $value['companyName'] = $names['data'][$value['companyNo']]??'';
- $data[]=$value;
- }
- return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
- }
- public function info(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
- if($id==""){
- return error_show(1002,"咨询单编号不能为空");
- }
- $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
- $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
- $fo['can']=$in;
- if(empty($fo)){
- return error_show(1002,"未找到咨询单编号");
- }else{
- return app_show(0,"获取成功",$fo);
- }
- }
- public function delete(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
- $de = Db::name('consult_bids')->where(['id'=>$id,'is_del'=>0])->find();
- if($de==false){
- return error_show(1002,'咨询商品信息未找到');
- }
- if($de['status']>1) return error_show(1002,'咨询商品信息当前状态不可删除');
- $dell= Db::name('consult_bids')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
- if($dell){
- return error_show(0,"删除成功");
- }else
- return error_show(1002,"删除失败");
- }
- public function create(){
- $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
- if($is_project===""){
- return error_show(1002,"参数is_project不能为空");
- }
- if($is_project==1){
- $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
- if($projectNo===""){
- return error_show(1002,"参数projectNo不能为空");
- }
- }
- $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
- if($khNo===""){
- return error_show(1002,"参数khNo不能为空");
- }
- $kehu= \app\admin\common\User::getIns()->handle("cInfo",['companyNo'=>$khNo]);
- if($kehu['code']!=0) return error_show($kehu['code'],$kehu['message']);
- $kehu_info = $kehu['data']??[];
- $area = isset($this->post['area']) && $this->post['area'] !=="" ? trim($this->post['area']) : ($kehu_info['area']??"");
- if($area==='')return error_show(1002,"客户区域不能为空");
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
- if($companyNo===""){
- return error_show(1002,"参数companyNo不能为空");
- }
- $companyinfo= \app\admin\common\User::getIns()->handle("getCodeAndName",['code'=>$companyNo]);
- if($companyinfo['code']!=0) return error_show($companyinfo['code'],$companyinfo['message']);
- $companyName = $companyinfo['data'][$companyNo]??"";
- $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
- if($endtime===""){
- return error_show(1002,"参数endtime不能为空");
- }
- $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) : "";
- if($platform_code===""){
- return error_show(1002,"参数platform_code不能为空");
- }
- $platform = Db::name('platform')
- ->field('id,status,is_select_pay_rate')
- ->where(['is_del' => 0, 'id' => $platform_code])
- ->findOrEmpty();
- if (empty($platform)) return json_show(1004, '该平台不存在');
- if ($platform['status'] != 1) return json_show(1004, '该平台已禁用');
- $pay_id = $platform_code;
- if ($platform['is_select_pay_rate'] == 1&& channel_is_company($platform_code,$companyNo))return error_show(1004, "平台渠道包含当前业务公司");
- $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
- if($ladder==""){
- return error_show(1005,"参数ladder不能为空");
- }
- $createrid= $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $depart = Db::connect('mysql_sys')
- ->name('account_item')
- ->field('itemid')
- ->where('account_id',$createrid)
- ->findOrEmpty();
- $zxNo=makeNo("ZX");
- Db::startTrans();
- try{
- $data=[
- "zxNo"=>$zxNo,
- "createrid"=>$createrid,
- "creater"=>$creater,
- "is_project"=>$is_project,
- "projectNo"=>isset($projectNo) ? $projectNo:"",
- "khNo"=>$khNo,
- "khName"=>$kehu_info['companyName']??"",
- "companyNo"=>$companyNo,
- "companyName"=>$companyName,
- "area"=>$area,
- "endtime"=>$endtime,
- "salesman"=>$creater,
- "platform_code"=>$platform_code,
- "saleid"=>$createrid,
- "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
- "pay_id"=>$pay_id,
- "status"=>0,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- ];
- $zx = Db::name("consult_order")->insert($data);
- if($zx){
- //判断是否是项目,且该项目是否存在台账记录中
- if($is_project==1) $stand_exists=Db::name('standing_book')->field('id')->where('projectNo',$projectNo)->find();
- foreach ($ladder as $value){
- $infoNo=makeNo("IF");
- $specinfo=[];
- if(isset($value['specinfo']) &&!empty($value['specinfo'])){
- foreach ($value["specinfo"] as $v){
- $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
- $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
- $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
- $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
- $specinfo[]=$v;
- }
- }
- $info=[
- "infoNo"=>$infoNo,
- "zxNo"=>$zxNo,
- "spuCode"=>"",
- "good_name"=>$value['good_name'],
- "good_img"=>$value['good_img'],
- "cat_id"=>$value['cat_id'],
- "unit"=>$value['unit'],
- "brand_id"=>$value['brand_id'],
- "arrival_time"=>$value['arrival_time'],
- "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
- "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
- "is_addrs"=>$value['is_addrs'],
- "is_custom"=>$value['is_custom'],
- "metal_id"=>$value['metal_id'],
- "config"=>isset($value['config'])?$value['config']:"",
- "other_config"=>isset($value['other_config'])?$value['other_config']:"",
- "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
- "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
- "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
- "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
- "budget_price"=>$value['budget_price'],
- "num"=>$value['num'],
- "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
- "use_desc"=>$value['use_desc']??'',
- "remark"=>$value['remark'],
- "status"=>1,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
- ];
- $up = Db::name("consult_info")->insertGetId($info);
- if(!$up){
- Db::rollback();
- return error_show(1004,'添加失败');
- }else{
- //修改状态
- ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
- "order_code" => $infoNo,//咨询单详情编号
- "status" => 1,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "create"//新建create,编辑edit,更改状态status
- ], "ZXD", 1, $info);
- //竞价单不走流程,不推待办已办
- // ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
- // "order_type" => 'ZXD',
- // "order_code" => $infoNo,//咨询单详情编号
- // "order_id" => $up,
- // "order_status" => 1,
- // 'before_status'=>0
- // ]);
- //如果存在该项目编码,更新对应的第一个竞价单编码,其他竞价单编码新增(带着项目编码)
- if (isset($stand_exists)) {
- Db::name('standing_book')
- ->where('id', $stand_exists['id'])
- ->update([
- 'infoNo' => $infoNo,
- 'updatetime' => date('Y-m-d H:i:s')
- ]);
- unset($stand_exists);//后面的竞价单编码不用更新,都是新增
- } else {
- //添加台账信息
- Db::name('standing_book')
- ->insert([
- 'standBookNo' => makeNo("IO"),
- 'projectNo' => isset($projectNo) ? $projectNo : '',
- 'infoNo' => $infoNo,
- 'companyNo' => $companyNo,
- 'customer_code' => $khNo,
- 'addtime' => date('Y-m-d H:i:s'),
- 'updatetime' => date('Y-m-d H:i:s')
- ]);
- }
- }
- }
- Db::commit();
- return app_show(0,"新建成功",["zxNo"=>$zxNo]);
- }else{
- Db::rollback();
- return error_show(1004,"新建失败");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1003,$e->getMessage());
- }
- }
- public function zxinfo(){
- $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
- if($infoNo==""){
- return error_show(1004,"参数infoNo不能为空");
- }
- $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
- if($zxinfo==false){
- return error_show(1004,"未找到信息数据");
- }
- $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
- if($zxorder==false){
- return error_show(1004,"未找到咨询信息数据");
- }
- $budget = get_budget($zxinfo['cat_id'], $zxorder['companyNo'], $zxorder['platform_code']);
- if($budget===false) $this->error("未找到业务公司有关的平台分类毛利信息");
- $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
- $zxinfo['khname']="";
- $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget));
- $zxinfo['khNo'] = $zxorder['khNo'];
- $zxinfo['area'] = $zxorder['area'];
- $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
- $zxinfo['brand']="";
- $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
- $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
- $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
- $zxinfo['company']="";
- $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
- $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
- $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
- $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
- $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
- $zxinfo['project_name']="";
- $zxinfo['budget_total']="";
- $zxinfo['departinfo']=[];
- $zxinfo['unit_name']="";
- $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
- $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
- $userCommon = \app\admin\common\User::getIns();
- $tmp = $userCommon->handle('getCodeAndName', ['code' => [$zxorder['companyNo'],$zxorder['khNo']]]);
- if($zxinfo['unit']!==""){
- $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
- $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
- }
- if($zxinfo['brand_id']!==""){
- $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
- $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
- }
- $zxinfo['company'] = $tmp['data'][$zxorder['companyNo']] ?? '';
- $zxinfo['khname'] = $tmp['data'][$zxorder['khNo']] ?? '';
- // }
- if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
- $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
- $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
- $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
- $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
- $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
- $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
- }
- if($zxorder['depart']>0){
- $tmp = $userCommon->handle('ciinfo',['id'=>$zxorder['depart']]);
- $zxinfo['departinfo']=$tmp['data'];
- }
- if($zxorder['platform_code']>0){
- $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
- $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
- }
- return app_show(0,"获取成功",$zxinfo);
- }
- public function zxedit(){
- $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
- if($infoNo==""){
- return error_show(1004,"参数infoNo不能为空");
- }
- $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
- if($zxinfo==false){
- return error_show(1004,"未找到信息数据");
- }
- $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
- $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
- if($good_name==""){
- return error_show(1003,"参数good_name不能为空");
- }
- $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
- if($good_img==""){
- return error_show(1003,"参数good_img不能为空");
- }
- $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
- if($cat_id==""){
- return error_show(1003,"参数cat_id不能为空");
- }
- $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
- if($unit==""){
- return error_show(1003,"参数unit不能为空");
- }
- $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
- $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
- if($arrival_time==""){
- return error_show(1003,"参数arrival_time不能为空");
- }
- $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
- if($specin==""){
- return error_show(1003,"参数specinfo不能为空");
- }
- $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
- // if($cost_desc==""){
- // return error_show(1003,"参数cost_desc不能为空");
- // }
- $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
- if($is_addrs===""){
- return error_show(1003,"参数is_addrs不能为空");
- }
- $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
- if($is_custom===""){
- return error_show(1003,"参数is_custom不能为空");
- }
- $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"0";
- if($metal_id===""){
- return error_show(1003,"参数metal_id不能为空");
- }
- $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
- $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
- $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
- $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
- $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
- $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
- $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
- $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
- if($num===""){
- return error_show(1003,"参数num不能为空");
- }
- if($budget_price===""){
- return error_show(1003,"参数budget_price不能为空");
- }
- $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
- $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
- $isbids = isset($this->post['isbids'])&& $this->post['isbids']!="" ? intval($this->post['isbids']):"1";
- $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo']])->field("area,is_project")->findOrEmpty();
- if(empty($zxorder))return error_show(1003,"咨询信息未找到");
- if($isbids==0){
- if($zxorder['is_project']==1)return error_show(1003,"项目类型咨询单不可进行此项编辑");
- }
- $area = isset($this->post['area'])&& $this->post['area']!="" ? trim($this->post['area']):$zxorder['area'];
- $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
- if($remark==""){
- return error_show(1003,"参数remark不能为空");
- }
- $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
- if($endtime==""){
- return error_show(1003,"参数endtime不能为空");
- }
- if($metal_id!=0){
- if($config==""){
- return error_show(1003,"参数config不能为空");
- }
- if($other_config==""){
- return error_show(1003,"参数other_config不能为空");
- }
- if($specs_weight===""){
- return error_show(1003,"参数specs_weight不能为空");
- }
- if($gold_price===""){
- return error_show(1003,"参数gold_price不能为空");
- }
- }
- $specinfo=[];
- foreach ($specin as $v){
- $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
- $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
- $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
- $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
- $specinfo[]=$v;
- }
- Db::startTrans();
- try{
- $innew =makeNo("IF");
- $info=[
- "infoNo"=>$innew,
- "zxNo"=>$zxinfo['zxNo'],
- "spuCode"=>"",
- "good_name"=>$good_name,
- "good_img"=>$good_img,
- "cat_id"=>$cat_id,
- "unit"=>$unit,
- "brand_id"=>$brand_id,
- "arrival_time"=>$arrival_time,
- "specinfo"=>json_encode($specinfo),
- "cost_desc"=>$cost_desc,
- "is_addrs"=>$is_addrs,
- "is_custom"=>$is_custom,
- "metal_id"=>$metal_id,
- "config"=>$config,
- "other_config"=>$other_config,
- "specs_weight"=>$specs_weight===""?0:$specs_weight,
- "gold_price"=>$gold_price===""? 0 : $gold_price,
- "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
- "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
- "budget_price"=>$budget_price,
- "num"=>$num,
- "pgNo"=>$pgNo,
- "use_desc"=>$use_desc,
- "remark"=>$remark,
- "bargain_num"=>$zxinfo['bargain_num']+1,
- "status"=>1,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- 'bargain_status'=>1,
- 'enclosure_file'=>$enclosure_file
- ];
- $up = Db::name("consult_info")->insert($info);
- if($up){
- //操作记录
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $innew,//咨询单详情编号
- "status" => 1,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "edit"//新建create,编辑edit,更改状态status
- ], "ZXD", 1, $this->post);
- if($isbids==1){
- $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select()->toArray();
- if (!empty($bidlist)){
- foreach ($bidlist as $value){
- unset($value['id']);
- $bidno=$value['bidNo'];
- $value['infoNo']=$innew;
- $value['bidNo']=makeNo("BD");
- $value['spuCode']= $value['is_combind']==1?makeNo("SSU"):makeNo("SKU");
- $value['tax_status']=-1;
- $value['out_tax_id'] =0;
- $value['out_tax'] ="";
- $value["remark"]="";
- $value['status'] =0;
- $value['updatetime'] =date("Y-m-d H:i:s");
- $in = Db::name("consult_bids")->insert($value);
- if($in==false)throw new \Exception("反馈商品新建失败");
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $innew,//咨询单详情编号
- "status" => 1,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "create"//新建create,编辑edit,更改状态status
- ], "FKD", 1, $this->post);
- if($value['is_combind']==1){
- $combine = ConsultTemp::where(["bidNo"=>$bidno])->select();
- if(!$combine->isEmpty()){
- (new ConsultTemp)->saveAll(array_map(function($v)use($value){
- $v['id']=null;
- $v['bidNo']=$value['bidNo'];
- $v['spuCode']= substr(makeNo('SPU'), 0, -2) . round(10,99);
- $v['out_tax_id'] =0;
- $v['out_tax'] ="";
- return $v;
- },$combine->toArray()));
- }
- }
- }
- }
- }
- $zxinfo["bargain_status"] =1;
- $zxinfo["status"] =6;
- $zxinfo["bargain_code"] =$innew;
- $zxinfo["updatetime"] =date("Y-m-d H:i:s");
- $bar=Db::name("consult_info")->save($zxinfo);
- if($bar==false)throw new \Exception("反馈商品更新失败");
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $zxinfo['infoNo'],//咨询单详情编号
- "status" => $zxinfo['status'],//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "edit"//新建create,编辑edit,更改状态status
- ], "ZXD", $zxinfo['status'], $zxinfo);
- //更新consule_order记录
- $op = Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,'area'=>$area, 'updatetime'=>date('Y-m-d H:i:s')]);
- if($op==false)throw new \Exception("咨询单结束时间更新失败");
- //维护台账记录
- $insert_standing_book_data=[
- 'standBookNo'=>makeNo('IO'),
- 'infoNo'=>$innew,
- 'addtime' => date('Y-m-d H:i:s'),
- 'updatetime' => date('Y-m-d H:i:s')
- ];
- $temp_project = Db::name('consult_order')->field('id,projectNo,khNo,companyNo')->where(['zxNo'=>$zxinfo['zxNo'], 'is_del'=>0])->find();
- if(!empty($temp_project)){
- $insert_standing_book_data['projectNo']=$temp_project['projectNo'];
- $insert_standing_book_data['companyNo']=$temp_project['companyNo'];
- $insert_standing_book_data['customer_code']=$temp_project['khNo'];
- }
- Db::name('standing_book')->insert($insert_standing_book_data);
- Db::commit();
- return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- //** 发布竞标任务 */
- public function bargain(){
- $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
- if($infoNo==""){
- return error_show(1004,"参数infoNo不能为空");
- }
- $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
- if($zxinfo==false){
- return error_show(1004,"未找到信息数据");
- }
- $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
- if($status===""){
- return error_show(1004,"参数status不能为空");
- }
- $old_zxinfo_status = $zxinfo['status'];
- $zxinfo['status']=$status;
- $zxinfo['updatetime']=date("Y-m-d H:i:s");
- $up = Db::name("consult_info")->save($zxinfo);
- if($up){
- if($status==2 || $status==7){
- Db::name("consult_bids")->where(["infoNo"=>$infoNo,"is_del"=>0])->update(["tax_status"=>0]);
- }
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_code" => $zxinfo['infoNo'],//咨询单详情编号
- "status" => $old_zxinfo_status,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "ZXD", $zxinfo['status'], $zxinfo);
- return app_show(0,"状态更新成功");
- }else{
- return error_show(1003,"状态更新失败");
- }
- }
- //反馈商品添加
- public function feadback(){
- $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
- if($infoNo==""){
- return error_show(1002,"参数infoNo不能为空");
- }
- $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
- if($zxinfo==false){
- return error_show(1003,"未找到信息数据");
- }
- if($zxinfo['status']!=1){
- return error_show(1004,"任务未进行");
- }
- $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
- if($zx==false){
- return error_show(1003,"未找咨询信息数据");
- }
- $good_name = isset($this->post['good_name'])&&$this->post['good_name']!=""? trim($this->post['good_name']):"";
- if($good_name==""){
- return error_show(1002,"参数good_name不能为空");
- }
- $brandid = isset($this->post['brand_id'])&&$this->post['brand_id']!=""? intval($this->post['brand_id']):"";
- $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
- if($cat_id==""){
- return error_show(1002,"参数cat_id不能为空");
- }
- $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
- if($specin==""){
- return error_show(1003,"参数specinfo不能为空");
- }
- $specinfo=[];
- foreach ($specin as $v){
- $spec =Db::name("specs")->where(["id"=>$v['spec_id']])->find();
- $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
- $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
- $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
- $specinfo[]=$v;
- }
- $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
- $is_combind = isset($this->post['is_combind'])&&$this->post['is_combind']!=""? intval($this->post['is_combind']):"0";
- $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
- $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
- $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
- $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
- $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day']) :"";
- $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
- $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
- if ($this->level == 2) {
- $supplier_account = checkHasAccountBySupplierNos([$supplierNo]);
- if (isset($supplier_account[$supplierNo])) return json_show(1004, '供应商已开通账号,请用供应商账户反馈');
- }
- $cgd_supplier_code = isset($this->post['cgd_supplier_code'])&&$this->post['cgd_supplier_code']!=''? trim($this->post['cgd_supplier_code']):'';
- $cgd_apply_id = isset($this->post['cgd_apply_id'])&&$this->post['cgd_apply_id']!=''? trim($this->post['cgd_apply_id']):0;
- $cgd_apply_name = isset($this->post['cgd_apply_name'])&&$this->post['cgd_apply_name']!=''? trim($this->post['cgd_apply_name']):'';
- $supplier_origin_price = isset($this->post['supplier_origin_price'])&&$this->post['supplier_origin_price']!=''? floatval($this->post['supplier_origin_price']):0;
-
- $user= \app\admin\common\User::getIns();
- $supplier =$user->handle("getCodeAndName",["code"=>[$supplierNo,$cgd_supplier_code]]);
- $supplierName = isset($supplier['data'][$supplierNo])?$supplier['data'][$supplierNo]:"";
- $cgd_supplier_name= $supplier['data'][$cgd_supplier_code]??'';
- $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
- $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
- $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
- $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
- $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
- $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
- $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
- $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"0";
- $good_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
- $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
- $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"0";
- $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
- $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval($this->post['pakge_fee']):"0";
- $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"0";
- $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
- $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
- $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
- if($nake_fee==="" ){
- return error_show(1004,"参数nake_fee不能为空");
- }
- $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
- $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
- $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
- $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
- if($delivery_place==''){
- return error_show(1002,"参数delivery_place不能为空");
- }
- // $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != '' ? trim($this->post['relaComNo']) : "";
- // if ($relaComNo == '') return error_show(1004, '关联公司不能为空');
-
- $createrid= $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $bidNo=makeNo("BD");
- $spucode=makeNo("SKU");
- $goodBind= isset($this->post['goodBind']) && !empty($this->post['goodBind']) ? $this->post['goodBind'] :[];
- if($is_combind==1){
- if(empty($goodBind))$this->error('组合商品商品明细不能为空');
- $spucode=makeNo('SSU');
- }
- $tax_id = isset($this->post['tax_id'])&&$this->post['tax_id']!==''? intval($this->post['tax_id']):'0';
- $cgd_tax_id = isset($this->post['cgd_tax_id'])&&$this->post['cgd_tax_id']!==''? intval($this->post['cgd_tax_id']):'0';
- $cgd_tax = isset($this->post['cgd_tax'])&&$this->post['cgd_tax']!==''? trim($this->post['cgd_tax']):'';
- $open_type= isset($this->post['open_type'])&&$this->post['open_type']!==''? intval($this->post['open_type']):1;
- $inv_good_name = isset($this->post['inv_good_name'])&&$this->post['inv_good_name']!==''? trim($this->post['inv_good_name']):'';
- if($open_type=='') return error_show(1004,'开票商品类型不能为空');
- if($open_type==1){
- if($tax_id=='') return error_show(1004,'商品税目id不能为空');
- if($inv_good_name=='') return error_show(1004,'开票商品名称不能为空');
- if($cgd_supplier_code!=""){
- if($cgd_tax_id==0) return error_show(1004,'源头供应商开票税目不能为空');
- if($cgd_tax==='') return error_show(1004,'源头供应商开票税率不能为空');
- }
- }
- //计算毛利率
- $budget = get_budget($zxinfo['cat_id'], $zx['companyNo'], $zx['platform_code']);
- if($budget===false) $this->error('未找到业务公司有关的平台分类毛利信息');
- //部分参数的大小校验
- $vali = Validate::rule([
- 'expire_day|有效时长'=>'require|elt:214748364',
- 'delivery_day|物流时长'=>'require|elt:214748364',
- 'work_day|生产工期'=>'require|elt:214748364',
- 'weight|总重量'=>'require|max:10',
- ]);
- $temp = [
- 'expire_day'=>$expire_day,
- 'delivery_day'=>$delivery_day,
- 'work_day'=>$work_day,
- 'weight'=>$weight,
- ];
- if(!$vali->check($temp)) return error_show(0,$vali->getError());
- $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
- $cat_top_list = made($cat_id);
- $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
- if ($is_gold_price == 1 && $cat_top_id == 6) {
- $gold = Db::name("gold_price1")
- ->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])
- ->order("addtime desc")
- ->find();
- $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;
- //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
- // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
- $saleprice = $total_fee/ (1 - $budget);
- //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
- $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"];
- }else{
- if($nake_fee){
- $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);
- $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
- }else{
- $saleprice = ($demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee) / (1 - $budget);
- $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee;
- }
- }
- $userCommon= \app\admin\common\User::getIns();
- $supplier_temp =$userCommon->handle("hqInfo",["code"=>$supplierNo]);
- if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1004,"供应商信息未找到");
- $supplierArr=$supplier_temp['data']??[];
- $supplier=$supplierArr['child']??[];
- if ($supplierArr['relation_code'] != '') {
- if ($supplierArr['relation_code'] == $zx['companyNo']) return error_show(1004, "业务公司与供应商信息一致");
- //判断支付渠道中是否有相关供应商
- $is_select_pay_rate = Db::name('platform')
- ->where(['is_del' => 0, 'id' => $zx['platform_code']])
- ->value('is_select_pay_rate', 0);
- if ($is_select_pay_rate == 1) {
- if(channel_is_company($zx['platform_code'],$supplierArr['relation_code'])) return error_show(1004, "平台渠道包含当前供应商公司{$supplierNo}");
- }
- }else{
- if($is_combind==1)$this->error("当前供应商无对应业务公司,不可选择组合商品");
- }
- $data=[
- "bidNo"=>$bidNo,
- "infoNo"=>$infoNo,
- "zxNo"=>$zxinfo['zxNo'],
- "spuCode"=>$spucode,
- "good_name"=>$good_name,
- "brand_id"=>$brandid,
- "cat_id"=>$cat_id,
- "specinfo"=>json_encode($specinfo),
- "unit_id"=>$unit_id,
- "cost_desc"=>$cost_desc,
- "work_day"=>$work_day,
- "delivery_day"=>$delivery_day,
- "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
- "expire_day"=>$expire_day,
- "origin_place"=>$origin_place,
- "supplierNo"=>$supplierNo,
- "supplierName"=>$supplierName,
- "pay_way"=>$pay_way,
- "tax"=>$tax,
- "send_way"=>$send_way,
- "metal_id"=>$metal_id,
- "is_gold_price"=>$is_gold_price,
- "config"=>$config,
- "other_config"=>$other_config,
- "weight"=>$weight,
- "good_weight"=>$good_weight,
- "gold_price"=>isset($gold["price"])?$gold["price"]:0,
- "is_diff"=>$is_diff,
- "demo_fee"=>$demo_fee,
- "delivery_fee"=>$delivery_fee,
- "open_fee"=>$open_fee,
- "pakge_fee"=>$pakge_fee,
- "nake_fee"=>$nake_fee,
- "mark_fee"=>$mark_fee,
- "cert_fee"=>$cert_fee,
- "cost_fee"=>$cost_fee,
- "total_fee"=>$total_fee,
- "supply_area"=>$supply_area,
- "remark"=>$remark,
- "sale_price"=>$saleprice,
- "sale_cost_fee"=>$sale_cost_fee,
- "origin_cost_fee"=>$sale_cost_fee,
- "origin_price"=>$saleprice,
- "createrid"=>$createrid,
- "creater"=>$creater,
- "status"=>$zxinfo['status']==1 ?1 :2,
- "is_del"=>0,
- "is_combind"=>$is_combind,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- 'delivery_place'=>$delivery_place,//发货地
- 'cgder' => $supplier['person'] ?? '',
- 'cgderid' => $supplier['personid'] ?? 0,
- 'supplier_origin_price'=>$supplier_origin_price,//供应商采购成本
- 'cgd_supplier_code'=>$cgd_supplier_code,//采购供应商编号
- 'cgd_supplier_name'=>$cgd_supplier_name,//采购供应商编号
- 'cgd_apply_id'=>$cgd_apply_id,//竞单人
- 'cgd_apply_name'=>$cgd_apply_name,//竞单人
- "open_type"=>$open_type,
- "inv_good_name"=>$inv_good_name,//采购商品名称
- "tax_id"=>$tax_id,//税目id
- "cgd_tax"=>$cgd_tax,//税目
- "cgd_tax_id"=>$cgd_tax_id
- ];
- Db::startTrans();
- try{
- $insert= Db::name("consult_bids")->insert($data);
- if($insert){
- if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
- $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
- if($projectinfo==false){
- Db::rollback();
- return error_show(1006,"未找到项目信息");
- }
- $temp=[];
- $temp['spuCode']=$spucode;
- $temp['skuCode']="";
- $temp['pgNo']=$zxinfo['pgNo'];
- $temp['projectNo']=$zx['projectNo'];
- $temp['good_name']=$good_name;
- $temp['good_type']=$projectinfo['good_type'];
- $temp['data_source']=2;
- $temp['cat_id']=$cat_id;
- $temp['budget_price']=$projectinfo['budget_price'];
- $temp['sale_price']=$saleprice;
- $temp['origin_price']=$total_fee;
- $temp['num']=$zxinfo['num'];
- $temp['status']=0;
- $temp['is_del']=0;
- $temp['creater']=$creater;
- $temp['createrid']=$createrid;
- $temp['addtime']=date("Y-m-d H:i:s");
- $temp['updatetime']=date("Y-m-d H:i:s");
- $nu = Db::name("project_feedback")->insert($temp);
- if($nu==false){
- Db::rollback();
- return error_show(1006,"项目反馈失败");
- }else{
- $old_projectinfo_status = $projectinfo['status'];
- $projectinfo['status']=2;
- $projectinfo['updatetime']=date("Y-m-d H:i:s");
- $up = Db::name("project_info")->save($projectinfo);
- if($up){
- //修改状态,添加待办,只记录动作
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_code" => $projectinfo['pgNo'],//编码
- "status" => $old_projectinfo_status,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "PRI", 2, $projectinfo);
- $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
- ->count();
- if($count==0){
- $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
- if($projetc!=false){
- $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
- (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
- if($proc==false){
- Db::rollback();
- return error_show(1006,"项目反馈失败");
- }else{
- //修改状态,添加待办
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_code" => $projetc['projectNo'],//项目编码
- "status" => 1,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "PRO", 2, $projetc);
- ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_type" => 'PRO',
- "order_code" => $projetc['projectNo'],
- "order_id" => $projetc['id'],
- "order_status" => 2,"before_status"=>1
- ]);
- }
- }
- }
- }
- }
- }
- if($is_combind==1){
- $arram=[
- 'bidNo'=>$bidNo,
- "companyNo"=>$zx['companyNo'],
- "companyName"=>$zx['companyName'],
- 'supplierName'=>$supplierName,
- ];
- (new \app\admin\model\ConsultTemp)->CreateByZx($goodBind,$arram);
- }
- Db::commit();
- return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
- }else{
- Db::rollback();
- return error_show(1006,"反馈失败");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1006,$e->getMessage());
- }
- }
- //反馈商品详情
- public function feadinfo(){
- $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
- if($bidNo==""){
- return error_show(1004,"参数bidNo不能为空");
- }
- $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
- if($info==false){
- return error_show(1004,"未找到商品数据");
- }
- $zx =Db::name("consult_order")->where(['zxNo'=>$info['zxNo'],"is_del"=>0])->find();
- if($zx==false) return error_show(1004,"未找到咨询单信息");
- $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
- $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
- $info['cat_info'] = made($info['cat_id'],[]);
- $info['noble_weight'] = $info['good_weight'];
- $info['companyNo'] = $zx['companyNo'];
- $info['companyName'] = $zx['companyName'];
- $info['order_createrid'] = $zx['createrid'];
- $info['order_creater'] = $zx['creater'];
- $user= \app\admin\common\User::getIns();
- $supplier =$user->handle("getCodeAndName",["code"=>$info['supplierNo']]);
- $info['supplierName'] = isset($supplier['data'][$info['supplierNo']])?$supplier['data'][$info['supplierNo']]:"";
- if($info['brand_id']!=0){
- $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
- $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
- }else{
- $info["brand_name"]="";
- $info["brand_id"]="";
- }
- $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
- $budget = get_budget($info['cat_id'], $zx['companyNo'], $zx['platform_code']);
- if($budget===false) $this->error('未找到业务公司有关的平台分类毛利信息');
- $god=[
- "metal_id"=>$info['metal_id'],
- "weight"=>$info["good_weight"],
- "demo_fee"=>$info["demo_fee"],
- "delivery_fee"=>$info["delivery_fee"],
- "open_fee"=>$info["open_fee"],
- "packing_fee"=>$info["pakge_fee"],
- "mark_fee"=>$info["mark_fee"],
- "nake_fee"=>$info["nake_fee"],
- "cert_fee"=>$info["cert_fee"],
- "cost_fee"=>$info["cost_fee"],
- "num"=>$bidinfo["num"],
- ];
- if($info['is_gold_price']==1){
- $price = GoldPrice($god, $budget);
- $info['sale_price'] =round($price,2);
- }
- $info['specinfo'] = json_decode($info['specinfo'],true);
- $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
- if($info['delivery_place']!=""){
- list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['delivery_place']);
- }
- $info['delivery_place_cn']=GetAddr(json_encode($place));
- $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
- if($info['origin_place']!=""){
- list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['origin_place']);
- }
- $info['origin_place_cn']=GetAddr(json_encode($place));
- $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
- $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
- $info['bargain'] =$bargain;
- $info["info_status"]=$bidinfo['status'];
- $info['good_img'] = explode(',',$info['good_img']);
- $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");
- $info['in_info'] = $tax[$info['tax_id']]??[];
- $info['out_info'] = $tax[$info['out_tax_id']]??[];
- $info['cgd_info'] = $tax[$info['cgd_tax_id']]??[];
- $info['child'] =[];
- if($info['is_combind']==1){
- $info['child'] =ConsultTemp::where(['bidNo'=>$bidNo])->select()->each(function(&$item){
- $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');
- $item['in_info'] = $tax[$item['tax_id']]??[];
- $item['out_info'] = $tax[$item['out_tax_id']]??[];
- $item['cgd_info'] = $tax[$item['cgd_tax_id']]??[];
- });
- }
- //添加商品创建人字段
- $good_info = Db::name('good_basic')
- ->field('id,createrid,creater')
- ->where('is_del',0)
- ->where('spuCode',$info['spuCode'])
- ->findOrEmpty();
- $info['good_createrid'] = $good_info['createrid']??0;
- $info['good_creater'] = $good_info['creater']??'';
- return app_show(0,"获取成功",$info);
- }
- //反馈商品编辑
- public function feededit(){
- $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
- if($bidNo==""){
- return error_show(1002,"参数bidNo不能为空");
- }
- $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
- if($bidinfo==false){
- return error_show(1003,"未找到信息数据");
- }
- if($bidinfo['status']>=5){
- return error_show(1004,"咨询单已确认无法修改");
- }
- $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
- if($zxinfo==false){
- return error_show(1003,"未找到信息数据");
- }
- $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
- if($zx==false){
- return error_show(1003,"未找咨询信息数据");
- }
- $pname = isset($this->post['good_name'])&&$this->post['good_name']!=""? trim($this->post['good_name']):"";
- if($pname==""){
- return error_show(1002,"参数good_name不能为空");
- }
- $brandid = isset($this->post['brand_id'])&&$this->post['brand_id']!=""? intval($this->post['brand_id']):"";
- // if($brandid==""){
- // return error_show(1002,"参数brandid不能为空");
- // }
- $is_combind = isset($this->post['is_combind'])&&$this->post['is_combind']!=''? intval($this->post['is_combind']):'0';
- $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
- if($cat_id==""){
- return error_show(1002,"参数cat_id不能为空");
- }
- $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
- if($specin==""){
- return error_show(1003,"参数specinfo不能为空");
- }
- $specinfo=[];
- foreach ($specin as $v){
- $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
- $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
- $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
- $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
- $specinfo[]=$v;
- }
- $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
- $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
- $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
- $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
- $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
- $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day']) :"";
- $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
- $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
-
- if ($this->level == 2) {
- $supplier_account = checkHasAccountBySupplierNos([$bidinfo['supplierNo'],$supplierNo]);
- if (isset($supplier_account[$bidinfo['supplierNo']])) return json_show(1004, '原供应商已开通账号,请用供应商账户反馈');
- if (isset($supplier_account[$supplierNo])) return json_show(1004, '供应商已开通账号,请用供应商账户反馈');
- }
- $cgd_supplier_code = isset($this->post['cgd_supplier_code'])&&$this->post['cgd_supplier_code']!=''? trim($this->post['cgd_supplier_code']):'';
- $cgd_apply_id = isset($this->post['cgd_apply_id'])&&$this->post['cgd_apply_id']!=''? trim($this->post['cgd_apply_id']):0;
- $cgd_apply_name = isset($this->post['cgd_apply_name'])&&$this->post['cgd_apply_name']!=''? trim($this->post['cgd_apply_name']):'';
- $supplier_origin_price = isset($this->post['supplier_origin_price'])&&$this->post['supplier_origin_price']!=''? floatval($this->post['supplier_origin_price']):0;
- $user= \app\admin\common\User::getIns();
- $supplier =$user->handle("getCodeAndName",["code"=>[$supplierNo,$cgd_supplier_code]]);
- $supplierName = isset($supplier['data'][$supplierNo])?$supplier['data'][$supplierNo]:"";
- $cgd_supplier_name= $supplier['data'][$cgd_supplier_code]??'';
- $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
- $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
- $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"0";
- $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
- $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
- $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
- $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
- $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"0";
- $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!=""? floatval($this->post['noble_weight']):"0";
- $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"0";
- $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"0";
- $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"0";
- $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"0";
- $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
- $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"0";
- $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"0";
- $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"0";
- $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
- $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
- $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
- $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
- if($delivery_place==''){
- return error_show(1002,"参数delivery_place不能为空");
- }
- $budget = get_budget($cat_id,$zx['companyNo'],$zx['platform_code']);
- if($budget===false) $this->error('未找到业务公司有关的平台分类毛利信息');
- $sale_cost_fee = $bidinfo['sale_cost_fee'];
- $cat_top_list = made($cat_id);
- $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
- if ($is_gold_price == 1 && $cat_top_id == 6) {
- $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
- ->find();
- //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
- $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;
- // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
- //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
- $saleprice = $total_fee / (1 - $budget);
- //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
- $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"];
- }else{
- $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);
- $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee/$zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee+$cert_fee +$nake_fee;
- }
- $userCommon= \app\admin\common\User::getIns();
- $supplier_temp =$userCommon->handle("hqInfo",["code"=>$supplierNo]);
- if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1004,"供应商信息未找到");
- $supplierArr=$supplier_temp['data']??[];
- $goodBind= isset($this->post['goodBind']) && !empty($this->post['goodBind']) ? $this->post['goodBind'] :[];
- if($is_combind==1){
- if(empty($goodBind))$this->error('组合商品商品明细不能为空');
- }
- if ($supplierArr['relation_code'] != '') {
- if ($supplierArr['relation_code'] == $zx['companyNo']) return error_show(1004, "业务公司与供应商信息一致");
- //判断支付渠道中是否有相关供应商
- $is_select_pay_rate = Db::name('platform')
- ->where(['is_del' => 0, 'id' => $zx['platform_code'],"status"=>1])
- ->value('is_select_pay_rate', 0);
- if ($is_select_pay_rate == 1) {
- if(channel_is_company($zx['platform_code'],$supplierArr['relation_code'])) return error_show(1004, "平台渠道包含当前供应商公司{$supplierNo}");
- }
- }else{
- if($is_combind==1)$this->error('当前供应商无对应业务公司,不可选择组合商品');
- }
- $tax_id = isset($this->post['tax_id'])&&$this->post['tax_id']!==''? intval($this->post['tax_id']):'';
- $open_type= isset($this->post['open_type'])&&$this->post['open_type']!==''? intval($this->post['open_type']):'';
- $inv_good_name = isset($this->post['inv_good_name'])&&$this->post['inv_good_name']!==''? trim($this->post['inv_good_name']):'';
- $cgd_tax_id = isset($this->post['cgd_tax_id'])&&$this->post['cgd_tax_id']!==''? intval($this->post['cgd_tax_id']):'0';
- $cgd_tax = isset($this->post['cgd_tax'])&&$this->post['cgd_tax']!==''? trim($this->post['cgd_tax']):'';
- if($open_type=='') return error_show(1004,'开票商品类型不能为空');
- if($open_type==1){
- if($tax_id=='') return error_show(1004,'商品税目id不能为空');
- if($inv_good_name=='') return error_show(1004,'开票商品名称不能为空');
- if($cgd_supplier_code!=''){
- if($cgd_tax_id==0) return error_show(1004,'源头供应商开票税目不能为空');
- if($cgd_tax==='') return error_show(1004,'源头供应商开票税率不能为空');
- }
- }
- Db::startTrans();
- try{
- $data=[
- "good_name"=>$pname,
- "brand_id"=>$brandid,
- "cat_id"=>$cat_id,
- "specinfo"=>json_encode($specinfo),
- "unit_id"=>$unit_id,
- "cost_desc"=>$cost_desc,
- "work_day"=>$work_day,
- "delivery_day"=>$delivery_day,
- "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
- "expire_day"=>$expire_day,
- "origin_place"=>$origin_place,
- "supplierNo"=>$supplierNo,
- "supplierName"=>$supplierName,
- "pay_way"=>$pay_way,
- "tax"=>$tax,
- "send_way"=>$send_way,
- "metal_id"=>$metal_id,
- "is_gold_price"=>$is_gold_price,
- "config"=>$config,
- "other_config"=>$other_config,
- "weight"=>$weight,
- "good_weight"=>$noble_weight,
- "is_diff"=>$is_diff,
- "demo_fee"=>$demo_fee,
- "gold_price"=>isset($gold["price"])?$gold["price"]:0,
- "delivery_fee"=>$delivery_fee,
- "open_fee"=>$open_fee,
- "pakge_fee"=>$pakge_fee,
- "nake_fee"=>$nake_fee,
- "mark_fee"=>$mark_fee,
- "cert_fee"=>$cert_fee,
- "cost_fee"=>$cost_fee,
- "sale_cost_fee"=>$sale_cost_fee,
- "origin_cost_fee"=>$sale_cost_fee,
- "total_fee"=>$total_fee,
- "sale_price"=>$saleprice,
- "origin_price"=>$saleprice,
- "supply_area"=>$supply_area,
- "remark"=>$remark,
- "status"=>0,
- "updatetime"=>date("Y-m-d H:i:s"),
- 'delivery_place' => $delivery_place,
- 'supplier_origin_price'=>$supplier_origin_price,//供应商采购成本
- 'cgd_supplier_code'=>$cgd_supplier_code,//采购供应商编号
- 'cgd_supplier_name'=>$cgd_supplier_name,//采购供应商编号
- 'cgd_apply_id'=>$cgd_apply_id,//竞单人
- 'cgd_apply_name'=>$cgd_apply_name,//竞单人
- 'open_type'=>$open_type,
- 'inv_good_name'=>$inv_good_name,//采购商品名称
- 'tax_id'=>$tax_id,//税目id
- 'cgd_tax'=>$cgd_tax,//税目
- 'cgd_tax_id'=>$cgd_tax_id
- ];
- $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
- if($insert){
- if($zxinfo['bargain_status']==1){
- $zxinfo['bargain_status']=0;
- $infoip =Db::name("consult_info")->save($zxinfo);
- if($infoip==false){
- Db::rollback();
- return error_show(1006,"咨询信息状态更新失败");
- }
- }
- if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
- $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
- if($projectinfo==false){
- Db::rollback();
- return error_show(1006,"未找到项目信息");
- }
- $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
- if($feed!=false) {
- $feed['good_name']=$pname;
- $feed['good_type']=$projectinfo['good_type'];
- $feed['cat_id']=$cat_id;
- $feed['sale_price']=$saleprice;
- $feed['origin_price']=$total_fee;
- $feed['updatetime']=date("Y-m-d H:i:s");
- $temp['updatetime']=date("Y-m-d H:i:s");
- $nu=Db::name("project_feedback")->save($feed);
- if ($nu == false) {
- Db::rollback();
- return error_show(1006 , "项目反馈失败");
- } else {
- $old_projectinfo_status=$projectinfo['status'];
- $projectinfo['status']=2;
- $projectinfo['updatetime']=date("Y-m-d H:i:s");
- $up=Db::name("project_info")->save($projectinfo);
- if ($up) {
- //修改状态,添加待办,只记录动作
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname] , [
- "order_code"=>$projectinfo['pgNo'] ,//编码
- "status"=>$old_projectinfo_status ,//这里的status是之前的值
- "action_remark"=>'' ,//备注
- "action_type"=>"status"//新建create,编辑edit,更改状态status
- ] , "PRI" , 2 , $projectinfo
- );
- $count=Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->count();
- if ($count == 0) {
- //先查询是否存在status==1的项目,有的话再更新,否则跳过
- $project_id=Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->value('id' , 0);
- if ($project_id) {
- $proc=Db::name("project")->where(["id"=>$project_id])->update(["status"=>2 , "updatetime"=>date("Y-m-d H:i:s")]);
- if ($proc == false) {
- Db::rollback();
- return error_show(1006 , "项目反馈失败");
- } else {
- //修改状态,添加待办
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname] , [
- "order_code"=>$projectinfo['projectNo'] ,//项目编码
- "status"=>1 ,//这里的status是之前的值
- "action_remark"=>'' ,//备注
- "action_type"=>"status"//新建create,编辑edit,更改状态status
- ] , "PRO" , 2 , $this->post
- );
- ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname] , [
- "order_type"=>'PRO' ,
- "order_code"=>$projectinfo['projectNo'] ,
- "order_id"=>$project_id ,
- "order_status"=>2 , "before_status"=>1
- ]
- );
- }
- }
- }
- }
- }
- }
- }
- if($is_combind==1){
- $arram=[
- 'bidNo'=>$bidNo,
- "companyNo"=>$zx['companyNo'],
- "companyName"=>$zx['companyName'],
- "supplierName"=>$supplierName,
- ];
- (new \app\admin\model\ConsultTemp)->CreateByZx($goodBind,$arram);
- }
- Db::commit();
- return app_show(0,"编辑成功");
- }else{
- Db::rollback();
- return error_show(1004,"编辑失败");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- //生成议价单
- public function bargain_add(){
- $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
- if($bidNo===""){
- return error_show(1004,"参数bidNo不能为空");
- }
- $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
- if($info==false){
- return error_show(1004,"未找到商品数据");
- }
- $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
- if($consult==false){
- return error_show(1004,"未找到咨询数据");
- }
- $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
- if($bargain_price===""){
- return error_show(1004,"参数bargain_price不能为空");
- }
- $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
- if($info['is_gold_price']==1){
- if($cost_price==""){
- return error_show(1004,"参数cost_price不能为空");
- }
- $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
- $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
- $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
- ->find();
- $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);
- }
- $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
- $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
- if($infos==false){
- return error_show(1004,"未找到商品数据");
- }
- if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
- return error_show(1004,"咨询单招标未结束或已确认商品");
- }
- //新增两个字段
- //议价备注
- $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
- //议价原因id
- $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
- if ($result_info_id != '') {
- $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
- if (empty($temp)) return error_show(1004, "议价原因选择不正确");
- }
- $createrid= $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $bargainNo =makeNo("BA");
- Db::startTrans();//::todo 金价 毛利计算
- try{
- $data=[
- "bidsNo"=>$bidNo,
- "infoNo"=>$info['infoNo'],
- "zxNo"=>$info['zxNo'],
- "bargainNo"=>$bargainNo,
- "bargain_type"=>1,
- "bargain_reason"=>$bargain_reason,
- "sale_price"=>$info['sale_price'],
- "cost_before_price"=>$info['sale_cost_fee'],
- "cost_after_price"=>$cost_price,
- "before_rate"=>round(($info['origin_price']-$info['total_fee'])/$info['origin_price'],4),
- "after_rate"=>$bargain_price==0?-1:round(($bargain_price-$info['total_fee'])/$bargain_price,4),
- "after_price"=>$bargain_price,
- "exam_info"=>"",
- "status"=>0,
- "is_del"=>0,
- "creater"=>$creater,
- "createrid"=>$createrid,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- 'bargain_remark'=>$bargain_remark,
- 'result_info_id'=>$result_info_id,
- ];
- $int = Db::name("bargain_order")->insertGetId($data);
- if($int){
- //修改状态,添加待办
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_code" => $bargainNo,//咨询单详情编号
- "status" => 0,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "YJD", $data['status'], $data);
- ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_type" => 'YJD',
- "order_code" => $bargainNo,
- "order_id" => $int,
- "order_status" =>0,
- "before_status"=>0,
- 'holder_id'=>$data['createrid']
- ]);
- $odlstatus=$info['status'];
- $info['status']=3;
- $info['updatetime']=date("Y-m-d H:i:s");
- $up =Db::name("consult_bids")->save($info);
- if($up){
- //修改状态,添加待办
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_code" => $bidNo,//咨询单详情编号
- "status" => $odlstatus,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "FKD", $info['status'], $info);
- $old_infos_status = $infos['status'];
- $infos['status']=3;
- $infos['updatetime']=date("Y-m-d H:i:s");
- $ups =Db::name("consult_info")->save($infos);
- if($ups){
- //修改状态,添加待办
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_code" => $infos['infoNo'],//咨询单详情编号
- "status" => $old_infos_status,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "ZXD", $infos['status'], $infos);
- //维护台账信息
- Db::name('standing_book')->where('infoNo', $info['infoNo'])->update(['bargainNo' => $bargainNo,'updatetime' => date('Y-m-d H:i:s')]);
- Db::commit();
- return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
- }
- }
- }
- Db::rollback();
- return error_show(1004,"议价单新建失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- public function bids_check(){
- $params = $this->request->param(["bidNo"=>"","status"=>"","remark"=>"","out_tax_id"=>"","out_tax"=>"","goodCombind"=>[]],"post");
- $valid = Validate::rule([
- "bidNo|反馈单编号"=>"require",
- "status|状态"=>"require|number",
- "remark|备注"=>"max:255",
- "out_tax_id|税目id"=>"requireIf:status,1|number",
- "out_tax|税目税率"=>"requireIf:status,1",
- "goodCombind|组合商品信息"=>"array",
- ]);
- if(!$valid->check($params)){
- return error_show(1004,$valid->getError());
- }
- $info =ConsultBids::where(['bidNo'=>$params['bidNo'],"is_del"=>0])->findOrEmpty();
- if($info->isEmpty()){
- return error_show(1004,"未找到商品数据");
- }
- $consult_info =ConsultInfo::where(['infoNo'=>$info['infoNo'],"is_del"=>0])->findOrEmpty();
- if($consult_info->isEmpty()) $this->error("未找到商品数据");
- if($consult_info['status']!=2&&$consult_info['status']!=3&&$consult_info['status']!=7){
- return error_show(1004,"咨询单招标未结束或已确认商品");
- }
- $goodCombind = $params['goodCombind'];
- if($info->is_combind==1 && $params['status']==1){
- if(empty($goodCombind)){
- return error_show(1004,"组合商品信息不能为空");
- }
- $valids = Validate::rule(["out_tax_id|税目id"=>"require|number",'out_tax|税目税率'=>'require',"id|商品id"=>"require"]);
- foreach ($goodCombind as $k=>$v){
- if(!$valids->check($v)){
- return error_show(1004,$valids->getError());
- }
- }
- }
- Db::startTrans();
- try {
- $oldstattus=$info->status;
- $info->tax_status=$params['status'];
- $info->out_tax_id=$params['out_tax_id'];
- $info->out_tax=$params['out_tax'];
- $info->remark=$params['remark'];
- $save=$info->save();
- if($save){
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- 'order_code' =>$params['bidNo'],//咨询单详情编号
- 'status' => $oldstattus,//这里的status是之前的值
- 'action_remark' => '',//备注
- 'action_type' => 'status'//新建create,编辑edit,更改状态status
- ], 'FKD', $params['status'], $info);
- if(!empty($goodCombind)){
- (new ConsultTemp())->saveAll($goodCombind);
- }
- }
- Db::commit();
- return app_show(0,'商品确定成功');
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- public function bids_check_batch(){
- $list = $this->request->param(["list"=>[]],"post");
- $valid = Validate::rule([
- "list|商品审核数据列表"=>"require|array",
- ]);
- if(!$valid->check($list)){
- return error_show(1004,$valid->getError());
- }
- $temp=[];
- $bids = ConsultBids::whereIn('bidNo',$list['list'])->column("id,infoNo,bidNo,status,tax_status,tax,tax_id,is_combind","bidNo");
- foreach ($list['list'] as $k=>$v){
- if (!isset($bids[$v])) return error_show(1004,"{$v}的反馈单不存在");
- if($bids[$v]['tax_status']!=0) return error_show(1004,"{$v}的反馈单状态不正确");
- $consult_info =ConsultInfo::where(['infoNo'=>$bids[$v]['infoNo'],'is_del'=>0])->findOrEmpty();
- if($consult_info->isEmpty()) $this->error("未找到{$v['bidNo']}的咨询单数据");
- if($consult_info['status']!=2&&$consult_info['status']!=3&&$consult_info['status']!=7){
- return error_show(1004,"{$v}的咨询单招标未结束或已确认商品");
- }
- if ($bids[$v]['is_combind']==1)return error_show(1004,$v.'组合商品不可参与批量审核');
- $temp[]=[
- "id"=>$bids[$v]['id'],
- "tax_status"=>1,
- "out_tax_id"=>$bids[$v]['tax_id'],
- "out_tax"=>$bids[$v]['tax']
- ];
- }
- try{
- $update= (new ConsultBids())->saveAll($temp);
- if($update->count()<=0)throw new \Exception("商品确定失败");
- }catch (\Exception $e){
- return error_show(1004,$e->getMessage());
- }
- return app_show(0,'商品确定成功');
- }
- //选择商品
- // public function bids_check(){
- // $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
- // if($bidNo===""){
- // return error_show(1004,"参数bidNo不能为空");
- // }
- // $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
- // if($info==false){
- // return error_show(1004,"未找到商品数据");
- // }
- // $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
- // if($infos==false){
- // return error_show(1004,"未找到商品数据");
- // }
- //
- // if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
- // return error_show(1004,"咨询单招标未结束或已确认商品");
- // }
- // Db::startTrans();
- // try {
- // $oldstattus=$info['status'];
- // $info['status']=6;
- // $info['updatetime']=date("Y-m-d H:i:s");
- // $bids = Db::name("consult_bids")->save($info);
- // if($bids){
- // //修改状态,添加待办
- // ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- // "order_code" =>$bidNo,//咨询单详情编号
- // "status" => $oldstattus,//这里的status是之前的值
- // "action_remark" => '',//备注
- // "action_type" => "status"//新建create,编辑edit,更改状态status
- // ], "FKD", $info['status'], $info);
- // $old_infos_status = $infos['status'];
- // $infos['status']=4;
- // $infos['updatetime']=date("Y-m-d H:i:s");
- // $se = Db::name("consult_info")->save($infos);
- // if($se){
- // //修改状态,添加待办
- // ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- // "order_code" => $infos['infoNo'],//咨询单详情编号
- // "status" => $old_infos_status,//这里的status是之前的值
- // "action_remark" => '',//备注
- // "action_type" => "status"//新建create,编辑edit,更改状态status
- // ], "ZXD", $infos['status'], $infos);
- // Db::name("bargain_order")->where(["bidsNo"=>$bidNo,"is_del"=>0,"status"=>[0,2,4,5,7]])
- // ->update(['status'=>12,"remark"=>'已选择商品,取消议价',"updatetime"=>date("Y-m-d H:i:s")]);
- // Db::commit();
- // return app_show(0,"商品确定成功");
- // }
- // }
- // Db::rollback();
- // return error_show(1004,"商品确认失败");
- // }catch (\Exception $e){
- // Db::rollback();
- // return error_show(1004,$e->getMessage());
- // }
- // }
- //议价审核
- /**
- * status:
- * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回 12取消
- * change 0待审核 1业务主管审核通过 2 业务驳回 3 业务主管越线通过4取消议价
- */
- public function bargain_status(){
- $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
- if($bargainNo===""){
- return error_show(1004,"参数bargainNo不能为空");
- }
- $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
- if($info==false){
- return error_show(1004,"未找到议价数据");
- }
- if($info['status']==4){
- return error_show(1004,"议价单已取消");
- }
- $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
- if($bids==false){
- return error_show(1004,"未找到商品数据");
- }
- $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
- if($coninfo==false){
- return error_show(1004,"未找到咨询单数据");
- }
- if($bids['status']==6){
- return error_show(1004,"咨询已选择商品");
- }
- $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
- if($status===''){
- return error_show(1005,"参数status不能为空");
- }
- $adjunct = isset($this->post['adjunct'])&& $this->post['adjunct']!=='' ? trim($this->post['adjunct']):"";
- $adjunct_name = isset($this->post['adjunct_name'])&& $this->post['adjunct_name']!=='' ? trim($this->post['adjunct_name']):"";
- $tmp = Db::name('consult_order')
- ->field('id,companyNo,platform_code')
- ->where(['is_del'=>0,'zxNo'=>$bids['zxNo']])
- ->findOrEmpty();
- $catinfo = get_budget($bids['cat_id'],$tmp['companyNo']??'',$tmp['platform_code']??0,true);
- if($catinfo===false) $this->error('未找到业务公司有关的平台分类毛利信息');
- $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
- if($bids['is_gold_price']==1){
- $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
- ->find();
- //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
- $total_fe= $bids['demo_fee'] / $coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] / $coninfo['num'] +
- $bids['good_weight']*$gold["price"] +$bids['cost_fee']*$bids['good_weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee'];
- // $saleprice =$total_fe / (1 - $budget);
- $rate_price = $total_fe / (1 - $rate);
- }else{
- $total_fe= $bids['demo_fee']/$coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] /
- $coninfo['num']+$bids['cost_fee']*$bids['good_weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'];
- if($bids['nake_fee']!=0){
- $rate_price = ($total_fe)/ (1 - $rate);
- }else{
- $rate_price =$total_fe/ (1 - $rate);
- }
- }
- $ra_status = $info['status'];
- $info['status']=$status;
- if($status==1){
- if($info['after_price']<$rate_price){
- $info['status']=3;
- if($adjunct=='') return error_show(1005,"越线通过附件不能为空");
- }
- }
- $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
- $createrid= $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- Db::startTrans();
- try{
- $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
- $examinfo[]=[
- "status"=>$status,
- "info_status"=>$ra_status,
- "remark"=>$remark,
- "adjunct"=>$adjunct,
- "adjunct_name"=>$adjunct_name,
- "createrid"=>$createrid,
- "creater"=>$creater
- ];
- $info['remark'] =$remark;
- $info['exam_info']=json_encode($examinfo) ;
- $info['updatetime'] =date("Y-m-d H:i:s");
- $up =Db::name("bargain_order")->save($info);
- if($up){
- //修改状态,添加待办
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_code" => $bargainNo,//咨询单详情编号
- "status" =>$ra_status,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "YJD", $info['status'], $info);
- $process=["order_code"=>$bargainNo,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'YJD',"before_status"=>$ra_status,'holder_id'=>$info['createrid']];
- ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname],$process);
- if($info['status']==1||$info['status']==2||$info['status']==3){
- $bidstatus=$bids['status'];
- $bids['status']=5;
- if($info['status']==1||$info['status']==3){
- $bids['sale_price']=$info['after_price'];
- if($bids['is_gold_price']==1){
- $bids['sale_cost_fee'] = $info['cost_after_price'];
- $bids['gold_price'] =isset($gold["price"])?$gold["price"]:0;
- }
- }else $bids['remark'] = $remark;
- $bids['updatetime']=date("Y-m-d H:i:s");
- $up =Db::name("consult_bids")->save($bids);
- if($up==false){
- Db::rollback();
- return error_show(1004,"数据更新失败");
- }
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_code" => $info["bidsNo"],//咨询单详情编号
- "status" => $bidstatus,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "FKD", $bids['status'], $bids);
- }
- Db::commit();
- return app_show(0,"更新成功");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- public function bargain_info(){
- $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
- if($bargainNo===""){
- return error_show(1004,"参数bargainNo不能为空");
- }
- $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
- if($info==false){
- return error_show(1004,"未找到议价数据");
- }
- $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
- if($bidinfos==false){
- return error_show(1004,"未找到商品数据");
- }
- $consultinfos =Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])->find();
- if($consultinfos==false){
- return error_show(1004,"未找到咨询商品数据");
- }
- $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
- $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
- $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
- $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
- $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
- $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
- if($bidinfos['brand_id']!=0){
- $info['brand_id'] = $bidinfos['brand_id'];
- $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
- $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
- }else{
- $info["brand_name"]="";
- $info["brand_id"]="";
- }
- // $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
- //获取竞价单详情
- $tmp = Db::name('consult_order')
- ->field('id,companyNo,platform_code,area')
- ->where(['is_del'=>0,'zxNo'=>$bidinfos['zxNo']])
- ->findOrEmpty();
- $catinfo = get_budget($bidinfos['cat_id'],$tmp['companyNo']??'',$tmp['platform_code']??0,true);
- if($catinfo===false) $this->error('未找到业务公司有关的平台分类毛利信息');
- $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
- $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
- $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
- $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
- $budget = isset($catinfo['rate']) ? $catinfo['rate']:0;
- $lower_rate = isset($catinfo['rate']) ? $catinfo['rate']:0;//业务烛光
- $info['budget'] =$budget;
- $info['area'] =$tmp['area'];
- $info['rate_status'] =0; //利率状态 0 业务主管利率无法通过 1 财务主管利率无法通过 2 boos利率无法通过 3 完全通过
- if($info['after_rate']>=$catinfo['rate']){
- //业务主管利率
- $info['rate_status'] =1;
- }
- $info['before_rate'] =round($info['before_rate']*100,2);
- $info['sale_price'] =round($bidinfos['origin_price'],2);
- $info['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
- $info['after_rate'] = round($info['after_rate']*100,2);
- $god=[
- "metal_id"=>$bidinfos['metal_id'],
- "weight"=>$bidinfos["good_weight"],
- "demo_fee"=>$bidinfos["demo_fee"],
- "delivery_fee"=>$bidinfos["delivery_fee"],
- "open_fee"=>$bidinfos["open_fee"],
- "packing_fee"=>$bidinfos["pakge_fee"],
- "mark_fee"=>$bidinfos["mark_fee"],
- "nake_fee"=>$bidinfos["nake_fee"],
- "cert_fee"=>$bidinfos["cert_fee"],
- "cost_fee"=>$bidinfos["cost_fee"],
- "num"=>$bidinfoe["num"],
- ];
- $info['gold_price']=0;
- $info['noble_weight']=$bidinfos['good_weight'];
- if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
- $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
- ->find();
- $info['gold_price'] =$gold['price'];
- $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);
- }else{
- if($bidinfos['nake_fee']!=0){
- $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);
- }else{
- $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);
- }
- }
- $info['cost_desc'] =$bidinfos['cost_desc'];
- $info['work_day'] =$bidinfos['work_day'];
- $info['delivery_day'] =$bidinfos['delivery_day'];
- $info['expire_day'] =$bidinfos['expire_day'];
- $info['origin_place'] =$bidinfos['origin_place'];
- $info['origin_addr'] ="";
- if($bidinfos['origin_place']!=''){
- $code = explode(",",$bidinfos['origin_place']);
- $temp=[];
- $temp['provice_code']=isset($code[0])?$code[0]:"";
- $temp['city_code']=isset($code[1])?$code[1]:"";
- $temp['area_code']=isset($code[2])?$code[2]:"";
- $addr= GetAddr(json_encode($temp));
- $info['origin_addr'] = $addr;
- }
- $info['supplierNo'] =$bidinfos['supplierNo'];
- $user= \app\admin\common\User::getIns();
- $supplier_temp =$user->handle("getCodeAndName",["code"=>$info['supplierNo']]);
- $supplier=$supplier_temp['data']??[];
- $info['supplier_name'] = $supplier[$info['supplierNo']]??"";
- $info['pay_way'] =$bidinfos['pay_way'];
- $info['tax'] =$bidinfos['tax'];
- $info['send_way'] =$bidinfos['send_way'];
- $info['metal_id'] =$bidinfos['metal_id'];
- $info['is_gold_price'] =$bidinfos['is_gold_price'];
- $info['config'] =$bidinfos['config'];
- $info['other_config'] =$bidinfos['other_config'];
- $info['weight'] =$bidinfos['weight'];
- $info['good_weight'] =$bidinfos['good_weight'];
- $info['is_diff'] =$bidinfos['is_diff'];
- $info['demo_fee'] =$bidinfos['demo_fee'];
- $info['delivery_fee'] =$bidinfos['delivery_fee'];
- $info['open_fee'] =$bidinfos['open_fee'];
- $info['pakge_fee'] =$bidinfos['pakge_fee'];
- $info['nake_fee'] =$bidinfos['nake_fee'];
- $info['mark_fee'] =$bidinfos['mark_fee'];
- $info['cert_fee'] =$bidinfos['cert_fee'];
- $info['cost_fee'] =$bidinfos['cost_fee'];
- $info['total_fee'] =$bidinfos['total_fee'];
- $info['supply_area'] =$bidinfos['supply_area'];
- $info['remark'] =$bidinfos['remark'];
- $info['is_addrs'] =$consultinfos['is_addrs'];
- $info['is_custom'] =$consultinfos['is_custom'];
- $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
- $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
- $info['lower_price'] =round($lower_price,2);
- //获取议价原因
- if ($info['result_info_id'] != 0) {
- $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
- } else {
- $info['result_info'] = '';
- }
- return app_show(0,"获取成功",$info);
- }
- public function bidlist(){
- $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
- $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
- $where=[['a.is_del',"=",0]];
- $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
- if ($zxNo !== "") {
- $where[] = ['a.zxNo','like','%'.$zxNo.'%'];
- }
- $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
- if ($infoNo !== "") {
- $where[] = ['a.infoNo','like','%'.$infoNo.'%'];
- }
- $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
- if ($bidNo !== "") {
- $where[] = ['bidNo','like','%'.$bidNo.'%'];
- }
- $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
- if ($pgNo !== "") {
- $where[] = ['c.pgNo','=',$pgNo];
- }
- $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
- if ($bargain_status !== "") {
- $where[] = ['bargain_status','=',$bargain_status];
- }
- $infoStatus = isset($this->post['info_status']) && !empty($this->post['info_status'])? $this->post['info_status'] : [];
- if (!empty($infoStatus)) {
- $where[] = ['c.status','in',$infoStatus];
- }
- $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
- if ($projectNo !== "") {
- $where[] = ['b.projectNo','=',$projectNo];
- }
- $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
- if($is_own==1){
- $rm= $this->uid;//isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $where[]=['a.createrid',"=",$rm];
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
- if ($status !== "") {
- $where[] = ['a.status','=',$status];
- }
- $tax_status = isset($this->post['tax_status']) && $this->post['tax_status'] !== "" ? intval($this->post['tax_status']) : "";
- if ($tax_status !== "") {
- $where[] = ['a.tax_status','=',$tax_status];
- }
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
- if ($companyNo !== "") {
- $where[] = ['companyNo','=',$companyNo];
- }
- $goodName = isset($this->post['goodName']) && $this->post['goodName'] !== "" ? trim($this->post['goodName']) : "";
- if ($goodName !== "") {
- $where[] = ['a.good_name','like','%'.$goodName.'%'];
- }
- $count = Db::name('consult_bids')->alias("a")
- ->leftJoin('consult_info c','a.infoNo=c.infoNo')
- ->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list =Db::name('consult_bids')->alias('a')
- ->leftJoin('consult_info c','a.infoNo=c.infoNo')
- ->leftJoin('consult_order b','a.zxNo=b.zxNo')
- ->where($where)
- ->field("a.*,b.companyNo,b.companyName,platform_code,c.num info_num,c.bargain_status,c.status info_status,
- b.creater order_creater,b.createrid order_createrid")
- ->order("a.id desc")
- ->page($page,$size)
- ->select()
- ->toArray();
- $data=[];
- $supplier = \app\model\Supplier::where(["code"=>array_column($list,"supplierNo"),"is_del"=>0])->column("name,legaler_type","code");
- $company = \app\model\Business::where(["companyNo"=>array_column($list,"companyNo"),"is_del"=>0])->column("legaler_type","companyNo");
- foreach ($list as $value){
- $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
- $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
- $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
- $value['supplierName'] = isset($supplier[$value['supplierNo']])?$supplier[$value['supplierNo']]['name']:"";
- $value['supplier_legaler_type'] = isset($supplier[$value['supplierNo']])?$supplier[$value['supplierNo']]['legaler_type']:"";
- $value['company_legaler_type'] = isset($company[$value['companyNo']])?$company[$value['companyNo']]:'';
- if($value['brand_id']!=0){
- $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
- $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
- }else{
- $value["brand_name"]="";
- $value["brand_id"]="";
- }
- $budget = get_budget($value['cat_id'],$value['companyNo']??'',$value['platform_code']??0);
- $god=[
- "metal_id"=>$value['metal_id'],
- "weight"=>$value["good_weight"],
- "demo_fee"=>$value["demo_fee"],
- "delivery_fee"=>$value["delivery_fee"],
- "open_fee"=>$value["open_fee"],
- "packing_fee"=>$value["pakge_fee"],
- "mark_fee"=>$value["mark_fee"],
- "nake_fee"=>$value["nake_fee"],
- "cert_fee"=>$value["cert_fee"],
- "cost_fee"=>$value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_cost_fee"]: $value["cost_fee"],
- "num"=>$value["info_num"],
- ];
- $top_cat = made($value['cat_id']);
- $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:0;
- if($value['is_gold_price']==1 && $top_cat_id==6 ){
- $price = GoldPrice($god, $budget);
- $value['sale_price'] = round($price,2);
- $value['origin_price'] = $value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_price"]:
- $value["origin_price"];
- }
- $value['cost_fee'] =$value['origin_cost_fee'];
- $value['specinfo'] = json_decode($value['specinfo'],true);
- $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
- //reject驳回原因,status==5表示驳回
- $value['reject']=[];
- if ($value['status'] >=5) {
- $value['reject'] = Db::name('bargain_order')
- ->field('id,remark,status')
- ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
- ->whereIn('status', 2)->order("id desc")
- ->find();
- }
- //产地
- $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
- if($value['delivery_place']!=""){
- list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['delivery_place']);
- }
- $value['delivery_place_cn']=GetAddr(json_encode($place));
- $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
- if($value['origin_place']!=""){
- list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['origin_place']);
- }
- $value['origin_addr']=GetAddr(json_encode($place));
- $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');
- $value['in_info'] = $tax[$value['tax_id']]??[];
- $value['out_info'] = $tax[$value['out_tax_id']]??[];
- $value['cgd_info'] = $tax[$value['cgd_tax_id']]??[];
- $good_info = Db::name('good_basic')
- ->field('id,createrid,creater')
- ->where('is_del',0)
- ->where('spuCode',$value['spuCode'])
- ->findOrEmpty();
- $value['good_createrid']=$good_info['createrid']??$value['createrid'];
- $value['good_creater']=$good_info['creater']??$value['creater'];
- $data[] = $value;
- }
- return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
- }
- public function feedlist(){
- $where=[['is_del',"=",0]];
- $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
- if ($zxNo !== "") {
- $where[] = ['zxNo','=',$zxNo];
- }
- $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
- if ($infoNo !== "") {
- $where[] = ['infoNo','=',$infoNo];
- }
- $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
- if ($bidNo !== "") {
- $where[] = ['bidNo','=',$bidNo];
- }
- $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
- if ($projectNo !== "") {
- $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
- ("zxNo");
- $where[] = ['zxNo','in',$zxlist];
- }
- $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
- if($is_own==1){
- $rm= $this->uid;//isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $where[]=['createrid',"=",$rm];
- }
- $list =Db::name('consult_bids')->where($where)->select();
- $data=[];
- $user= \app\admin\common\User::getIns();
- $supplier_temp =$user->handle("getCodeAndName",["code"=>array_column($list,"supplierNo")]);
- // if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) throw new Exception('该供应商不存在');
- $supplier=$supplier_temp['data']??[];
- foreach ($list as $value){
- // $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
- $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
- $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
- $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
- // $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
- $value['supplierName'] = isset($supplier[$value['supplierNo']])?$supplier[$value['supplierNo']]:"";
- if($value['brand_id']!=0){
- $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
- $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
- }else{
- $value["brand_name"]="";
- $value["brand_id"]="";
- }
- $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
- // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
- $zx = Db::name("consult_order")->where(["zxNo"=>$value["zxNo"]])->find();
- $budget = get_budget($value['cat_id'],$zx['companyNo']??'',$zx['platform_code']??0);
- if($budget===false) $this->error('未找到业务公司有关的平台分类毛利信息');
- $god=[
- "metal_id"=>$value['metal_id'],
- "weight"=>$value["good_weight"],
- "demo_fee"=>$value["demo_fee"],
- "delivery_fee"=>$value["delivery_fee"],
- "open_fee"=>$value["open_fee"],
- "packing_fee"=>$value["pakge_fee"],
- "mark_fee"=>$value["mark_fee"],
- "nake_fee"=>$value["nake_fee"],
- "cert_fee"=>$value["cert_fee"],
- "cost_fee"=>$value["cost_fee"],
- "num"=>$bidinfo["num"],
- ];
- if ($value['is_gold_price'] == 1 ) {
- $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
- ->find();
- //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
- //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
- $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num'] +$value["good_weight"] *$gold["price"] +
- $value["cost_fee"] * $value["good_weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
- // //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
- // $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"];
- }else{
- if($value["nake_fee"]){
- $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);
- }else{
- $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);
- }
- }
- $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
- $value['specinfo'] = json_decode($value['specinfo'],true);
- $value['bargain_status']=$bidinfo['bargain_status'];
- $data[]=$value;
- }
- return app_show(0,"获取成功",$data);
- }
- public function bragain_list()
- {
- $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
- $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
- $where = [['bo.is_del', "=", 0]];
- $bidsNo = isset($this->post['bidsNo']) && $this->post['bidsNo'] != "" ? trim($this->post['bidsNo']) : "";
- if ($bidsNo != "") {
- $where[] = ["bo.bidsNo", "like", "%$bidsNo%"];
- }
- $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
- if ($zxNo !== "") {
- $where[] = ['bo.zxNo', 'like', "%$zxNo%"];
- }
- $bargainNo = isset($this->post['bargainNo']) && $this->post['bargainNo'] !== "" ? trim($this->post['bargainNo']) : "";
- if ($bargainNo !== "") {
- $where[] = ['bo.bargainNo', 'like', "%$bargainNo%"];
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
- if ($status !== "") {
- $where[] = ['bo.status', '=', $status];
- }
- $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
- if ($infoNo !== "") {
- $where[] = ['bo.infoNo', 'like', "%$infoNo%"];
- }
- $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
- if ($projectNo !== "") {
- $zxlist = Db::name("consult_order")->where(["projectNo" => $projectNo, "is_del" => 0, "is_project" => 1])->column("zxNo");
- $where[] = ['bo.zxNo', 'in', $zxlist];
- }
- $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
- if ($pgNo !== "") {
- $bidinfo = Db::name("consult_info")->where([["pgNo", "=", $pgNo], ["is_del", "=", 0]])->column("infoNo");
- $where[] = ['bo.infoNo', 'in', $bidinfo];
- }
- $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
- if ($start != "") {
- $where[] = ["bo.addtime", ">=", date("Y-m-d H:i:s", strtotime($start))];
- }
- if ($end != "") {
- $where[] = ["bo.addtime", "<=", date("Y-m-d H:i:s", strtotime($end))];
- }
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
- if ($company_name !== "") $where[] = ["bo.createrid", 'in', get_company_item_user_by_name($company_name)];
- $companyNo = trim($this->post['companyNo'] ?? '');
- if ($companyNo !== "") $where[] = ["b.companyNo", 'like', '%' . $companyNo . '%'];
- $role = $this->checkDataShare();
- $hand = resign_hand_user($this->uid, 0);
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
- $where[] = ['bo.createrid', 'in', $arr];
- }
- $count = Db::name("bargain_order")
- ->alias('bo')
- ->leftJoin('consult_order b', 'b.zxNo=bo.zxNo')
- ->leftJoin('consult_info c', 'c.infoNo=bo.infoNo')
- ->where($where)
- ->count('bo.id');
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('bargain_order')
- ->alias('bo')
- ->field('bo.*,b.companyNo,b.area,c.num,b.platform_code')
- ->leftJoin('consult_order b', 'b.zxNo=bo.zxNo')
- ->leftJoin('consult_info c', 'c.infoNo=bo.infoNo')
- ->where($where)
- ->page($page, $size)
- ->order('bo.addtime', 'desc')
- ->select()
- ->toArray();
- $all_createrid = array_column($list, 'createrid');
- $item = get_company_name_by_uid($all_createrid);
- $userCommon = \app\admin\common\User::getIns();
- $names = $userCommon->handle('getCodeAndName', ['code' => array_column($list, 'companyNo')]);
- $bidinfos_list = Db::name('consult_bids')
- ->where(['is_del' => 0, 'bidNo' => array_column($list, 'bidsNo')])
- ->column('*', 'bidNo');
- $brand = Db::name("brand")
- ->where(["id" =>array_column($bidinfos_list,'brand_id')])
- ->column('brand_name', 'id');
- $cat = Db::name("cat")
- ->where(["id" => array_column($bidinfos_list,'cat_id')])
- ->column('order_rate', 'id');
- $unit = Db::name("unit")
- ->where(["id" => array_column($bidinfos_list,'unit_id')])
- ->column('unit', 'id');
- $data = [];
- foreach ($list as $value) {
- $value['companyName'] = $names['data'][$value['companyNo']] ?? '';
- $bidinfos = $bidinfos_list[$value['bidsNo']]??[];
- $value['spuCode'] = isset($bidinfos['spuCode']) ? $bidinfos['spuCode'] : "";
- $value['good_name'] = isset($bidinfos['good_name']) ? $bidinfos['good_name'] : "";
- $value['good_img'] = isset($bidinfos['good_img']) ? $bidinfos['good_img'] : "";
- $value['brand_id'] = isset($bidinfos['brand_id']) ? $bidinfos['brand_id'] : "";
- $value['brand_id'] = $bidinfos['brand_id']??0;
- $value['brand_name'] = $brand[$value['brand_id']] ?? '';
- $value['can'] = isset($bidinfos['cat_id']) && $bidinfos['cat_id'] != 0 ? made($bidinfos['cat_id']) : [];
- $value['unit'] = $unit[$bidinfos['unit_id']??0] ?? '';//isset($unit['unit'])?$unit['unit']:'';
- $budget = get_budget($bidinfos['cat_id']??0,$value['companyNo']??'',$value['platform_code']??0);
- if($budget===false) $this->error('未找到业务公司有关的平台分类毛利信息');
- $value['budget'] = $budget;
- $value['metal_name'] = isset($bidinfos['metal_id']) && $bidinfos['metal_id'] != 0 ? $this->noble[$bidinfos['metal_id']] : "";
- $value['sale_price'] = round($bidinfos['origin_price']??0, 2);
- $value['cost_before_price'] = round($bidinfos['origin_cost_fee']??0, 2);
- $value['specinfo'] = isset($bidinfos['specinfo']) && $bidinfos['specinfo'] != "" ? json_decode($bidinfos['specinfo'], true) : [];
- $value['company_name'] = $item[$value['createrid']] ?? '';
- //是否具有编辑权限
- $value['is_allow_update'] = 0;
- if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
- $data[] = $value;
- }
- return app_show(0, "获取成功", ["count" => $count, "list" => $data]);
- }
- //招标工作台
- public function crontablist(){
- $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
- $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
- $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
- $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
- if ($zxNo !== "") {
- $where[] = ['a.zxNo','=',$zxNo];
- }
- $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
- if ($salesman !== "") {
- //$where["salesman"] =Db::Raw("like '%$salesman%'");
- $where[]= ["b.salesman",'like',"%$salesman%"];
- }
- $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
- if ($cpName !== "") {
- //$where["cpName"]= Db::Raw("like '%$cpName%'");
- $where[]= ["a.good_Name",'like',"%$cpName%"];
- }
- $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
- if ($khNo !== "") {
- // $where['khNo'] = $khNo;
- $where[]= ["b.khNo",'like',"%$khNo%"];
- }
- $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
- if ($start !="") {
- //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
- $where[]= ["a.addtime",'>=',$start];
- }
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
- if($end !=""){
- $where[]= ["a.addtime",'<=',$end];
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
- if ($status !== "") {
- $where[]= ["a.status",'=',$status];
- }
- $userCommon=\app\admin\common\User::getIns();
- $supplierNo = trim($this->post['supplierNo'] ?? '');
- if ($supplierNo != '') {
- //如果筛选供应商,不查看同一家业务公司的数据
- $relaComArr = $userCommon->handle("hqInfo", ["code" => $supplierNo]);
- if ($relaComArr['data']['relation_code'] ?? '' != '') $where[] = ['b.companyNo', '<>', $relaComArr['data']['relation_code']];
- }
- //查看非本公司的竞价单
- $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != "" ? trim($this->post['relaComNo']) : "";
- if ($relaComNo != "") {
- if ($this->level == 3) {
- $relaComArr = $userCommon->handle("hqInfo", ["code" => $relaComNo]);
- $where[] = ['b.companyNo', '<>', $relaComArr['data']['relation_code'] ?? ''];
- }
- }
- $count = Db::name('consult_info')
- ->alias("a")
- ->leftJoin("consult_order b","a.zxNo=b.zxNo")
- ->leftJoin("platform c","c.id=b.platform_code")
- ->where($where)
- ->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list =Db::name('consult_info')
- ->alias("a")
- ->leftJoin("consult_order b","a.zxNo=b.zxNo")
- ->leftJoin("platform c","c.id=b.platform_code")
- ->where($where)
- ->page($page,$size)
- ->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")
- ->select()
- ->toArray();
- $data=[];
- $brand = Db::name('brand')
- ->whereIn('id',array_column($list,'brand_id'))
- ->column('brand_name','id');
- $names = $userCommon->handle('getCodeAndName',['code'=>array_unique(array_merge(array_column($list,'khNo'),array_column($list,'companyNo')))]);
- foreach ($list as $value){
- $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
- $budget = get_budget((int)$value['cat_id'], $value['companyNo'], (int)$value['platform_id']);
- $value['original_price']=sprintf("%.2f",$value['budget_price']* (1 -$budget));
- $value['brand_name']= $brand[$value['brand_id']]??'';//isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
- $value['khname'] = $value['companyName'] = "";
- $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],true):[];
- if($value['khNo']!==""){
- $value['khname']= $names['data'][$value['khNo']]??'';//isset($kh['companyName'])?$kh['companyName']:"";
- }
- if($value['companyNo']!='') $value['companyName'] = $names['data'][$value['companyNo']]??'';
- $consult =Db::name("consult_bids")
- ->where(["infoNo"=>$value['infoNo'],"createrid"=>$this->uid,"is_del"=>0])
- ->find();
- $consults =Db::name("consult_bids")
- ->where(["infoNo"=>$value['infoNo'],"is_del"=>0])
- ->find();
- $value['is_feed'] =$consult==false?0:1;
- $value['is_all_feed'] =$consults==false?0:1;
- $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
- $data[]=$value;
- }
- return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
- }
- //复制上面的bidlist方法,只更改排序方式
- public function bidlistCopy()
- {
- $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
- $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
- $where = [['cb.is_del', "=", 0]];//不要'取消转单'状态下的数据
- $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
- if ($zxNo !== "") $where[] = ['cb.zxNo', 'like', '%' . $zxNo . '%'];
- $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
- if ($infoNo !== "") $where[] = ['cb.infoNo', 'like', '%' . $infoNo . '%'];
- $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
- if ($bidNo !== "") $where[] = ['cb.bidNo', 'like', '%' . $bidNo . '%'];
- $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
- if ($pgNo !== "") {
- $bidinfo = Db::name("consult_info")->where([["pgNo", "=", $pgNo], ["is_del", "=", 0]])->column("infoNo");
- $where[] = ['cb.infoNo', 'in', $bidinfo];
- }
- $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
- if ($bargain_status !== "") {
- $bidinfo = Db::name("consult_info")->where([["bargain_status", "=", $bargain_status], ["is_del", "=", 0]])->column("infoNo");
- $where[] = ['cb.infoNo', 'in', $bidinfo];
- }
- $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
- if ($projectNo !== "") {
- $zxlist = Db::name("consult_order")->where(["projectNo" => $projectNo, "is_del" => 0, "is_project" => 1])->column("zxNo");
- $where[] = ['cb.zxNo', 'in', $zxlist];
- }
- $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
- if ($is_own == 1) {
- $rm = $this->uid;
- $where[] = ['cb.createrid', "=", $rm];
- }
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
- if ($company_name !== "") $where[] = ["cb.createrid", 'in', get_company_item_user_by_name($company_name)];
- $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
- if ($good_name !== "") $where[] = ["cb.good_name", 'like', '%' . $good_name . '%'];
- $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
- if ($supplierNo !== "") $where[] = ["cb.supplierNo", '=', $supplierNo];
- $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] !== "" ? trim($this->post['relaComNo']) : "";
- if ($relaComNo !== "") $where[] = ["d.companyNo", '=', $relaComNo];
- $companyNo = $this->post['companyNo']??'';
- if($companyNo!='') $where[]=['d.companyNo','like','%' .$this->post['companyNo']. '%'];
- $count = Db::name('consult_bids')
- ->alias('cb')
- ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
- ->leftJoin("consult_order d", "d.zxNo=c.zxNo")
- ->where($where)
- ->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('consult_bids')
- ->alias('cb')
- ->field('cb.*,d.companyNo,d.platform_code,d.area')
- ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
- ->leftJoin("consult_order d", "d.zxNo=c.zxNo")
- ->where($where)
- ->page($page, $size)
- ->order('cb.addtime', 'desc')
- ->select()
- ->toArray();
- $data = [];
- $user= \app\admin\common\User::getIns();
- $supplier_temp =$user->handle("getCodeAndName",["code"=>array_unique(array_merge(array_column($list,"supplierNo"),array_column($list,"companyNo")))]);
- $supplier=$supplier_temp['data']??[];
- $unit=Db::name('unit')
- ->where(['id'=>array_column($list,'unit_id'),'is_del'=>0])
- ->column('unit','id');
- $brand=Db::name('brand')
- ->where(['id'=>array_column($list,'brand_id'),'is_del'=>0])
- ->column('brand_name','id');
- $tmp_cat = [];
- foreach ($list as $value) {
- if(!isset($tmp_cat[$value['cat_id']])) $tmp_cat[$value['cat_id']] =made($value['cat_id']);
- $value['can'] = $tmp_cat[$value['cat_id']]??[];//isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
- $value['unit'] = $unit[$value['unit_id']]??'';//isset($unit['unit']) ? $unit['unit'] : '';
- $value['supplierName'] = isset($supplier[$value['supplierNo']]) ? $supplier[$value['supplierNo']] : "";
- $value['companyName'] = $supplier[$value['companyNo']]??'';
- $value["brand_name"] = $brand[$value['brand_id']] ?? '';//isset($brand['brand_name']) ? $brand['brand_name'] : "";
- $bidinfo = Db::name("consult_info")->where(["infoNo" => $value["infoNo"]])->find();
- $budget = get_budget((int)$value['cat_id'], $value['companyNo'], (int)$value['platform_code']);
- $god = [
- "metal_id" => $value['metal_id'],
- "weight" => $value["good_weight"],
- "demo_fee" => $value["demo_fee"],
- "delivery_fee" => $value["delivery_fee"],
- "open_fee" => $value["open_fee"],
- "packing_fee" => $value["pakge_fee"],
- "mark_fee" => $value["mark_fee"],
- "nake_fee" => $value["nake_fee"],
- "cert_fee" => $value["cert_fee"],
- "cost_fee" => $value["sale_cost_fee"]!=$value["origin_cost_fee"] ? $value["sale_cost_fee"] : $value["cost_fee"],
- "num" => $bidinfo["num"],
- ];
- if ($value['is_gold_price'] == 1) {
- $price = GoldPrice($god, $budget / 100);
- $value['sale_price'] = round($price, 2);
- }
- $value['cost_fee'] = $value['origin_cost_fee'];
- $value['specinfo'] = json_decode($value['specinfo'], true);
- $value['metal_name'] = isset($value['metal_id']) && $value['metal_id'] != 0 ? $this->noble[$value['metal_id']] : "";
- $value['bargain_status'] = $bidinfo['bargain_status'];
- //reject驳回原因,status==5表示驳回
- $value['reject'] = [];
- if ($value['status'] >= 5) {
- $value['reject'] = Db::name('bargain_order')
- ->field('id,remark,status')
- ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
- ->whereIn('status', 2)->order("id desc")
- ->find();
- }
- //产地
- $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
- if ($value['delivery_place'] != "") {
- list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['delivery_place']);
- }
- $value['delivery_place_cn'] = GetAddr(json_encode($place));
- $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
- if ($value['origin_place'] != "") {
- list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['origin_place']);
- }
- $value['origin_addr'] = GetAddr(json_encode($place));
- $value['company_name'] = $item[$value['createrid']]??'';
- $data[] = $value;
- }
- unset($tmp_cat);
- unset($list);
- return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
- }
- /**复制数据
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function zxcopy(){
- $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
- if($infoNo==""){
- return error_show(1004,"参数infoNo不能为空");
- }
- $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
- if($zxinfo==false){
- return error_show(1004,"未找到信息数据");
- }
- $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo']])->value("is_project",0);
- if($zxorder==1)return error_show(1003,"项目类型咨询单不可进行此项复制");
- $zxinfo['status']=0;
- $zxinfo['infoNo']=makeNo("IF");
- $zxinfo['id']=null;
- $zxinfo['bargain_status']=0;
- $zxinfo['updatetime']=date("Y-m-d H:i:s");
- $zxinfo['addtime']=date("Y-m-d H:i:s");
- $copy=Db::name("consult_info")->insert($zxinfo,true);
- if($copy==false)return error_show(1004,"咨询数据复制失败");
- return app_show(0,"咨询数据复制成功",["infoNo"=>$zxinfo['infoNo']]);
- }
- /**修改编辑复制数据
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function zxCopyEdit(){
- $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
- if($infoNo==""){
- return error_show(1004,"参数infoNo不能为空");
- }
- $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
- if($zxinfo==false){
- return error_show(1004,"未找到信息数据");
- }
- $temp_project = Db::name('consult_order')->field('id,projectNo,khNo,companyNo,area')->where(['zxNo'=>$zxinfo['zxNo'], 'is_del'=>0])->find();
- $area = isset($this->post['area']) && $this->post['area'] !=="" ? trim($this->post['area']) : $temp_project['area'];
- if($area==='')return error_show(1002,"客户区域不能为空");
- $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
- $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
- if($good_name==""){
- return error_show(1003,"参数good_name不能为空");
- }
- $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
- if($good_img==""){
- return error_show(1003,"参数good_img不能为空");
- }
- $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
- if($cat_id==""){
- return error_show(1003,"参数cat_id不能为空");
- }
- $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
- if($unit==""){
- return error_show(1003,"参数unit不能为空");
- }
- $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
- $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
- if($arrival_time==""){
- return error_show(1003,"参数arrival_time不能为空");
- }
- $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
- if($specin==""){
- return error_show(1003,"参数specinfo不能为空");
- }
- $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
- // if($cost_desc==""){
- // return error_show(1003,"参数cost_desc不能为空");
- // }
- $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
- if($is_addrs===""){
- return error_show(1003,"参数is_addrs不能为空");
- }
- $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
- if($is_custom===""){
- return error_show(1003,"参数is_custom不能为空");
- }
- $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
- if($metal_id===""){
- return error_show(1003,"参数metal_id不能为空");
- }
- $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
- $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
- $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
- $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
- $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
- $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
- $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
- $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
- if($num===""){
- return error_show(1003,"参数num不能为空");
- }
- if($budget_price===""){
- return error_show(1003,"参数budget_price不能为空");
- }
- $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
- $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
- $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
- if($remark==""){
- return error_show(1003,"参数remark不能为空");
- }
- $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
- if($endtime==""){
- return error_show(1003,"参数endtime不能为空");
- }
- if($metal_id!=0){
- if($config==""){
- return error_show(1003,"参数config不能为空");
- }
- if($other_config==""){
- return error_show(1003,"参数other_config不能为空");
- }
- if($specs_weight===""){
- return error_show(1003,"参数specs_weight不能为空");
- }
- if($gold_price===""){
- return error_show(1003,"参数gold_price不能为空");
- }
- }
- $specinfo=[];
- foreach ($specin as $v){
- $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
- $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
- $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
- $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
- $specinfo[]=$v;
- }
- Db::startTrans();
- try{
- $info=[
- "good_name"=>$good_name,
- "good_img"=>$good_img,
- "cat_id"=>$cat_id,
- "unit"=>$unit,
- "brand_id"=>$brand_id,
- "arrival_time"=>$arrival_time,
- "specinfo"=>json_encode($specinfo),
- "cost_desc"=>$cost_desc,
- "is_addrs"=>$is_addrs,
- "is_custom"=>$is_custom,
- "metal_id"=>$metal_id,
- "config"=>$config,
- "other_config"=>$other_config,
- "specs_weight"=>$specs_weight===""?0:$specs_weight,
- "gold_price"=>$gold_price===""? 0 : $gold_price,
- "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
- "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
- "budget_price"=>$budget_price,
- "num"=>$num,
- "pgNo"=>$pgNo,
- "use_desc"=>$use_desc,
- "remark"=>$remark,
- "bargain_num"=>$zxinfo['bargain_num']+1,
- "status"=>1,
- "is_del"=>0,
- "updatetime"=>date("Y-m-d H:i:s"),
- 'bargain_status'=>1,
- 'enclosure_file'=>$enclosure_file
- ];
- $up = Db::name("consult_info")->where($zxinfo)->update($info);
- if($up){
- //操作记录
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $infoNo,//咨询单详情编号
- "status" => 0,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "edit"//新建create,编辑edit,更改状态status
- ], "ZXD", 1, $this->post);
- //更新consule_order记录
- $op = Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,'area'=>$area, 'updatetime'=>date('Y-m-d H:i:s')]);
- if($op==false)throw new \Exception("咨询单结束时间更新失败");
- //维护台账记录
- $insert_standing_book_data=[
- 'standBookNo'=>makeNo('IO'),
- 'infoNo'=>$infoNo,
- 'addtime' => date('Y-m-d H:i:s'),
- 'updatetime' => date('Y-m-d H:i:s')
- ];
- if(!empty($temp_project)){
- $insert_standing_book_data['companyNo']=$temp_project['companyNo'];
- $insert_standing_book_data['customer_code']=$temp_project['khNo'];
- }
- Db::name('standing_book')->insert($insert_standing_book_data);
- Db::commit();
- return app_show(0,"咨询修改成功",["infoNo"=>$infoNo]);
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- }
|