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