Consult.php 149 KB

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