Consult.php 129 KB

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