dealer_tender_list.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <?php
  2. include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
  3. include $_SERVER['DOCUMENT_ROOT'].'/common/dealer_chk.php';
  4. $s_cd_dealer = $_SESSION['s_cd_dealer'];
  5. $s_cd_dealer_p = $_SESSION['s_cd_dealer_p'];
  6. $s_ds_type = $_SESSION['s_ds_type'];
  7. $s_ds_usertype = $_SESSION['s_ds_usertype'];
  8. $s_ds_company_bp1 = $_SESSION['s_ds_company_bp1'];
  9. $s_ds_branch1 = $_SESSION['s_ds_branch1'];
  10. $s_ds_company_bp2 = $_SESSION['s_ds_company_bp2'];
  11. $s_ds_branch2 = $_SESSION['s_ds_branch2'];
  12. $s_ds_company_bp3 = $_SESSION['s_ds_company_bp3'];
  13. $s_ds_branch3 = $_SESSION['s_ds_branch3'];
  14. $PageNo = $_REQUEST['pageno'];
  15. $PageSize = $_REQUEST['PageSize'];
  16. if (empty($PageNo)) {$PageNo=1;}else{$PageNo=$PageNo;}
  17. if (empty($PageSize)) {
  18. $PageSize=8; //목록개수설정
  19. }else{$PageSize=$PageSize;}
  20. $pagestartpoint=($PageNo-1)*$PageSize;
  21. $sql_from = "";
  22. $sql = "where s.ds_delind='N'";
  23. $orderby = "order by s.dt_insert desc";
  24. $searchtype = $_REQUEST['searchtype'];
  25. $searchword = $_REQUEST['searchword'];
  26. $ds_usertype = $_REQUEST['ds_usertype'];
  27. $ds_status = $_REQUEST['ds_status'];
  28. $ds_type = "A0"; //A0 : 매입
  29. $sql = $sql. " and s.ds_type = '$ds_type' ";
  30. if($ds_status == "E0"){ //입찰하지 않은 판매건
  31. $sql = $sql. " and s.dt_approve >= DATE_ADD(now(), INTERVAL '-".LIMIT_TIME_TENDER."' HOUR) ";
  32. if($s_ds_usertype == "B0"){ //kcar 딜러
  33. /*
  34. 20210130 kcar직원 전부 전 지점에 입찰 가능하게 처리부탁드립니다.
  35. $sql = $sql. " and (
  36. (
  37. s.ds_company_bp = '$s_ds_company_bp1' and ds_branch = '$s_ds_branch1'
  38. )
  39. or (
  40. s.ds_company_bp = '$s_ds_company_bp2' and ds_branch = '$s_ds_branch2'
  41. )
  42. or (
  43. s.ds_company_bp = '$s_ds_company_bp3' and ds_branch = '$s_ds_branch3'
  44. )
  45. ) ";
  46. */
  47. $sql = $sql. " and ds_branch > ''
  48. and s.ds_company_bp in ('$s_ds_company_bp1', '$s_ds_company_bp2', '$s_ds_company_bp3' )
  49. ";
  50. }else{
  51. $sql = $sql. " and s.ds_area in (
  52. select
  53. SUBSTRING_INDEX (SUBSTRING_INDEX(nm_area,',',numbers.n),',',-1)
  54. from
  55. (select 1 n union all select 2
  56. union all select 3 union all select 4
  57. union all select 5 union all select 6
  58. union all select 7 union all select 8
  59. union all select 9 union all select 10
  60. union all select 11 union all select 12
  61. union all select 13 union all select 14
  62. union all select 15 union all select 16
  63. union all select 17 union all select 18
  64. union all select 19 union all select 20
  65. ) numbers INNER JOIN dealer_master
  66. on CHAR_LENGTH ( nm_area ) - CHAR_LENGTH ( REPLACE ( nm_area , ',' , '' ))>= numbers . n-1
  67. where cd_dealer = $s_cd_dealer_p
  68. ) ";
  69. }
  70. }
  71. if($s_ds_type == "D0"){ //딜러
  72. $sql_ds_type = " and cd_dealer_p = '$s_cd_dealer' ";
  73. }else{ //딜러-관리자
  74. $sql_ds_type = " and cd_dealer = '$s_cd_dealer' ";
  75. }
  76. if($searchword != ""){
  77. if($searchtype=="" || $searchtype==null){
  78. $sql = $sql. " and (s.nm_name like '$searchword%' or a.nm_number like '$searchword%') ";
  79. }else{
  80. $sql = $sql. " and $searchtype like '$searchword%'";
  81. }
  82. }
  83. if($ds_usertype != ""){
  84. $sql = $sql. " and s.ds_usertype = '$ds_usertype'";
  85. }
  86. if($ds_status == "E0"){ //딜러 업체 소속 입찰 건이 2건 보다 작을 시만 입찰 요청 건에 보이게 한다. //입찰하지 않은 판매건
  87. $sql = $sql. " and s.ds_status in ('E0','F0')";
  88. //딜러 업체 소속 입찰 건이 2건 보다 작을 시만 입찰 요청 건에 보이게 한다.
  89. $sql_from = $sql_from. " left outer join ( ";
  90. $sql_from = $sql_from. " select cd_sale from tender_master where ds_delind = 'N' and cd_dealer_p = '$s_cd_dealer_p' group by cd_sale having count(*) > 1) f ";
  91. $sql_from = $sql_from. " on (s.cd_sale = f.cd_sale) ";
  92. $sql = $sql. " and f.cd_sale is null "; //딜러 업체 소속 입찰 건이 2건 보다 작을 시만 입찰 요청 건에 보이게 한다.
  93. if($s_ds_type == "D1"){ //딜러-관리자
  94. //본인 입찰 건 제외한 입찰 건
  95. $sql_from = $sql_from. " left outer join ( ";
  96. $sql_from = $sql_from. " select cd_sale from tender_master where ds_delind = 'N' and cd_dealer = '$s_cd_dealer' group by cd_sale) g ";
  97. $sql_from = $sql_from. " on (s.cd_sale = g.cd_sale) ";
  98. $sql = $sql. " and g.cd_sale is null "; //본인 입찰 건 제외한 입찰 건
  99. }
  100. }else{
  101. if($ds_status == "F0"){ //입찰 중인 판매건
  102. $sql = $sql. " and s.ds_status in ('E0','F0')";
  103. // $sql = $sql. " and s.cd_sale in (select cd_sale from tender_master where ds_delind = 'N' ".$sql_ds_type." group by cd_sale)"; //20191001이전 지연 쿼리
  104. $sql = $sql. " and exists(select cd_sale from tender_master where cd_sale = s.cd_sale and ds_delind = 'N' ".$sql_ds_type." )"; //20191001 cd_sale_cd_user_cd_dealer index 설정 후 쿼리 변경
  105. $sql = $sql. " and getRemainTimeByPhase('".LIMIT_TIME_TENDER."', '".LIMIT_TIME_SELL."', s.dt_approve, now()) != '0분' ";//20200707 입찰마감 시간 지난 건 안보이게 처리
  106. }else if($ds_status == "Z0"){ //낙찰된 판매건
  107. //검차 결과가 없거나 거래완료인 매물만 나오게 수정 2021-07-15
  108. // $sql = $sql. " and s.ds_status in ('Z0')";
  109. $sql = $sql. " and s.ds_status in ('Z0') and (s.ds_status_contract = '' or s.ds_status_contract = 'Z0')";
  110. $sql_from = $sql_from. " inner join ( ";
  111. $sql_from = $sql_from. " select cd_sale from tender_master where ds_delind = 'N' and ds_status in ('Z0') ".$sql_ds_type." group by cd_sale) h ";
  112. $sql_from = $sql_from. " on (s.cd_sale = h.cd_sale) ";
  113. // $sql = $sql. " and h.cd_sale is not null ";
  114. }else if($ds_status == "ZS"){ //구매 확정된 판매건
  115. // $sql = $sql. " and s.ds_status in ('Z0')";
  116. // $sql = $sql. " and s.ds_status_contract in ('Z0')";
  117. $sql = $sql. " and s.ds_status in ('ZS')";
  118. $sql_from = $sql_from. " inner join ( ";
  119. $sql_from = $sql_from. " select cd_sale from tender_master where ds_delind = 'N' and ds_status in ('Z0') ".$sql_ds_type." group by cd_sale) i ";
  120. $sql_from = $sql_from. " on (s.cd_sale = i.cd_sale) ";
  121. // $sql = $sql. " and i.cd_sale is not null ";
  122. }else if($ds_status == "ZE"){ //유찰
  123. /*
  124. 관리자의 해약 리스트는 낙찰 상태의 거래 실패의 경우 리스트를 가져 오며,
  125. 사이트에서 유찰상태에 대한 정의가 딱히 정해 진게 없어서 아래의 조건에 해당되는 데이터를 가져온다
  126. 2020-02-02
  127. 관리자 해약 리스트 : and s.ds_status in ('Z0') and s.ds_status_contract in ('C0')
  128. 1. 낙찰상태로 변경됐으나 본인이 안된 경우
  129. - sale_master.ds_status = 'Z0' and tender_master.ds_status = 'A0'
  130. 2. 낙찰상태로 변경 됐고 본인이 된 경우
  131. 1) 거래 실패 처리 할 경우
  132. - sale_master.ds_status = 'Z0' and ds_status_contract = 'C0'
  133. 2) 견적 실수로 처리 할 경우
  134. - sale_master.ds_status = 'ZE'
  135. 3. 입찰 시간 초과와 입찰중인 상태일 경우
  136. - sale_master.ds_status = 'E0' and dt_approve + 낙찰시간 < 현재시간
  137. */
  138. $sql_column = ", sum_a.fail_type , s.nm_price as nm_price_sale ";
  139. $sql_from.= " inner join (
  140. -- 낙찰상태로 변경됐으나 본인이 안된 경우
  141. -- 단 유프로는 오류로 인해 입찰이 한번이 아닌 여러번이 될 수도 있음
  142. select s.cd_sale, '1' as fail_type from sale_master s
  143. inner join (
  144. select cd_sale
  145. from tender_master
  146. where ds_status = 'A0'
  147. $sql_ds_type
  148. and cd_sale not in(select cd_sale from tender_master where ds_status = 'Z0' $sql_ds_type )
  149. group by cd_sale) i on (s.cd_sale = i.cd_sale)
  150. where s.ds_status in ('Z0', 'ZS')
  151. union
  152. -- 2. 낙찰상태로 변경 됐고 본인이 된 경우
  153. -- 1) 거래 실패 처리 할 경우
  154. -- 2) 견적 실수로 처리 할 경우
  155. select s.cd_sale, '2' as fail_type from sale_master s
  156. inner join (
  157. select cd_sale
  158. from tender_master
  159. where ds_status = 'Z0'
  160. $sql_ds_type
  161. group by cd_sale) i on (s.cd_sale = i.cd_sale)
  162. where ((s.ds_status = 'Z0' and s.ds_status_contract = 'C0')
  163. or s.ds_status = 'ZE'
  164. )
  165. union
  166. -- 3. 입찰 시간 초과와 입찰중인 상태일 경우
  167. select s.cd_sale, '3' as fail_type from sale_master s
  168. inner join (
  169. select cd_sale
  170. from tender_master
  171. where 1
  172. $sql_ds_type
  173. group by cd_sale) i on (s.cd_sale = i.cd_sale)
  174. where (s.ds_status = 'E0' and getRemainTimeByPhase('".LIMIT_TIME_TENDER."', '".LIMIT_TIME_SELL."', s.dt_approve, now()) = '0분')
  175. ) sum_a on sum_a.cd_sale = s.cd_sale";
  176. }else{
  177. $sql = $sql. " and 1!=1 ";
  178. }
  179. }
  180. if($ds_status == "E0"){
  181. $nm_title = "입찰대기 리스트";
  182. }else if($ds_status == "F0"){
  183. $nm_title = "입찰중 리스트";
  184. }else if($ds_status == "Z0"){
  185. $nm_title = "낙찰 리스트";
  186. }else if($ds_status == "ZE"){
  187. $nm_title = "유찰 리스트";
  188. }else if($ds_status == "ZS"){
  189. $nm_title = "구매확정 리스트";
  190. }
  191. if($_SERVER['REMOTE_ADDR'] == '220.86.24.199') {
  192. // echo "select count(*) from sale_master s inner join car_master a on ( s.cd_car = a.cd_car ) $sql_from $sql";
  193. }
  194. $totalrows = @mysql_result(mysql_query("select count(*) from sale_master s inner join car_master a on ( s.cd_car = a.cd_car ) $sql_from $sql"),0,0);
  195. ?>
  196. <? include("../include/inc_top.php") ?>
  197. <? include("../include/inc_header.php") ?>
  198. <section id="wrap">
  199. <section id="visual" class="visual_mypage">
  200. <h2>마이페이지</h2>
  201. <p>쉽고 간편한 내차팔기, 견적산출, 최종 매각까지 어떤 수수료도 요구하지 않습니다.</p>
  202. </section>
  203. <section id="content">
  204. <ul class="location">
  205. <li><a href="/" class="home">홈</a></li>
  206. <li><span class="depth1">마이페이지</span>
  207. <ul class="sub_depth">
  208. <li><a href="#">마이페이지</a></li>
  209. <li><a href="#">입찰정보</a></li>
  210. <li><a href="#">차량정보</a></li>
  211. <li><a href="#">문의내역</a></li>
  212. </ul>
  213. </li>
  214. <li><span class="depth2">딜러</span></li>
  215. </ul>
  216. <? include("./inc_menu_dealer.php") ?>
  217. <h3><?=$nm_title?></h3>
  218. <div class="select_sort">
  219. <span class="select">
  220. <select>
  221. <option value="">최근</option>
  222. <option value="">종료임박순</option>
  223. <option value="">응찰적은순</option>
  224. </select>
  225. </span>
  226. </div>
  227. <ul class="car_list ty2">
  228. <?
  229. if($totalrows>0) {
  230. $r = mysql_query("SELECT
  231. a.*
  232. , b.nm_model
  233. , c.nm_grade
  234. , d.nm_brand
  235. , e.nm_model_sub
  236. , getCode('car_master','ds_type',a.ds_type) as nm_type
  237. , getCode('car_master','ds_open',a.ds_open) as nm_open
  238. , getCode('car_master','ds_sales',a.ds_sales) as nm_sales
  239. , getCode('car_master','ds_transmission',a.ds_transmission) as nm_transmission
  240. , getCode('member_master','ds_area',s.ds_area) as nm_area
  241. , getCode('sale_master','ds_status',s.ds_status) as nm_status
  242. , s.cd_sale
  243. , s.nm_name nm_name_sale
  244. , s.ds_status ds_status_sale
  245. , case when s.ds_status in ('B0','C0') then '미승인' when s.ds_status in ('D0') then '반려' when s.ds_status in ('E0','F0') then case when 'E0' = '$ds_status' then '입찰대기' else '입찰중' end when s.ds_status in ('G0') then '입찰마감' when s.ds_status in ('Z0') then '낙찰' when s.ds_status in ('ZS') then '구매확정' else '' end as nm_status_sale
  246. , case when a.ds_accident in ('A0') then '유' when a.ds_accident in ('B0') then '무' end as nm_act_yn_name
  247. , getRemainTime(".LIMIT_TIME_TENDER.", s.dt_approve, now()) as time_limit_tender
  248. , getRemainTime(".LIMIT_TIME_SELL.", s.dt_approve, now()) as time_limit_sell
  249. , ifnull((select min(nm_price) from tender_master where ds_delind = 'N' and cd_sale = s.cd_sale ".$sql_ds_type."), '') nm_price_tender
  250. , t.cd_tender cd_tender
  251. , t.ds_lock_status ds_lock_status
  252. $sql_column
  253. FROM sale_master s
  254. inner join car_master a on (s.cd_car = a.cd_car)
  255. left outer join car_model b on (a.cd_model = b.cd_model)
  256. left outer join car_grade c on (a.cd_grade = c.cd_grade)
  257. left outer join car_brand d on (a.cd_brand = d.cd_brand)
  258. left outer join car_model_sub e on (a.cd_model_sub = e.cd_model_sub)
  259. left outer join tender_master t on (s.cd_sale = t.cd_sale and t.ds_status = 'Z0' and t.ds_delind = 'N')
  260. $sql_from
  261. $sql $orderby LIMIT $pagestartpoint,$PageSize");
  262. $i=1;
  263. while($col = mysql_fetch_array($r)) {
  264. $tmpNum =$totalrows-($PageSize*($PageNo-1));
  265. $no = ($tmpNum - $i)+1;
  266. ?>
  267. <?
  268. if($col[ds_status_sale] == "ZS" && $ds_status != "ZE"){
  269. ?>
  270. <li onclick="location.href='./dealer_tender_view3.php?list_url=<?=$list_url?>&cd_sale=<?=$col[cd_sale]?>&ds_status_sale=<?=$col[ds_status_sale]?>&ds_status=<?=$ds_status?>&ListPageNo=<?=$PageNo?>';" style="cursor:pointer;">
  271. <?
  272. }else if($col[ds_status_sale] == "Z0" && $ds_status != "ZE"){
  273. $lock_border = "";
  274. if($col[ds_lock_status] == 'A0') {
  275. $lock_border = "border: 3px solid #ff0000;";
  276. }
  277. ?>
  278. <li onclick="location.href='./dealer_tender_view2.php?list_url=<?=$list_url?>&cd_sale=<?=$col[cd_sale]?>&ds_status_sale=<?=$col[ds_status_sale]?>&ds_status=<?=$ds_status?>&ListPageNo=<?=$PageNo?>';" style="cursor:pointer;<?=$lock_border?>">
  279. <?
  280. }else{
  281. ?>
  282. <li onclick="location.href='./dealer_tender_view.php?list_url=<?=$list_url?>&cd_sale=<?=$col[cd_sale]?>&ds_status_sale=<?=$col[ds_status_sale]?>&ds_status=<?=$ds_status?>&ListPageNo=<?=$PageNo?>';" style="cursor:pointer;">
  283. <?
  284. }
  285. ?>
  286. <span class="thumb"><img src="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$col[nm_file_front]?>" alt=""></span>
  287. <dl>
  288. <dt><?=$col[nm_model]." ".$col[nm_model_sub]." ".$col[nm_grade]?></dt>
  289. <dd>주행거리 : <?=$col[nm_mileage]?>km</dd>
  290. <dd>최초등록일 : <?=$col[nm_regdate_mm]?> / <?=$col[nm_regdate_yyyy]?></dd>
  291. <dd>사고유무 : <?=$col[nm_act_yn_name]?></dd>
  292. <dd>판매지역 : <?=$col[nm_area]?></dd>
  293. <?
  294. if($ds_status != "E0"){ //입찰하지 않은 판매건
  295. ?>
  296. <dd>입찰금액 : <?=$col[nm_price_tender]?>만원 </dd>
  297. <?
  298. }
  299. ?>
  300. <? if($ds_status == "E0" || $ds_status == "F0"){ ?>
  301. <dd>마감시간 : <?=$col[time_limit_tender]?></dd>
  302. <? } ?>
  303. <?
  304. if($ds_status == "ZE") {
  305. if($col[fail_type] == 1) {
  306. ?>
  307. <dd>낙찰금액 : <?=$col[nm_price_sale]?>만원 </dd>
  308. <?
  309. }
  310. }
  311. ?>
  312. </dl>
  313. <div class="flag">
  314. <?
  315. if($ds_status == "ZE") {
  316. if($col[fail_type] == 1) {
  317. ?>
  318. 낙찰
  319. <? }else { ?>
  320. 유찰
  321. <?
  322. }
  323. } else {
  324. ?>
  325. <? if($col[time_limit_sell]=="0분" && ($col[ds_status_sale] == "E0" || $col[ds_status_sale] == "F0")){ ?>
  326. 거래마감
  327. <? }else{ ?>
  328. <?=$col[nm_status_sale]?>
  329. <? } ?>
  330. <? } ?>
  331. </div>
  332. </li>
  333. <?
  334. $i++;
  335. }
  336. }else{
  337. ?>
  338. <li class="info_no">
  339. 등록된 정보가 없습니다.
  340. </li>
  341. <?
  342. }
  343. ?>
  344. </ul>
  345. <div class="paging">
  346. <?
  347. $url = "./dealer_tender_list.php?searchtype=$searchtype&searchword=$searchword&ds_status=$ds_status&ds_usertype=$ds_usertype";
  348. ListPg1($url ,$PageNo,$PageSize,10,$totalrows,$leftboard[1],$rootpath);
  349. ?>
  350. </div>
  351. </section>
  352. </section>
  353. <font color="white"><?= "" ?></font>
  354. <? include("../include/inc_footer.php") ?>
  355. <? include("../include/inc_bottom.php") ?>
  356. <?
  357. mysql_close($connect);
  358. ?>