Consult.php 126 KB

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