Consult.php 152 KB

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