Consult.php 129 KB

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