Consult.php 155 KB

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