123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\ActionLog;
- use app\admin\model\DataGroup as DataGroupModel;
- use app\admin\model\ProcessOrder;
- 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%"];
- }
- $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];
- }
- $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->checkRole();
- // if(!empty($role['write'])){
- // $where[]=["b.createrid","in",$role['write']];
- // }
- // $role = $this->checkDataShare();
- // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["b.createrid", "in", $role[DataGroupModel::$type_全部]];
- $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];
- }
- // if(!empty($role['platform']) ){
- // $where[]=["b.platform_code","in",$role['platform']];
- // }
- $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")
- ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
- ->where($where)
- ->page($page, $size)
- ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart,u.itemid")
- ->order("a.id desc")
- ->cursor();
- $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):[];
- $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
- $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
- $value['khname']="";
- if($value['khNo']!==""){
- $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
- $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
- }
- $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
- $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
- //是否具有编辑权限
- $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 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 del(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
- $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
- if($de==false){
- return error_show(1002,'咨询单信息未找到');
- }
- $dell= Db::name('consult')->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不能为空");
- }
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
- if($companyNo===""){
- return error_show(1002,"参数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不能为空");
- }
- $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
- if($ladder==""){
- return error_show(1005,"参数ladder不能为空");
- }
- $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(105,"参数token不能为空");
- }
- $pay_id = isset($this->post['pay_id']) && $this->post['pay_id'] !== "" ? intval($this->post['pay_id']) : "0";
- if($pay_id!=0){
- $payinfo =Db::name("pay")->where("id",$pay_id)->findOrEmpty();
- if(empty($payinfo)) return error_show(1004, "支付渠道信息未找到");
- if($payinfo['status']!=1)return error_show(1004, "支付渠道已禁用");
- $supplierArr =Db::name("pay_rate")->where(["pay_id"=>$pay_id,"status"=>1,"is_del"=>0])->column("companyNo");
- if(in_array($companyNo,$supplierArr)) return error_show(1004, "支付渠道含有该业务公司,支付渠道无法使用!");
- }
- $user =GetUserInfo($token);
- if(empty($user)||$user['code']!=0){
- return error_show(102,"用户数据不存在");
- }
- $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
- $zxNo=makeNo("ZX");
- Db::startTrans();
- try{
- $data=[
- "zxNo"=>$zxNo,
- "createrid"=>$createrid,
- "creater"=>$creater,
- "is_project"=>$is_project,
- "projectNo"=>isset($projectNo) ? $projectNo:"",
- "khNo"=>$khNo,
- "companyNo"=>$companyNo,
- "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());
- }
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- 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,"未找到咨询信息数据");
- }
- $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
- $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
- $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/100));
- $zxinfo['khNo']="";
- $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);
- $zxinfo['pay_name'] = $zxorder['pay_id']==0?"":Db::name("pay")->where("id",$zxorder['pay_id'])->value("pay_name",'');
- $zxinfo['pay_id'] = $zxorder['pay_id'];
- if($zxorder['khNo']!==""){
- $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
- $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
- $zxinfo['khNo']= $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']:"";
- }
- if($zxorder['companyNo']!==""){
- $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
- $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
- }
- 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){
- $zxinfo['departinfo']=GetPart($zxorder['depart']);
- }
- 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']):"";
- 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']):"";
- // if($use_desc==""){
- // return error_show(1003,"参数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不能为空");
- }
- }
- $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(102,"参数token不能为空");
- }
- $user =GetUserInfo($token);
- if(empty($user)||$user['code']!=0){
- return error_show(105,"用户数据不存在");
- }
- $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;
- }
- $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
- 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),
- // "color"=>$color,
- // "material"=>$material,
- "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($this->post['token'], [
- "order_code" => $innew,//咨询单详情编号
- "status" => 1,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "edit"//新建create,编辑edit,更改状态status
- ], "ZXD", 1, $this->post);
- // ProcessOrder::AddProcess($this->post['token'], [
- // "order_type" => 'ZXD',
- // "order_code" => $innew,//咨询单详情编号
- // "order_id" => 0,
- // "order_status" => 1
- // ]);
- if (!empty($bidlist)){
- foreach ($bidlist as $value){
- unset($value['id']);
- $value['infoNo']=$innew;
- $value['bidNo']=makeNo("BD");
- $value['spuCode']=makeNo("SKU");
- $value['status'] =0;
- $value['updatetime'] =date("Y-m-d H:i:s");
- $in = Db::name("consult_bids")->insert($value);
- if($in==false){
- Db::rollback();
- return error_show(1004,"反馈商品新建失败");
- }
- ActionLog::logAdd($this->post['token'], [
- "order_code" => $innew,//咨询单详情编号
- "status" => 1,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "edit"//新建create,编辑edit,更改状态status
- ], "FKD", 1, $this->post);
- }
- }
- $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){
- Db::rollback();
- return error_show(1004,"反馈商品更新失败");
- }else{
- //修改状态,添加待办
- ActionLog::logAdd($this->post['token'], [
- "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,
- 'updatetime'=>date('Y-m-d H:i:s')]);
- if($op==false){
- Db::rollback();
- return error_show(1004,'咨询单结束时间更新失败');
- }
- //维护台账记录
- $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不能为空");
- }
- // if($status==1&&$zxinfo['status']>1){
- // $zxinfo['bargain_num']=+1;
- // }
- $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){
- //修改状态,添加待办
- ActionLog::logAdd($this->post['token'], [
- "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,"未找咨询信息数据");
- }
- $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
- if($pname==""){
- return error_show(1002,"参数pname不能为空");
- }
- $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
- $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']):"";
- $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不能为空");
- }
- $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(1002,"参数token不能为空");
- }
- $user =GetUserInfo($token);
- if(empty($user)||$user['code']!=0){
- return error_show(1005,"用户数据不存在");
- }
- $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $bidNo=makeNo("BD");
- $spucode=makeNo("SKU");
- $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
- $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
- //部分参数的大小校验
- $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 = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
- //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
- $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 = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_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;
- }
- }
- $supplier = Db::name('supplier')
- ->field('id,person,personid')
- ->where('code',$supplierNo)
- ->findOrEmpty();
- $data=[
- "bidNo"=>$bidNo,
- "infoNo"=>$infoNo,
- "zxNo"=>$zxinfo['zxNo'],
- "spuCode"=>$spucode,
- "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,
- "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,
- "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,
- ];
- 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']=$pname;
- $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($this->post['token'], [
- "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($this->post['token'], [
- "order_code" => $projetc['projectNo'],//项目编码
- "status" => 1,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "PRO", 2, $projetc);
- ProcessOrder::AddProcess($this->post['token'], [
- "order_type" => 'PRO',
- "order_code" => $projetc['projectNo'],
- "order_id" => $projetc['id'],
- "order_status" => 2,"before_status"=>1
- ]);
- }
- }
- }
- }
- }
- }
- 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,"未找到商品数据");
- }
- $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'];
- $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
- $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
- 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"]="";
- }
- $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
- $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
- $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
- $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/100);
- $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['good_img'] = explode(',',$info['good_img']);
- //添加商品创建人字段
- $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['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
- if($pname==""){
- return error_show(1002,"参数pname不能为空");
- }
- $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
- // if($brandid==""){
- // return error_show(1002,"参数brandid不能为空");
- // }
- $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']):"";
- $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不能为空");
- }
- $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
- $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
- $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;
- }
- Db::startTrans();
- try{
- $data=[
- "good_name"=>$pname,
- "brand_id"=>$brandid,
- "cat_id"=>$cat_id,
- "specinfo"=>json_encode($specinfo),
- // "material"=>$material,
- "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,
- "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
- ];
- $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($this->post['token'] , [
- "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($this->post['token'] , [
- "order_code"=>$projectinfo['projectNo'] ,//项目编码
- "status"=>1 ,//这里的status是之前的值
- "action_remark"=>'' ,//备注
- "action_type"=>"status"//新建create,编辑edit,更改状态status
- ] , "PRO" , 2 , $this->post
- );
- ProcessOrder::AddProcess($this->post['token'] , [
- "order_type"=>'PRO' ,
- "order_code"=>$projectinfo['projectNo'] ,
- "order_id"=>$project_id ,
- "order_status"=>2 , "before_status"=>1
- ]
- );
- }
- }
- }
- }
- }
- }
- }
- 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']):"";
- // if($bargain_reason===""){
- // return error_show(1004,"参数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,"咨询单招标未结束或已确认商品");
- }
- $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(105,"参数token不能为空");
- }
- $user =GetUserInfo($token);
- if(empty($user)||$user['code']!=0){
- return error_show(1002,"用户数据不存在");
- }
- //新增两个字段
- //议价备注
- $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= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= 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'],2),
- "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
- "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($this->post['token'], [
- "order_code" => $bargainNo,//咨询单详情编号
- "status" => 0,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "YJD", $data['status'], $data);
- ProcessOrder::AddProcess($this->post['token'], [
- "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($this->post['token'], [
- "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($this->post['token'], [
- "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(){
- $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($this->post['token'], [
- "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($this->post['token'], [
- "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 驳回
- */
- 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']==12){
- 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不能为空");
- }
- $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
- $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
- $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
- $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
- $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
- 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 = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
- //$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);
- $money_price =$total_fe / (1 - $money_rate);
- $lower_price =$total_fe / (1 - $lower_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){
- $saleprice = ($total_fe)/ (1 - $budget);
- $rate_price = ($total_fe)/ (1 - $rate);
- $money_price =($total_fe)/ (1 - $money_rate);
- $lower_price = ($total_fe) / (1 - $lower_rate);
- }else{
- $saleprice = $total_fe / (1 - $budget);
- $rate_price =$total_fe/ (1 - $rate);
- $money_price =$total_fe / (1 - $money_rate);
- $lower_price = $total_fe/ (1 - $lower_rate);
- }
- }
- $ra_status = $info['status'];
- if($status==1){
- if($info['status']==0){
- if($info['after_price']<$rate_price){
- $info['status']=2;
- }else{
- $info['status']=1;
- }
- }elseif($info['status']==2){
- $info['status']=4;
- }elseif($info['status']==4||$info['status']==5){
- if($info['after_price']<$money_price){
- $info['status']=7;
- }else{
- $info['status']=6;
- }
- }elseif($info['status']==7){
- $info['lower_price'] =$lower_price;
- if($info['after_price']<$lower_price){
- $info['status']=10;
- }else{
- $info['status']=9;
- }
- }
- }else{
- if($info['status']==0){
- $info['status']=3;
- }elseif($info['status']==2){
- $info['status']=4;
- }elseif($info['status']==4||$info['status']==5){
- $info['status']=8;
- }elseif($info['status']==7){
- $info['lower_price'] =$lower_price;
- $info['status']=11;
- }
- }
- $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
- $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(105,"参数token不能为空");
- }
- $user =GetUserInfo($token);
- if(empty($user)||$user['code']!=0){
- return error_show(1002,"用户数据不存在");
- }
- $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= 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,"createrid"=>$createrid,
- "creater"=>$creater];
- // $info['status'] =$status;
- $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($this->post['token'], [
- "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($token,$process);
- if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
- $bidstatus=$bids['status'];
- $bids['status']=5;
- if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
- $bids['sale_price']=$info['after_price'];
- 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();
- // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
- // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
- $bids['sale_cost_fee'] = $info['cost_after_price'];
- $bids['gold_price'] =isset($gold["price"])?$gold["price"]:0;
- }
- }
- $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($this->post['token'], [
- "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['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);
- $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();
- $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['order_rate']) ? $catinfo['order_rate']:0;
- $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
- $info['budget'] =$budget;
- $info['rate_status'] =0; //利率状态 0 业务主管利率无法通过 1 财务主管利率无法通过 2 boos利率无法通过 3 完全通过
- if($info['after_rate']>=$catinfo['rate']){
- //业务主管利率
- $info['rate_status'] =1;
- }
- elseif ($info['after_rate']>=$catinfo['money_rate']){
- //财务主管利率
- $info['rate_status'] =2;
- }
- elseif ($info['after_rate']>=$catinfo['lower_rate']){
- //boss利率
- $info['rate_status'] =3;
- }
- $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'];
- $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
- $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
- $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['sale_price'] =round($bidinfos['sale_price'],2);//议价前价格
- $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
- if($info['status']==7){
- $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=[['is_del',"=",0]];
- $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
- if ($zxNo !== "") {
- $where[] = ['zxNo','like','%'.$zxNo.'%'];
- }
- $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
- if ($infoNo !== "") {
- $where[] = ['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 !== "") {
- $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
- $where[] = ['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[] = ['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[] = ['zxNo','in',$zxlist];
- }
- $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
- if($is_own==1){
- $token = isset($this->post['token']) ? trim($this->post['token']) : "";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $apply_id =GetUserInfo($token);
- if(empty($apply_id)||$apply_id['code']!=0){
- return error_show(1002,"申请人数据不存在");
- }
- $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $where[]=['createrid',"=",$rm];
- }
- $count = Db::name('consult_bids')->where($where)->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
- $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['name'])?$supplier['name']:"";
- 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;
- $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"],
- "cost_fee"=>$value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_cost_fee"]: $value["cost_fee"],
- //暂时注掉,搞不清楚原因@吴广广
- "num"=>$bidinfo["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/100);
- $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']]:"";
- $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', [3,8,11])->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));
- // if($value['origin_place']!=''){
- // $code = explode(",",$value['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));
- // $value['origin_addr'] = $addr;
- // }
- $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];
- }
- $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(102,"参数token不能为空");
- }
- $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
- if($is_own==1){
- $token = isset($this->post['token']) ? trim($this->post['token']) : "";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $apply_id =GetUserInfo($token);
- if(empty($apply_id)||$apply_id['code']!=0){
- return error_show(1002,"申请人数据不存在");
- }
- $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $where[]=['createrid',"=",$rm];
- }
- $list =Db::name('consult_bids')->where($where)->select();
- $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['name'])?$supplier['name']:"";
- 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;
- $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)];
- // $role=$this->checkRole();
- // if(!empty($role['write'])){
- // $where[]=["bo.createrid","in",$role['write']];
- // }
- // $role = $this->checkDataShare();
- // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ['bo.createrid', 'in', $role[DataGroupModel::$type_全部]];
- $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("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
- ->where($where)
- ->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('bargain_order')
- ->alias('bo')
- ->field('bo.*,u.itemid')
- ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
- ->where($where)
- ->page($page, $size)
- ->order('bo.addtime', 'desc')
- ->cursor();
- $data=[];
- foreach ($list as $value){
- $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
- $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']:"";
- if($bidinfos['brand_id']!=0){
- $value['brand_id'] = $bidinfos['brand_id'];
- $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
- $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
- }else{
- $value["brand_name"]="";
- $value["brand_id"]="";
- }
- $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
- $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
- $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
- $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
- $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
- $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
- $value['budget'] =$budget;
- $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"],
- ];
- // if($bidinfos['is_gold_price']==1){
- // $price = GoldPrice($god, $budget/100);
- // }else{
- // $price = GoodPrice($god, $budget/100);
- // }
- $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
- $value['sale_price'] =round($bidinfos['origin_price'],2);
- $value['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
- $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
- $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
- //是否具有编辑权限
- $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,"获取成功",["list"=>$data,"count"=>$count]);
- }
- 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];
- }
- // $role=$this->checkRole();
- // if(!empty($role['platform']) ){
- // $where[]=["b.platform_code","in",$role['platform']];
- // }
- $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.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
- $data=[];
- foreach ($list as $value){
- $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
- $cat =Db::name("cat")->where(["id"=>$value['cat_id']])->find();
- $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
- $value['original_price']=sprintf("%.2f",$value['budget_price']* (1 -$budget/100));
- $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
- $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
- $value['khname']="";
- $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
- true):[];
- if($value['khNo']!==""){
- $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
- $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
- }
- $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],['c.status','<>',6]];//不要'取消转单'状态下的数据
- $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) {
- $token = isset($this->post['token']) ? trim($this->post['token']) : "";
- if ($token == "") return error_show(101, 'token不能为空');
- $apply_id = GetUserInfo($token);
- if (empty($apply_id) || $apply_id['code'] != 0) return error_show(1002, "申请人数据不存在");
- $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $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 . '%'];
- $supplierName = isset($this->post['supplierName']) && $this->post['supplierName'] !== "" ? trim($this->post['supplierName']) : "";
- if ($supplierName !== "") $where[] = ["s.name", 'like', '%' . $supplierName . '%'];
- $count = Db::name('consult_bids')
- ->alias('cb')
- ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
- ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
- ->leftJoin('supplier s', 's.code=cb.supplierNo')
- ->where($where)
- ->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('consult_bids')
- ->alias('cb')
- ->field('cb.*,u.itemid,s.name supplierName')
- ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
- ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
- ->leftJoin('supplier s', 's.code=cb.supplierNo')
- ->where($where)
- ->page($page, $size)
- ->order('cb.addtime', 'desc')
- ->cursor();
- $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['name']) ? $supplier['name'] : "";
- 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;
- $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', [3, 8, 11])->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));
- // if($value['origin_place']!=''){
- // $code = explode(",",$value['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));
- // $value['origin_addr'] = $addr;
- // }
- $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
- $data[] = $value;
- }
- return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
- }
- }
|