Consult.php 153 KB

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