Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

364 rader
12 KiB

  1. <?php
  2. /**
  3. *
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 娄梦宁
  12. * PhpStorm AroundModel.php
  13. * Create By 2016/11/10 14:57 $
  14. */
  15. namespace Around\Model;
  16. use Base\Tool\DbTable;
  17. use Base\Tool\LoginTool;
  18. use Model\Model\OrderMain;
  19. use Util\Util\Util;
  20. class AroundModel extends DbTable
  21. {
  22. public $db = 'CST';
  23. /**
  24. * Function Description:查询周边游列表
  25. * Function Name: getlists
  26. * @param $area_id
  27. * @param $page
  28. * @param $limit
  29. *
  30. * @return array
  31. *
  32. * @author 娄梦宁
  33. */
  34. function getlists($area_id, $page, $limit)
  35. {
  36. $page = $page == 0 ? 0 : $page - 1;
  37. $sql = '' . "SELECT
  38. a.line_sub_type AS type,
  39. a.line_name AS zname,
  40. a.LINE_DESCRIBE AS tickdes,
  41. b.IMG_URL AS img,
  42. b.PRODUCT_ID AS pro_id,
  43. floor(c.CUS_PRICE) AS price
  44. FROM
  45. opera_line a
  46. LEFT JOIN base_img b ON b.PRODUCT_ID = a.line_id
  47. LEFT JOIN opera_tickets c ON c.LINE_ID = a.LINE_ID
  48. LEFT JOIN opera_line_group d on a.line_id=d.LINE_ID
  49. WHERE
  50. a.cancel_flag = 0
  51. AND b.cancel_flag = 0
  52. AND c.cancel_flag = 0
  53. AND d.cancel_flag = 0
  54. AND b.img_type = 369
  55. AND a.line_type = 369
  56. AND c.SEAT_TYPE = 72
  57. AND c.HUMAN_TYPE in (159,334)
  58. and d.DAY_NUM=1
  59. and d.START_AREA_ID=$area_id
  60. group by
  61. a.line_id
  62. ORDER BY
  63. a.create_time
  64. LIMIT $page,$limit
  65. ";
  66. $result = $this->fetchAll($sql);
  67. if ($result === false) {
  68. return Util::returnArrEr('获取周边游数据失败!');
  69. } else {
  70. $results['list'] = $result;
  71. $results['page'] = $page + 1;
  72. $results['limit'] = $limit;
  73. return Util::returnArrSu('', $results);
  74. }
  75. }
  76. /**
  77. * Function Description:构造周边游详情返回的数据
  78. * Function Name: getdetailes
  79. * @param $pro_id
  80. *
  81. * @return array
  82. *
  83. * @author 娄梦宁
  84. */
  85. function getdetailes($pro_id)
  86. {
  87. $sql = '' . "SELECT
  88. a.line_id AS pro_id,
  89. a.LINE_DESCRIBE AS tickdes,
  90. a.line_name AS zname,
  91. a.line_sub_type AS type,
  92. floor(c.CUS_PRICE) AS price
  93. FROM
  94. opera_line a
  95. LEFT JOIN opera_tickets c ON c.LINE_ID = a.LINE_ID
  96. WHERE
  97. c.cancel_flag=0
  98. and c.cancel_flag=0
  99. and a.line_id = $pro_id";
  100. $result1 = $this->fetchAll($sql);
  101. $sql = '' . "SELECT
  102. img_url
  103. FROM
  104. base_img
  105. WHERE
  106. product_id = $pro_id
  107. AND IMG_TYPE = 369
  108. ORDER BY
  109. seq_id desc";
  110. $result2 = $this->fetchAll($sql);
  111. $sql = '' . "SELECT
  112. img_url
  113. FROM
  114. base_img
  115. WHERE
  116. product_id = $pro_id
  117. AND IMG_TYPE = 374
  118. ORDER BY
  119. seq_id desc ";
  120. $result3 = $this->fetchAll($sql);
  121. $sql = '' . "SELECT
  122. img_url
  123. FROM
  124. base_img
  125. WHERE
  126. product_id = $pro_id
  127. AND IMG_TYPE = 375
  128. ORDER BY
  129. seq_id desc";
  130. $result4 = $this->fetchAll($sql);
  131. if ($result1 === false || $result2 === false || $result3 === false) {
  132. return Util::returnArrEr("数据错误");
  133. } else {
  134. $result = $result1[0];
  135. foreach ($result2 as $key => $val) {
  136. $result2[$key] = $val['img_url'];
  137. }
  138. foreach ($result3 as $key => $val) {
  139. $result3[$key] = $val['img_url'];
  140. }
  141. foreach ($result4 as $key => $val) {
  142. $result4[$key] = $val['img_url'];
  143. }
  144. $result['topimg'] = $result2;
  145. $result['otherimg'] = $result3;
  146. $result['notice'] = $result4;
  147. return Util::returnArrSu("", $result);
  148. }
  149. }
  150. /**
  151. * Function Description:获取周边游下单详细数据
  152. * Function Name: getorders
  153. * @param $pro_id
  154. * @param $date
  155. * @param $pnum
  156. *
  157. * @return array
  158. *
  159. * @author 娄梦宁
  160. */
  161. function getorders($pro_id, $date, $pnum)
  162. {
  163. //周一至周四使用零售价CUS_PRICE,周567使用分销价PROD_PRICE
  164. $week1 = date('w', strtotime($date));
  165. if ($week1 >= 5 || $week1 === 0) {
  166. $pricetype = 'c.PROD_PRICE';
  167. } else {
  168. $pricetype = 'c.CUS_PRICE';
  169. }
  170. $sql = '' . "SELECT
  171. a.line_id AS pro_id,
  172. a.LINE_DESCRIBE AS tickdes,
  173. a.line_name AS zname,
  174. $pricetype AS price
  175. FROM
  176. opera_line a
  177. LEFT JOIN opera_tickets c ON c.LINE_ID = a.LINE_ID
  178. WHERE
  179. a.line_id = $pro_id
  180. and a.cancel_flag=0
  181. and c.cancel_flag=0
  182. ";
  183. $result1 = $this->fetchAll($sql);
  184. $sql = '' . "SELECT
  185. a.START_TIME,
  186. b.res_name,
  187. day_num
  188. FROM
  189. opera_line_group a
  190. LEFT JOIN base_resource b ON a.start_res_id = b.res_id
  191. WHERE
  192. a.line_id = $pro_id
  193. and a.cancel_flag=0
  194. and b.cancel_flag=0
  195. GROUP BY
  196. b.area_id
  197. ORDER BY
  198. day_num,seq_id
  199. ";
  200. $result2 = $this->fetchAll($sql);
  201. if ($result1 === false || $result2 === false) {
  202. return Util::returnArrEr("数据错误");
  203. } else {
  204. $result = $result1[0];
  205. $result['start_date'] = date("Y年m月d日", strtotime($date));
  206. $cnt = count($result2) - 1;
  207. $datenum = $result2[1]['day_num'] - 1;
  208. $result['end_date'] = date("Y年m月d日", strtotime("$date +$datenum day"));
  209. $result['price'] = $result['price'] * $pnum;
  210. $result['start_time'] = $result2[0]['START_TIME'];
  211. $result['start_area'] = $result2[0]['res_name'];
  212. $result['end_area'] = $result2[$cnt]['res_name'];
  213. $result['end_time'] = $result2[$cnt]['START_TIME'];
  214. return Util::returnArrSu("", $result);
  215. }
  216. }
  217. /**
  218. * Function Description:构造12.29之前的日期价格数组
  219. * Function Name: getdate
  220. * @param $pro_id
  221. *
  222. * @return array
  223. *
  224. * @author 娄梦宁
  225. */
  226. public function getdate($pro_id)
  227. {
  228. $sql = '' . "select CUS_PRICE,PROD_PRICE from opera_tickets where line_id=$pro_id
  229. and cancel_flag=0";
  230. $price = $this->fetchRow($sql);
  231. if ($price === false) {
  232. return Util::returnArrEr("数据查询错误");
  233. } else {
  234. $price1 = $price['CUS_PRICE'];
  235. $price2 = $price['PROD_PRICE'];
  236. $result = array();
  237. $timer = date('H', time());
  238. if ($timer > 13) {
  239. $timer1 = strtotime('+2 day');
  240. } else {
  241. $timer1 = strtotime('+1 day');
  242. }
  243. for ($i = $timer1; $i < strtotime('2018-01-01'); $i += 86400) {
  244. $thisdate = date('Y-m-d', $i);
  245. $week = date('w', $i);
  246. if ($week >= 5 || $week == 0) {
  247. $result[] = array(
  248. 'date' => $thisdate,
  249. 'price' => $price2
  250. );
  251. } else {
  252. $result[] = array(
  253. 'date' => $thisdate,
  254. 'price' => $price1
  255. );
  256. }
  257. }
  258. return Util::returnArrSu("", $result);
  259. }
  260. }
  261. public function makeorders($arr)
  262. {
  263. //判断价格是否正确
  264. $start_date = $arr['para_start_date'];
  265. $week_type = date('w', $start_date);
  266. if ($week_type < 5 || $week_type > 0) {
  267. $price_str = 'cus_price';
  268. } else {
  269. $price_str = 'prod_price';
  270. };
  271. $sql = '' . "select $price_str from opera_tickets where line_id=$arr[para_line_id] and cancel_flag=0";
  272. $check_price = $this->fetchOne($sql);
  273. if ($check_price != $arr['para_price']) {
  274. return Util::returnArrEr("数据错误");
  275. }
  276. //判断剩余座位是否足够
  277. $pro_id = $arr['para_line_id'];
  278. $p_num = $arr['para_count'];
  279. $sql = '' . "SELECT
  280. seat_count - saled_count as seat
  281. FROM
  282. run_bus
  283. WHERE
  284. run_id IN (
  285. SELECT
  286. run_id
  287. FROM
  288. run_main
  289. WHERE
  290. prod_id IN (
  291. SELECT
  292. sub_line_id
  293. FROM
  294. opera_line_group
  295. WHERE
  296. line_id = $pro_id
  297. )
  298. AND run_date = '$start_date' and run_status=138 and cancel_flag=0
  299. )
  300. ";
  301. $seat_count = $this->fetchAll($sql);
  302. foreach ($seat_count as $val) {
  303. if ($val['seat'] < $p_num) {
  304. return Util::returnArrEr('剩余座位不够');
  305. }
  306. }
  307. $sql = '' . "SELECT DISTINCT
  308. start_res_id,
  309. end_res_id
  310. FROM
  311. opera_line_group
  312. WHERE
  313. line_id = $pro_id
  314. and cancel_flag=0
  315. ";
  316. $res_id = $this->fetchAll($sql);
  317. $res_id_go = $res_id[0]['start_res_id'];
  318. $cnt = count($res_id) - 1;
  319. $res_back_id = $res_id[$cnt]['start_res_id'];
  320. $contacts = $arr['para_remark'];
  321. $sql = '' . "select `name`,id_num from wechat_customer where id in ($contacts)";
  322. $contacts = $this->fetchAll($sql);
  323. $count = count($contacts);
  324. while ($count < $p_num) {
  325. $contacts[] = $contacts[0];
  326. $count++;
  327. }
  328. $para_contact = '{';
  329. foreach ($contacts as $val) {
  330. $para_contact .= $val['name'] . ',' . $val['id_num'] . '|';
  331. }
  332. $para_contact = "'" . substr_replace($para_contact, '}', -1, 1) . "'";
  333. $sql = "call sp_make_order_wechat(2,$arr[para_line_id],'$arr[para_start_date]',$res_id_go,$res_back_id,$arr[para_count],'$arr[para_contact]',$para_contact,$arr[para_price]) ";
  334. $result = $this->procQuery($sql);
  335. if ($result['code'] === 0) {
  336. $newid = $result['data'][0][0]['order_id'];
  337. $user_id = LoginTool::$userId;
  338. $sql = '' . "update order_main set OUTSIDE_SALE_ORG_ID=164,SALES_MAN='吴昊',MEMBER_ID=$user_id,order_prod_type=369 where (order_id=$newid or parent_order_id=$newid)";
  339. $result1 = $this->execSql($sql);
  340. $orderMain = new OrderMain();
  341. $result2 = $orderMain->updateBookStatus($newid);
  342. if ($result2['flag']) {
  343. if ($result1) {
  344. $siteConfig = Util::getSiteConfig();
  345. $url = "{$siteConfig['host_name']}/wechat/WxPay/realpay/weChatShopPay.php?order_id={$newid}";
  346. return Util::returnArrSu('', '', $url);
  347. } else {
  348. return Util::returnArrEr("修改订单状态出错");
  349. }
  350. }
  351. }
  352. return Util::returnArrEr("订单提交失败");
  353. }
  354. }