Consult.php 153 KB

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