Consult.php 82 KB

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