Consult.php 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644
  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','=',$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. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  59. ->count();
  60. $total = ceil($count / $size);
  61. $page = $page >= $total ? $total : $page;
  62. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  63. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->order("a.id desc")->select();
  64. $data=[];
  65. foreach ($list as $value){
  66. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  67. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  68. true):[];
  69. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  70. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  71. $value['khname']="";
  72. if($value['khNo']!==""){
  73. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  74. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  75. }
  76. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  77. $data[]=$value;
  78. }
  79. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  80. }
  81. public function info(){
  82. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  83. if($id==""){
  84. return error_show(1002,"咨询单编号不能为空");
  85. }
  86. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  87. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  88. $fo['can']=$in;
  89. if(empty($fo)){
  90. return error_show(1002,"未找到咨询单编号");
  91. }else{
  92. return app_show(0,"获取成功",$fo);
  93. }
  94. }
  95. public function del(){
  96. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  97. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  98. if($de==false){
  99. return error_show(1002,'咨询单信息未找到');
  100. }
  101. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  102. if($dell){
  103. return error_show(0,"删除成功");
  104. }else
  105. return error_show(1002,"删除失败");
  106. }
  107. public function create(){
  108. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  109. if($is_project===""){
  110. return error_show(1002,"参数is_project不能为空");
  111. }
  112. if($is_project==1){
  113. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  114. if($projectNo===""){
  115. return error_show(1002,"参数projectNo不能为空");
  116. }
  117. }
  118. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  119. if($khNo===""){
  120. return error_show(1002,"参数khNo不能为空");
  121. }
  122. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  123. if($companyNo===""){
  124. return error_show(1002,"参数companyNo不能为空");
  125. }
  126. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  127. if($endtime===""){
  128. return error_show(1002,"参数endtime不能为空");
  129. }
  130. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  131. "";
  132. if($platform_code===""){
  133. return error_show(1002,"参数platform_code不能为空");
  134. }
  135. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  136. if($ladder==""){
  137. return error_show(1005,"参数ladder不能为空");
  138. }
  139. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  140. if($token==''){
  141. return error_show(105,"参数token不能为空");
  142. }
  143. $user =GetUserInfo($token);
  144. if(empty($user)||$user['code']!=0){
  145. return error_show(102,"用户数据不存在");
  146. }
  147. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  148. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  149. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  150. $zxNo=makeNo("ZX");
  151. Db::startTrans();
  152. try{
  153. $data=[
  154. "zxNo"=>$zxNo,
  155. "createrid"=>$createrid,
  156. "creater"=>$creater,
  157. "is_project"=>$is_project,
  158. "projectNo"=>isset($projectNo) ? $projectNo:"",
  159. "khNo"=>$khNo,
  160. "companyNo"=>$companyNo,
  161. "endtime"=>$endtime,
  162. "salesman"=>$creater,
  163. "platform_code"=>$platform_code,
  164. "saleid"=>$createrid,
  165. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  166. "status"=>0,
  167. "is_del"=>0,
  168. "addtime"=>date("Y-m-d H:i:s"),
  169. "updatetime"=>date("Y-m-d H:i:s"),
  170. ];
  171. $zx = Db::name("consult_order")->insert($data);
  172. if($zx){
  173. foreach ($ladder as $value){
  174. $infoNo=makeNo("IF");
  175. $specinfo=[];
  176. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  177. foreach ($value["specinfo"] as $v){
  178. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  179. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  180. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  181. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  182. $specinfo[]=$v;
  183. }
  184. }
  185. $info=[
  186. "infoNo"=>$infoNo,
  187. "zxNo"=>$zxNo,
  188. "spuCode"=>"",
  189. "good_name"=>$value['good_name'],
  190. "good_img"=>$value['good_img'],
  191. "cat_id"=>$value['cat_id'],
  192. "unit"=>$value['unit'],
  193. "brand_id"=>$value['brand_id'],
  194. "arrival_time"=>$value['arrival_time'],
  195. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  196. "cost_desc"=>$value['cost_desc'],
  197. "is_addrs"=>$value['is_addrs'],
  198. "is_custom"=>$value['is_custom'],
  199. "metal_id"=>$value['metal_id'],
  200. "config"=>isset($value['config'])?$value['config']:"",
  201. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  202. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  203. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  204. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  205. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  206. "budget_price"=>$value['budget_price'],
  207. "num"=>$value['num'],
  208. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  209. "use_desc"=>$value['use_desc'],
  210. "remark"=>$value['remark'],
  211. "status"=>1,
  212. "is_del"=>0,
  213. "addtime"=>date("Y-m-d H:i:s"),
  214. "updatetime"=>date("Y-m-d H:i:s")
  215. ];
  216. $up = Db::name("consult_info")->insert($info);
  217. if(!$up){
  218. Db::rollback();
  219. return error_show(1004,'添加失败');
  220. }
  221. }
  222. $stn = ["order_code"=>$zxNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  223. ActionLog::logAdd($this->post['token'],$stn,"ZXD",2,$info);
  224. $process=["order_code"=>$zxNo,"order_id"=>Db::name("consult_order")->getLastInsID(),"order_status"=>1,"order_type"=>'ZXD'];
  225. ProcessOrder::AddProcess($this->post['token'],$process);
  226. Db::commit();
  227. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  228. }else{
  229. Db::rollback();
  230. return error_show(1004,"新建失败");
  231. }
  232. }catch (\Exception $e){
  233. Db::rollback();
  234. return error_show(1003,$e->getMessage());
  235. }
  236. }
  237. public function zxinfo(){
  238. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  239. if($infoNo==""){
  240. return error_show(1004,"参数infoNo不能为空");
  241. }
  242. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  243. if($zxinfo==false){
  244. return error_show(1004,"未找到信息数据");
  245. }
  246. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  247. if($zxorder==false){
  248. return error_show(1004,"未找到咨询信息数据");
  249. }
  250. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  251. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  252. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  253. $zxinfo['khname']="";
  254. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  255. $zxinfo['khNo']="";
  256. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  257. $zxinfo['brand']="";
  258. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  259. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  260. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  261. $zxinfo['company']="";
  262. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  263. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  264. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  265. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  266. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  267. $zxinfo['project_name']="";
  268. $zxinfo['budget_total']="";
  269. $zxinfo['departinfo']=[];
  270. $zxinfo['unit_name']="";
  271. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  272. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  273. if($zxorder['khNo']!==""){
  274. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  275. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  276. $zxinfo['khNo']= $zxorder['khNo'];
  277. }
  278. if($zxinfo['unit']!==""){
  279. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  280. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  281. }
  282. if($zxinfo['brand_id']!==""){
  283. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  284. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  285. }
  286. if($zxorder['companyNo']!==""){
  287. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  288. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  289. }
  290. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  291. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  292. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  293. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  294. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  295. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  296. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  297. }
  298. if($zxorder['depart']>0){
  299. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  300. }
  301. if($zxorder['platform_code']>0){
  302. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  303. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  304. }
  305. return app_show(0,"获取成功",$zxinfo);
  306. }
  307. public function zxedit(){
  308. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  309. if($infoNo==""){
  310. return error_show(1004,"参数infoNo不能为空");
  311. }
  312. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  313. if($zxinfo==false){
  314. return error_show(1004,"未找到信息数据");
  315. }
  316. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  317. if($good_name==""){
  318. return error_show(1003,"参数good_name不能为空");
  319. }
  320. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  321. if($good_img==""){
  322. return error_show(1003,"参数good_img不能为空");
  323. }
  324. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  325. if($cat_id==""){
  326. return error_show(1003,"参数cat_id不能为空");
  327. }
  328. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  329. if($unit==""){
  330. return error_show(1003,"参数unit不能为空");
  331. }
  332. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  333. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  334. if($arrival_time==""){
  335. return error_show(1003,"参数arrival_time不能为空");
  336. }
  337. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  338. if($specin==""){
  339. return error_show(1003,"参数specinfo不能为空");
  340. }
  341. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  342. if($cost_desc==""){
  343. return error_show(1003,"参数cost_desc不能为空");
  344. }
  345. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  346. if($is_addrs===""){
  347. return error_show(1003,"参数is_addrs不能为空");
  348. }
  349. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  350. if($is_custom===""){
  351. return error_show(1003,"参数is_custom不能为空");
  352. }
  353. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  354. if($metal_id===""){
  355. return error_show(1003,"参数metal_id不能为空");
  356. }
  357. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  358. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  359. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  360. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  361. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  362. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  363. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  364. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  365. if($num===""){
  366. return error_show(1003,"参数num不能为空");
  367. }
  368. if($budget_price===""){
  369. return error_show(1003,"参数budget_price不能为空");
  370. }
  371. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  372. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  373. if($use_desc==""){
  374. return error_show(1003,"参数use_desc不能为空");
  375. }
  376. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  377. if($remark==""){
  378. return error_show(1003,"参数remark不能为空");
  379. }
  380. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  381. if($endtime==""){
  382. return error_show(1003,"参数endtime不能为空");
  383. }
  384. if($metal_id!=0){
  385. if($config==""){
  386. return error_show(1003,"参数config不能为空");
  387. }
  388. if($other_config==""){
  389. return error_show(1003,"参数other_config不能为空");
  390. }
  391. if($specs_weight===""){
  392. return error_show(1003,"参数specs_weight不能为空");
  393. }
  394. if($gold_price===""){
  395. return error_show(1003,"参数gold_price不能为空");
  396. }
  397. }
  398. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  399. if($token==''){
  400. return error_show(102,"参数token不能为空");
  401. }
  402. $user =GetUserInfo($token);
  403. if(empty($user)||$user['code']!=0){
  404. return error_show(105,"用户数据不存在");
  405. }
  406. $specinfo=[];
  407. foreach ($specin as $v){
  408. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  409. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  410. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  411. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  412. $specinfo[]=$v;
  413. }
  414. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  415. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  416. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  417. Db::startTrans();
  418. try{
  419. $innew =makeNo("IF");
  420. $info=[
  421. "infoNo"=>$innew,
  422. "zxNo"=>$zxinfo['zxNo'],
  423. "spuCode"=>"",
  424. "good_name"=>$good_name,
  425. "good_img"=>$good_img,
  426. "cat_id"=>$cat_id,
  427. "unit"=>$unit,
  428. "brand_id"=>$brand_id,
  429. "arrival_time"=>$arrival_time,
  430. "specinfo"=>json_encode($specinfo),
  431. // "color"=>$color,
  432. // "material"=>$material,
  433. "cost_desc"=>$cost_desc,
  434. "is_addrs"=>$is_addrs,
  435. "is_custom"=>$is_custom,
  436. "metal_id"=>$metal_id,
  437. "config"=>$config,
  438. "other_config"=>$other_config,
  439. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  440. "gold_price"=>$gold_price===""? 0 : $gold_price,
  441. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  442. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  443. "budget_price"=>$budget_price,
  444. "num"=>$num,
  445. "pgNo"=>$pgNo,
  446. "use_desc"=>$use_desc,
  447. "remark"=>$remark,
  448. "status"=>1,
  449. "is_del"=>0,
  450. "addtime"=>date("Y-m-d H:i:s"),
  451. "updatetime"=>date("Y-m-d H:i:s"),
  452. 'bargain_status'=>1
  453. ];
  454. $up = Db::name("consult_info")->insert($info);
  455. if($up){
  456. if (!empty($bidlist)){
  457. foreach ($bidlist as $value){
  458. unset($value['id']);
  459. $value['infoNo']=$innew;
  460. $value['bidNo']=makeNo("BD");
  461. $value['spuCode']=makeNo("SKU");
  462. $value['status'] =0;
  463. $value['updatetime'] =date("Y-m-d H:i:s");
  464. $in = Db::name("consult_bids")->insert($value);
  465. if($in==false){
  466. Db::rollback();
  467. return error_show(1004,"反馈商品新建失败");
  468. }
  469. }
  470. }
  471. $zxinfo["bargain_status"] =1;
  472. $zxinfo["bargain_code"] =$innew;
  473. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  474. $bar=Db::name("consult_info")->save($zxinfo);
  475. if($bar==false){
  476. Db::rollback();
  477. return error_show(1004,"反馈商品更新失败");
  478. }
  479. //更新consule_order记录
  480. Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,'updatetime'=>date('Y-m-d H:i:s')]);
  481. Db::commit();
  482. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  483. }
  484. }catch (\Exception $e){
  485. Db::rollback();
  486. return error_show(1004,$e->getMessage());
  487. }
  488. }
  489. //** 发布竞标任务 */
  490. public function bargain(){
  491. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  492. if($infoNo==""){
  493. return error_show(1004,"参数infoNo不能为空");
  494. }
  495. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  496. if($zxinfo==false){
  497. return error_show(1004,"未找到信息数据");
  498. }
  499. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  500. if($status===""){
  501. return error_show(1004,"参数status不能为空");
  502. }
  503. if($status==1&&$zxinfo['status']>1){
  504. $zxinfo['bargain_num']=+1;
  505. }
  506. $zxinfo['status']=$status;
  507. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  508. $up = Db::name("consult_info")->save($zxinfo);
  509. if($up){
  510. return app_show(0,"状态更新成功");
  511. }else{
  512. return error_show(1003,"状态更新失败");
  513. }
  514. }
  515. public function feadback(){
  516. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  517. if($infoNo==""){
  518. return error_show(1002,"参数infoNo不能为空");
  519. }
  520. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  521. if($zxinfo==false){
  522. return error_show(1003,"未找到信息数据");
  523. }
  524. if($zxinfo['status']!=1){
  525. return error_show(1004,"任务未进行");
  526. }
  527. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  528. if($zx==false){
  529. return error_show(1003,"未找咨询信息数据");
  530. }
  531. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  532. if($pname==""){
  533. return error_show(1002,"参数pname不能为空");
  534. }
  535. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  536. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  537. if($cat_id==""){
  538. return error_show(1002,"参数cat_id不能为空");
  539. }
  540. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  541. if($specin==""){
  542. return error_show(1003,"参数specinfo不能为空");
  543. }
  544. $specinfo=[];
  545. foreach ($specin as $v){
  546. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  547. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  548. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  549. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  550. $specinfo[]=$v;
  551. }
  552. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  553. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  554. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  555. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  556. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  557. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  558. :"";
  559. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  560. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  561. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  562. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  563. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  564. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"";
  565. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"";
  566. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  567. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  568. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  569. $good_weight = isset($this->post['good_weight'])&&$this->post['good_weight']!==""? floatval($this->post['good_weight']):"";
  570. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"";
  571. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"";
  572. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"";
  573. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval
  574. ($this->post['pakge_fee']):"";
  575. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"";
  576. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"";
  577. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"";
  578. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"";
  579. if($nake_fee==="" ){
  580. return error_show(1004,"参数nake_fee不能为空");
  581. }
  582. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  583. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  584. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  585. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  586. if($token==''){
  587. return error_show(1002,"参数token不能为空");
  588. }
  589. $user =GetUserInfo($token);
  590. if(empty($user)||$user['code']!=0){
  591. return error_show(1005,"用户数据不存在");
  592. }
  593. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  594. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  595. $bidNo=makeNo("BD");
  596. $spucode=makeNo("SKU");
  597. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  598. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  599. //部分参数的大小校验
  600. $vali = Validate::rule([
  601. 'expire_day|有效时长'=>'require|elt:214748364',
  602. 'delivery_day|物流时长'=>'require|elt:214748364',
  603. 'work_day|生产工期'=>'require|elt:214748364',
  604. 'weight|总重量'=>'require|max:10',
  605. ]);
  606. $temp = [
  607. 'expire_day'=>$expire_day,
  608. 'delivery_day'=>$delivery_day,
  609. 'work_day'=>$work_day,
  610. 'weight'=>$weight,
  611. ];
  612. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  613. if($is_gold_price==1){
  614. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  615. ->find();
  616. $total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*
  617. $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  618. $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)*
  619. $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  620. }else{
  621. $saleprice = $open_fee/$zxinfo['num'] +
  622. $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee/(1-$budget);
  623. $total_fee = $open_fee/$zxinfo['num'] +
  624. $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  625. }
  626. $data=[
  627. "bidNo"=>$bidNo,
  628. "infoNo"=>$infoNo,
  629. "zxNo"=>$zxinfo['zxNo'],
  630. "spuCode"=>$spucode,
  631. "good_name"=>$pname,
  632. "brand_id"=>$brandid,
  633. "cat_id"=>$cat_id,
  634. "specinfo"=>json_encode($specinfo),
  635. "unit_id"=>$unit_id,
  636. "cost_desc"=>$cost_desc,
  637. "work_day"=>$work_day,
  638. "delivery_day"=>$delivery_day,
  639. "good_img"=>$good_img,
  640. "expire_day"=>$expire_day,
  641. "origin_place"=>$origin_place,
  642. "supplierNo"=>$supplierNo,
  643. "pay_way"=>$pay_way,
  644. "tax"=>$tax,
  645. "send_way"=>$send_way,
  646. "metal_id"=>$metal_id,
  647. "is_gold_price"=>$is_gold_price,
  648. "config"=>$config,
  649. "other_config"=>$other_config,
  650. "weight"=>$weight,
  651. "good_weight"=>$good_weight,
  652. "is_diff"=>$is_diff,
  653. "demo_fee"=>$demo_fee,
  654. "delivery_fee"=>$delivery_fee,
  655. "open_fee"=>$open_fee,
  656. "pakge_fee"=>$pakge_fee,
  657. "nake_fee"=>$nake_fee,
  658. "mark_fee"=>$mark_fee,
  659. "cert_fee"=>$cert_fee,
  660. "cost_fee"=>$cost_fee,
  661. "total_fee"=>$total_fee,
  662. "supply_area"=>$supply_area,
  663. "remark"=>$remark,
  664. "sale_price"=>$saleprice,
  665. "origin_price"=>$saleprice,
  666. "createrid"=>$createrid,
  667. "creater"=>$creater,
  668. "status"=>$zxinfo['status']==1 ?1 :2,
  669. "is_del"=>0,
  670. "addtime"=>date("Y-m-d H:i:s"),
  671. "updatetime"=>date("Y-m-d H:i:s")
  672. ];
  673. Db::startTrans();
  674. try{
  675. $insert= Db::name("consult_bids")->insert($data);
  676. if($insert){
  677. // $data=[
  678. // "spuCode"=>$spucode,
  679. // "good_name"=>$pname,
  680. // "brand_id"=>$brandid,
  681. // "good_unit"=>$unit_id,
  682. // "good_type"=>0,
  683. // "moq"=>1,
  684. // "customized"=>$work_day,
  685. // "tax"=>$tax,
  686. // "supplierNo"=>$supplierNo,
  687. // "is_auth"=>0,
  688. // "craft_desc"=>$cost_desc,
  689. // "good_remark"=>$remark,
  690. // "good_img"=>$good_img,
  691. // "good_thumb_img"=>"",
  692. // "good_info_img"=>"",
  693. // "status"=>1,
  694. // "is_del"=>0,
  695. // "createrid"=>$createrid,
  696. // "creater"=>$creater,
  697. // "addtime"=>date("Y-m-d H:i:s"),
  698. // "updatetime"=>date("Y-m-d H:i:s")
  699. // ];
  700. // $good = Db::name("good_zixun")->insert($data);
  701. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  702. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  703. if($projectinfo==false){
  704. Db::rollback();
  705. return error_show(1006,"未找到项目信息");
  706. }
  707. $temp=[];
  708. $temp['spuCode']=$spucode;
  709. $temp['skuCode']="";
  710. $temp['pgNo']=$zxinfo['pgNo'];
  711. $temp['projectNo']=$zx['projectNo'];
  712. $temp['good_name']=$pname;
  713. $temp['good_type']=$projectinfo['good_type'];
  714. $temp['data_source']=2;
  715. $temp['cat_id']=$cat_id;
  716. $temp['budget_price']=$projectinfo['budget_price'];
  717. $temp['sale_price']=$saleprice;
  718. $temp['origin_price']=$total_fee;
  719. $temp['num']=$zxinfo['num'];
  720. $temp['status']=0;
  721. $temp['is_del']=0;
  722. $temp['creater']=$creater;
  723. $temp['createrid']=$createrid;
  724. $temp['addtime']=date("Y-m-d H:i:s");
  725. $temp['updatetime']=date("Y-m-d H:i:s");
  726. $nu = Db::name("project_feedback")->insert($temp);
  727. if($nu==false){
  728. Db::rollback();
  729. return error_show(1006,"项目反馈失败");
  730. }else{
  731. $projectinfo['status']=2;
  732. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  733. $up = Db::name("project_info")->save($projectinfo);
  734. if($up){
  735. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  736. ->count();
  737. if($count==0){
  738. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  739. if($projetc!=false){
  740. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  741. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  742. if($proc==false){
  743. Db::rollback();
  744. return error_show(1006,"项目反馈失败");
  745. }
  746. }
  747. }
  748. }
  749. }
  750. }
  751. Db::commit();
  752. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  753. }else{
  754. Db::rollback();
  755. return error_show(1006,"反馈失败");
  756. }
  757. }catch (\Exception $e){
  758. Db::rollback();
  759. return error_show(1006,$e->getMessage());
  760. }
  761. }
  762. public function feadinfo(){
  763. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  764. if($bidNo==""){
  765. return error_show(1004,"参数bidNo不能为空");
  766. }
  767. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  768. if($info==false){
  769. return error_show(1004,"未找到商品数据");
  770. }
  771. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  772. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  773. $info['cat_info'] = made($info['cat_id'],[]);
  774. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  775. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  776. if($info['brand_id']!=0){
  777. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  778. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  779. }else{
  780. $info["brand_name"]="";
  781. $info["brand_id"]="";
  782. }
  783. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  784. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  785. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  786. $god=[
  787. "metal_id"=>$info['metal_id'],
  788. "weight"=>$info["weight"],
  789. "demo_fee"=>$info["demo_fee"],
  790. "delivery_fee"=>$info["delivery_fee"],
  791. "open_fee"=>$info["open_fee"],
  792. "packing_fee"=>$info["pakge_fee"],
  793. "mark_fee"=>$info["mark_fee"],
  794. "nake_fee"=>$info["nake_fee"],
  795. "cert_fee"=>$info["cert_fee"],
  796. "cost_fee"=>$info["cost_fee"],
  797. "num"=>$bidinfo["num"],
  798. ];
  799. if($info['is_gold_price']==1){
  800. $price = GoldPrice($god, $budget/100);
  801. $info['sale_price'] =round($price,2);
  802. }
  803. $info['specinfo'] = json_decode($info['specinfo'],true);
  804. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  805. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  806. $info['bargain'] =$bargain;
  807. return app_show(0,"获取成功",$info);
  808. }
  809. public function feededit(){
  810. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  811. if($bidNo==""){
  812. return error_show(1002,"参数bidNo不能为空");
  813. }
  814. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  815. if($bidinfo==false){
  816. return error_show(1003,"未找到信息数据");
  817. }
  818. if($bidinfo['status']>=5){
  819. return error_show(1004,"咨询单已确认无法修改");
  820. }
  821. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  822. if($zxinfo==false){
  823. return error_show(1003,"未找到信息数据");
  824. }
  825. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  826. if($zx==false){
  827. return error_show(1003,"未找咨询信息数据");
  828. }
  829. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  830. if($pname==""){
  831. return error_show(1002,"参数pname不能为空");
  832. }
  833. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  834. // if($brandid==""){
  835. // return error_show(1002,"参数brandid不能为空");
  836. // }
  837. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  838. if($cat_id==""){
  839. return error_show(1002,"参数cat_id不能为空");
  840. }
  841. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  842. if($specin==""){
  843. return error_show(1003,"参数specinfo不能为空");
  844. }
  845. $specinfo=[];
  846. foreach ($specin as $v){
  847. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  848. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  849. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  850. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  851. $specinfo[]=$v;
  852. }
  853. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  854. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  855. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  856. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  857. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  858. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  859. :"";
  860. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  861. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  862. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  863. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  864. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  865. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"";
  866. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"";
  867. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  868. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  869. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"";
  870. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"";
  871. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"";
  872. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"";
  873. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"";
  874. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"";
  875. if($nake_fee==="" ||$nake_fee==0 ){
  876. return error_show(1004,"参数nake_fee不能为空或零");
  877. }
  878. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"";
  879. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"";
  880. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"";
  881. $total_fee = isset($this->post['total_fee'])&&$this->post['total_fee']!=""? floatval($this->post['total_fee']):"";
  882. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  883. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  884. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  885. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  886. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  887. if($is_gold_price==1){
  888. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  889. ->find();
  890. $total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*
  891. $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  892. $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)*
  893. $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  894. }else{
  895. $saleprice = $open_fee/$zxinfo['num'] +
  896. $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee/(1-$budget);
  897. $total_fee = $open_fee/$zxinfo['num'] +
  898. $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  899. }
  900. Db::startTrans();
  901. try{
  902. $data=[
  903. "good_name"=>$pname,
  904. "brand_id"=>$brandid,
  905. "cat_id"=>$cat_id,
  906. "specinfo"=>json_encode($specinfo),
  907. // "material"=>$material,
  908. "unit_id"=>$unit_id,
  909. "cost_desc"=>$cost_desc,
  910. "work_day"=>$work_day,
  911. "delivery_day"=>$delivery_day,
  912. "good_img"=>$good_img,
  913. "expire_day"=>$expire_day,
  914. "origin_place"=>$origin_place,
  915. "supplierNo"=>$supplierNo,
  916. "pay_way"=>$pay_way,
  917. "tax"=>$tax,
  918. "send_way"=>$send_way,
  919. "metal_id"=>$metal_id,
  920. "is_gold_price"=>$is_gold_price,
  921. "config"=>$config,
  922. "other_config"=>$other_config,
  923. "weight"=>$weight,
  924. "is_diff"=>$is_diff,
  925. "demo_fee"=>$demo_fee,
  926. "delivery_fee"=>$delivery_fee,
  927. "open_fee"=>$open_fee,
  928. "pakge_fee"=>$pakge_fee,
  929. "nake_fee"=>$nake_fee,
  930. "mark_fee"=>$mark_fee,
  931. "cert_fee"=>$cert_fee,
  932. "cost_fee"=>$cost_fee,
  933. "total_fee"=>$total_fee,
  934. "sale_price"=>$saleprice,
  935. "supply_area"=>$supply_area,
  936. "remark"=>$remark,
  937. "updatetime"=>date("Y-m-d H:i:s")
  938. ];
  939. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  940. if($insert){
  941. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  942. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  943. if($projectinfo==false){
  944. Db::rollback();
  945. return error_show(1006,"未找到项目信息");
  946. }
  947. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  948. if($feed==false){
  949. Db::rollback();
  950. return error_show(1006,"未找到项目反馈信息");
  951. }
  952. $feed['good_name']=$pname;
  953. $feed['good_type']=$projectinfo['good_type'];
  954. $feed['cat_id']=$cat_id;
  955. $feed['sale_price']=$saleprice;
  956. $feed['origin_price']=$total_fee;
  957. $temp['updatetime']=date("Y-m-d H:i:s");
  958. $nu = Db::name("project_feedback")->save($feed);
  959. if($nu==false){
  960. Db::rollback();
  961. return error_show(1006,"项目反馈失败");
  962. }else{
  963. $projectinfo['status']=2;
  964. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  965. $up = Db::name("project_info")->save($projectinfo);
  966. if($up){
  967. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  968. ->count();
  969. if($count==0){
  970. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  971. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  972. if($proc==false){
  973. Db::rollback();
  974. return error_show(1006,"项目反馈失败");
  975. }
  976. }
  977. }
  978. }
  979. }
  980. Db::commit();
  981. return app_show(0,"编辑成功");
  982. }else{
  983. Db::rollback();
  984. return error_show(1004,"编辑失败");
  985. }
  986. }catch (\Exception $e){
  987. Db::rollback();
  988. return error_show(1004,$e->getMessage());
  989. }
  990. }
  991. public function bargain_add(){
  992. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  993. if($bidNo===""){
  994. return error_show(1004,"参数bidNo不能为空");
  995. }
  996. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  997. if($info==false){
  998. return error_show(1004,"未找到商品数据");
  999. }
  1000. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1001. if($bargain_price===""){
  1002. return error_show(1004,"参数bargain_price不能为空");
  1003. }
  1004. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1005. // if($bargain_reason===""){
  1006. // return error_show(1004,"参数bargain_reason不能为空");
  1007. // }
  1008. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1009. if($infos==false){
  1010. return error_show(1004,"未找到商品数据");
  1011. }
  1012. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1013. return error_show(1004,"咨询单招标未结束或已确认商品");
  1014. }
  1015. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1016. if($token==''){
  1017. return error_show(105,"参数token不能为空");
  1018. }
  1019. $user =GetUserInfo($token);
  1020. if(empty($user)||$user['code']!=0){
  1021. return error_show(1002,"用户数据不存在");
  1022. }
  1023. //新增两个字段
  1024. //议价备注
  1025. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1026. //议价原因id
  1027. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1028. if ($result_info_id != '') {
  1029. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1030. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1031. }
  1032. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1033. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1034. $bargainNo =makeNo("BA");
  1035. Db::startTrans();//::todo 金价 毛利计算
  1036. try{
  1037. $data=[
  1038. "bidsNo"=>$bidNo,
  1039. "infoNo"=>$info['infoNo'],
  1040. "zxNo"=>$info['zxNo'],
  1041. "bargainNo"=>$bargainNo,
  1042. "bargain_type"=>1,
  1043. "bargain_reason"=>$bargain_reason,
  1044. "sale_price"=>$info['sale_price'],
  1045. "cost_before_price"=>$info['cost_fee'],
  1046. "cost_after_price"=>$info['cost_fee'],
  1047. "before_rate"=>$info['cost_fee'],
  1048. "after_rate"=>$info['cost_fee'],
  1049. "after_price"=>$bargain_price,
  1050. "exam_info"=>"",
  1051. "status"=>1,
  1052. "is_del"=>0,
  1053. "creater"=>$creater,
  1054. "createrid"=>$createrid,
  1055. "addtime"=>date("Y-m-d H:i:s"),
  1056. "updatetime"=>date("Y-m-d H:i:s"),
  1057. 'bargain_remark'=>$bargain_remark,
  1058. 'result_info_id'=>$result_info_id,
  1059. ];
  1060. $int = Db::name("bargain_order")->insert($data);
  1061. if($int){
  1062. $info['status']=3;
  1063. $info['updatetime']=date("Y-m-d H:i:s");
  1064. $up =Db::name("consult_bids")->save($info);
  1065. if($up){
  1066. $infos['status']=3;
  1067. $infos['updatetime']=date("Y-m-d H:i:s");
  1068. $ups =Db::name("consult_info")->save($infos);
  1069. if($ups){
  1070. Db::commit();
  1071. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1072. }
  1073. }
  1074. }
  1075. Db::rollback();
  1076. return error_show(1004,"议价单新建失败");
  1077. }catch (\Exception $e){
  1078. Db::rollback();
  1079. return error_show(1004,$e->getMessage());
  1080. }
  1081. }
  1082. public function bids_check(){
  1083. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1084. if($bidNo===""){
  1085. return error_show(1004,"参数bidNo不能为空");
  1086. }
  1087. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1088. if($info==false){
  1089. return error_show(1004,"未找到商品数据");
  1090. }
  1091. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1092. if($infos==false){
  1093. return error_show(1004,"未找到商品数据");
  1094. }
  1095. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1096. return error_show(1004,"咨询单招标未结束或已确认商品");
  1097. }
  1098. Db::startTrans();
  1099. try {
  1100. $info['status']=6;
  1101. $info['updatetime']=date("Y-m-d H:i:s");
  1102. $bids = Db::name("consult_bids")->save($info);
  1103. if($bids){
  1104. $infos['status']=4;
  1105. $infos['updatetime']=date("Y-m-d H:i:s");
  1106. $se = Db::name("consult_info")->save($infos);
  1107. if($se){
  1108. Db::commit();
  1109. return app_show(0,"商品确定成功");
  1110. }
  1111. }
  1112. Db::rollback();
  1113. return error_show(1004,"商品确认失败");
  1114. }catch (\Exception $e){
  1115. Db::rollback();
  1116. return error_show(1004,$e->getMessage());
  1117. }
  1118. }
  1119. public function bargain_status(){
  1120. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1121. if($bargainNo===""){
  1122. return error_show(1004,"参数bargainNo不能为空");
  1123. }
  1124. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1125. if($info==false){
  1126. return error_show(1004,"未找到议价数据");
  1127. }
  1128. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1129. if($bids==false){
  1130. return error_show(1004,"未找到商品数据");
  1131. }
  1132. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1133. if($coninfo==false){
  1134. return error_show(1004,"未找到咨询单数据");
  1135. }
  1136. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1137. if($status==''){
  1138. return error_show(1005,"参数status不能为空");
  1139. }
  1140. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1141. // if($remark==""){
  1142. // return error_show(1004,"参数remark不能为空");
  1143. // }
  1144. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1145. if($token==''){
  1146. return error_show(105,"参数token不能为空");
  1147. }
  1148. $user =GetUserInfo($token);
  1149. if(empty($user)||$user['code']!=0){
  1150. return error_show(1002,"用户数据不存在");
  1151. }
  1152. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1153. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1154. Db::startTrans();
  1155. try{
  1156. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1157. $examinfo[]=["status"=>$status,"remark"=>$remark,"createrid"=>$createrid,"creater"=>$creater];
  1158. $info['status'] =$status;
  1159. $info['remark'] =$remark;
  1160. $info['exam_info']=json_encode($examinfo) ;
  1161. $info['updatetime'] =date("Y-m-d H:i:s");
  1162. $up =Db::name("bargain_order")->save($info);
  1163. if($up){
  1164. if($status==4||$status==5||$status==6||$status==7){
  1165. $bids['status']=5;
  1166. if($status==4){
  1167. $bids['sale_price']=$info['after_price'];
  1168. }
  1169. $bids['updatetime']=date("Y-m-d H:i:s");
  1170. $up =Db::name("consult_bids")->save($bids);
  1171. if($up==false){
  1172. Db::rollback();
  1173. return error_show(1004,"数据更新失败");
  1174. }
  1175. }
  1176. Db::commit();
  1177. return app_show(0,"更新成功");
  1178. }
  1179. }catch (\Exception $e){
  1180. Db::rollback();
  1181. return error_show(1004,$e->getMessage());
  1182. }
  1183. }
  1184. public function bargain_info(){
  1185. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1186. if($bargainNo===""){
  1187. return error_show(1004,"参数bargainNo不能为空");
  1188. }
  1189. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1190. if($info==false){
  1191. return error_show(1004,"未找到议价数据");
  1192. }
  1193. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1194. if($bidinfos==false){
  1195. return error_show(1004,"未找到商品数据");
  1196. }
  1197. $consultinfos = Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])
  1198. ->find();
  1199. if($consultinfos==false){
  1200. return error_show(1004,"未找到咨询商品数据");
  1201. }
  1202. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1203. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1204. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1205. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1206. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1207. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_encode($info['exam_info']):"";
  1208. if($bidinfos['brand_id']!=0){
  1209. $info['brand_id'] = $bidinfos['brand_id'];
  1210. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1211. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1212. }else{
  1213. $info["brand_name"]="";
  1214. $info["brand_id"]="";
  1215. }
  1216. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1217. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1218. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1219. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1220. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1221. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1222. $info['budget'] =$budget;
  1223. $god=[
  1224. "metal_id"=>$bidinfos['metal_id'],
  1225. "weight"=>$bidinfos["weight"],
  1226. "demo_fee"=>$bidinfos["demo_fee"],
  1227. "delivery_fee"=>$bidinfos["delivery_fee"],
  1228. "open_fee"=>$bidinfos["open_fee"],
  1229. "packing_fee"=>$bidinfos["pakge_fee"],
  1230. "mark_fee"=>$bidinfos["mark_fee"],
  1231. "nake_fee"=>$bidinfos["nake_fee"],
  1232. "cert_fee"=>$bidinfos["cert_fee"],
  1233. "cost_fee"=>$bidinfos["cost_fee"],
  1234. "num"=>$bidinfoe["num"],
  1235. ];
  1236. $info['gold_price']=0;
  1237. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1238. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1239. ->find();
  1240. $info['gold_price'] =$gold['price'];
  1241. }
  1242. $info['cost_desc'] =$bidinfos['cost_desc'];
  1243. $info['work_day'] =$bidinfos['work_day'];
  1244. $info['delivery_day'] =$bidinfos['delivery_day'];
  1245. $info['expire_day'] =$bidinfos['expire_day'];
  1246. $info['origin_place'] =$bidinfos['origin_place'];
  1247. $info['origin_addr'] ="";
  1248. if($bidinfos['origin_place']!=''){
  1249. $code = explode(",",$bidinfos['origin_place']);
  1250. $temp=[];
  1251. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1252. $temp['city_code']=isset($code[1])?$code[1]:"";
  1253. $temp['area_code']=isset($code[2])?$code[2]:"";
  1254. $addr= GetAddr(json_encode($temp));
  1255. $info['origin_addr'] = $addr;
  1256. }
  1257. $info['supplierNo'] =$bidinfos['supplierNo'];
  1258. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1259. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1260. $info['pay_way'] =$bidinfos['pay_way'];
  1261. $info['tax'] =$bidinfos['tax'];
  1262. $info['send_way'] =$bidinfos['send_way'];
  1263. $info['metal_id'] =$bidinfos['metal_id'];
  1264. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1265. $info['config'] =$bidinfos['config'];
  1266. $info['other_config'] =$bidinfos['other_config'];
  1267. $info['weight'] =$bidinfos['weight'];
  1268. $info['is_diff'] =$bidinfos['is_diff'];
  1269. $info['demo_fee'] =$bidinfos['demo_fee'];
  1270. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1271. $info['open_fee'] =$bidinfos['open_fee'];
  1272. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1273. $info['nake_fee'] =$bidinfos['nake_fee'];
  1274. $info['mark_fee'] =$bidinfos['mark_fee'];
  1275. $info['cert_fee'] =$bidinfos['cert_fee'];
  1276. $info['cost_fee'] =$bidinfos['cost_fee'];
  1277. $info['total_fee'] =$bidinfos['total_fee'];
  1278. $info['supply_area'] =$bidinfos['supply_area'];
  1279. $info['remark'] =$bidinfos['remark'];
  1280. $info['is_addrs'] =$consultinfos['is_addrs'];
  1281. $info['is_custom'] =$consultinfos['is_custom'];
  1282. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1283. $info['sale_price'] =round($bidinfos['sale_price'],2);
  1284. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1285. //获取议价原因
  1286. if ($info['result_info_id'] != 0) {
  1287. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1288. } else {
  1289. $info['result_info'] = '';
  1290. }
  1291. return app_show(0,"获取成功",$info);
  1292. }
  1293. public function bidlist(){
  1294. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1295. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1296. $where=[['is_del',"=",0]];
  1297. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1298. if ($zxNo !== "") {
  1299. $where[] = ['zxNo','=',$zxNo];
  1300. }
  1301. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1302. if ($infoNo !== "") {
  1303. $where[] = ['infoNo','=',$infoNo];
  1304. }
  1305. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1306. if ($bidNo !== "") {
  1307. $where[] = ['bidNo','=',$bidNo];
  1308. }
  1309. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1310. if ($pgNo !== "") {
  1311. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1312. $where[] = ['infoNo','in',$bidinfo];
  1313. }
  1314. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1315. if ($bargain_status !== "") {
  1316. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1317. $where[] = ['infoNo','in',$bidinfo];
  1318. }
  1319. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1320. if ($projectNo !== "") {
  1321. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1322. ("zxNo");
  1323. $where[] = ['zxNo','in',$zxlist];
  1324. }
  1325. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1326. if($token==""){
  1327. return error_show(101,'token不能为空');
  1328. }
  1329. $apply_id =GetUserInfo($token);
  1330. if(empty($apply_id)||$apply_id['code']!=0){
  1331. return error_show(1002,"申请人数据不存在");
  1332. }
  1333. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1334. $where[]=['createrid',"=",$rm];
  1335. $count = Db::name('consult_bids')->where($where)->count();
  1336. $total = ceil($count / $size);
  1337. $page = $page >= $total ? $total : $page;
  1338. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select();
  1339. $data=[];
  1340. foreach ($list as $value){
  1341. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1342. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1343. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1344. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1345. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1346. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1347. if($value['brand_id']!=0){
  1348. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1349. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1350. }else{
  1351. $value["brand_name"]="";
  1352. $value["brand_id"]="";
  1353. }
  1354. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1355. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1356. $god=[
  1357. "metal_id"=>$value['metal_id'],
  1358. "weight"=>$value["weight"],
  1359. "demo_fee"=>$value["demo_fee"],
  1360. "delivery_fee"=>$value["delivery_fee"],
  1361. "open_fee"=>$value["open_fee"],
  1362. "packing_fee"=>$value["pakge_fee"],
  1363. "mark_fee"=>$value["mark_fee"],
  1364. "nake_fee"=>$value["nake_fee"],
  1365. "cert_fee"=>$value["cert_fee"],
  1366. "cost_fee"=>$value["cost_fee"],
  1367. "num"=>$bidinfo["num"],
  1368. ];
  1369. if($value['is_gold_price']==1){
  1370. $price = GoldPrice($god, $budget/100);
  1371. $value['sale_price'] = round($price,2);
  1372. }
  1373. $value['specinfo'] = json_decode($value['specinfo'],true);
  1374. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1375. $value['bargain_status']=$bidinfo['bargain_status'];
  1376. $data[]=$value;
  1377. }
  1378. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1379. }
  1380. public function feedlist(){
  1381. $where=[['is_del',"=",0]];
  1382. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1383. if ($zxNo !== "") {
  1384. $where[] = ['zxNo','=',$zxNo];
  1385. }
  1386. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1387. if ($infoNo !== "") {
  1388. $where[] = ['infoNo','=',$infoNo];
  1389. }
  1390. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1391. if ($bidNo !== "") {
  1392. $where[] = ['bidNo','=',$bidNo];
  1393. }
  1394. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1395. if ($projectNo !== "") {
  1396. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1397. ("zxNo");
  1398. $where[] = ['zxNo','in',$zxlist];
  1399. }
  1400. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1401. if($token==''){
  1402. return error_show(102,"参数token不能为空");
  1403. }
  1404. // $user =GetUserInfo($token);
  1405. // if(empty($user)||$user['code']!=0){
  1406. // return error_show(105,"用户数据不存在");
  1407. // }
  1408. // $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1409. // $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1410. // $where[] = ["createrid","=",$createrid];
  1411. $list =Db::name('consult_bids')->where($where)->select();
  1412. $data=[];
  1413. foreach ($list as $value){
  1414. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1415. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1416. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1417. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1418. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1419. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1420. if($value['brand_id']!=0){
  1421. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1422. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1423. }else{
  1424. $value["brand_name"]="";
  1425. $value["brand_id"]="";
  1426. }
  1427. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1428. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1429. $god=[
  1430. "metal_id"=>$value['metal_id'],
  1431. "weight"=>$value["weight"],
  1432. "demo_fee"=>$value["demo_fee"],
  1433. "delivery_fee"=>$value["delivery_fee"],
  1434. "open_fee"=>$value["open_fee"],
  1435. "packing_fee"=>$value["pakge_fee"],
  1436. "mark_fee"=>$value["mark_fee"],
  1437. "nake_fee"=>$value["nake_fee"],
  1438. "cert_fee"=>$value["cert_fee"],
  1439. "cost_fee"=>$value["cost_fee"],
  1440. "num"=>$bidinfo["num"],
  1441. ];
  1442. if($value['is_gold_price']==1){
  1443. $price = GoldPrice($god, $budget/100);
  1444. $value['sale_price'] =round($price,2);
  1445. }
  1446. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1447. $value['specinfo'] = json_decode($value['specinfo'],true);
  1448. $value['bargain_status']=$bidinfo['bargain_status'];
  1449. $data[]=$value;
  1450. }
  1451. return app_show(0,"获取成功",$data);
  1452. }
  1453. public function bragain_list(){
  1454. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1455. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1456. $where=[['is_del',"=",0]];
  1457. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1458. if($bidsNo!=""){
  1459. $where[]=["bidsNo","=",$bidsNo];
  1460. }
  1461. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1462. if ($zxNo !== "") {
  1463. $where[] = ['zxNo','=',$zxNo];
  1464. }
  1465. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1466. if ($infoNo !== "") {
  1467. $where[] = ['infoNo','=',$infoNo];
  1468. }
  1469. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1470. if ($projectNo !== "") {
  1471. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1472. ("zxNo");
  1473. $where[] = ['zxNo','in',$zxlist];
  1474. }
  1475. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1476. if ($pgNo !== "") {
  1477. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1478. $where[] = ['infoNo','in',$bidinfo];
  1479. }
  1480. $count=Db::name("bargain_order")->where($where)->count();
  1481. $total = ceil($count / $size);
  1482. $page = $page >= $total ? $total : $page;
  1483. $list =Db::name('bargain_order')->where($where)->page($page,$size)->order('addtime','desc')->select();
  1484. $data=[];
  1485. foreach ($list as $value){
  1486. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1487. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1488. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1489. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1490. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1491. if($bidinfos['brand_id']!=0){
  1492. $value['brand_id'] = $bidinfos['brand_id'];
  1493. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1494. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1495. }else{
  1496. $value["brand_name"]="";
  1497. $value["brand_id"]="";
  1498. }
  1499. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1500. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1501. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1502. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1503. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1504. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1505. $value['budget'] =$budget;
  1506. $god=[
  1507. "metal_id"=>$bidinfos['metal_id'],
  1508. "weight"=>$bidinfos["weight"],
  1509. "demo_fee"=>$bidinfos["demo_fee"],
  1510. "delivery_fee"=>$bidinfos["delivery_fee"],
  1511. "open_fee"=>$bidinfos["open_fee"],
  1512. "packing_fee"=>$bidinfos["pakge_fee"],
  1513. "mark_fee"=>$bidinfos["mark_fee"],
  1514. "nake_fee"=>$bidinfos["nake_fee"],
  1515. "cert_fee"=>$bidinfos["cert_fee"],
  1516. "cost_fee"=>$bidinfos["cost_fee"],
  1517. "num"=>$bidinfoe["num"],
  1518. ];
  1519. // if($bidinfos['is_gold_price']==1){
  1520. // $price = GoldPrice($god, $budget/100);
  1521. // }else{
  1522. // $price = GoodPrice($god, $budget/100);
  1523. // }
  1524. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1525. $value['sale_price'] =round($bidinfos['sale_price'],2);
  1526. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1527. $data[]=$value;
  1528. }
  1529. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  1530. }
  1531. public function crontablist(){
  1532. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1533. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1534. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  1535. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1536. if ($zxNo !== "") {
  1537. $where[] = ['a.zxNo','=',$zxNo];
  1538. }
  1539. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  1540. if ($salesman !== "") {
  1541. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  1542. $where[]= ["b.salesman",'like',"%$salesman%"];
  1543. }
  1544. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  1545. if ($cpName !== "") {
  1546. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  1547. $where[]= ["a.good_Name",'like',"%$cpName%"];
  1548. }
  1549. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  1550. if ($khNo !== "") {
  1551. // $where['khNo'] = $khNo;
  1552. $where[]= ["b.khNo",'like',"%$khNo%"];
  1553. }
  1554. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  1555. if ($start !="") {
  1556. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  1557. $where[]= ["a.addtime",'>=',$start];
  1558. }
  1559. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  1560. if($end !=""){
  1561. $where[]= ["a.addtime",'<=',$end];
  1562. }
  1563. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  1564. if ($status !== "") {
  1565. $where[]= ["a.status",'=',$status];
  1566. }
  1567. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  1568. ->count();
  1569. $total = ceil($count / $size);
  1570. $page = $page >= $total ? $total : $page;
  1571. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  1572. ->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();
  1573. $data=[];
  1574. foreach ($list as $value){
  1575. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1576. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  1577. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  1578. $value['khname']="";
  1579. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  1580. true):[];
  1581. if($value['khNo']!==""){
  1582. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  1583. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  1584. }
  1585. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1586. $data[]=$value;
  1587. }
  1588. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1589. }
  1590. }