|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- <?php
-
- /**
- *
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 娄梦宁
- * PhpStorm AroundModel.php
- * Create By 2016/11/10 14:57 $
- */
- namespace Around\Model;
-
- use Base\Tool\DbTable;
- use Base\Tool\LoginTool;
- use Model\Model\OrderMain;
- use Util\Util\Util;
-
- class AroundModel extends DbTable
- {
- public $db = 'CST';
-
- /**
- * Function Description:查询周边游列表
- * Function Name: getlists
- * @param $area_id
- * @param $page
- * @param $limit
- *
- * @return array
- *
- * @author 娄梦宁
- */
- function getlists($area_id, $page, $limit)
- {
- $page = $page == 0 ? 0 : $page - 1;
- $sql = '' . "SELECT
- a.line_sub_type AS type,
- a.line_name AS zname,
- a.LINE_DESCRIBE AS tickdes,
- b.IMG_URL AS img,
- b.PRODUCT_ID AS pro_id,
- floor(c.CUS_PRICE) AS price
- FROM
- opera_line a
- LEFT JOIN base_img b ON b.PRODUCT_ID = a.line_id
- LEFT JOIN opera_tickets c ON c.LINE_ID = a.LINE_ID
- LEFT JOIN opera_line_group d on a.line_id=d.LINE_ID
- WHERE
- a.cancel_flag = 0
- AND b.cancel_flag = 0
- AND c.cancel_flag = 0
- AND d.cancel_flag = 0
- AND b.img_type = 369
- AND a.line_type = 369
- AND c.SEAT_TYPE = 72
- AND c.HUMAN_TYPE in (159,334)
- and d.DAY_NUM=1
- and d.START_AREA_ID=$area_id
- group by
- a.line_id
- ORDER BY
- a.create_time
- LIMIT $page,$limit
- ";
- $result = $this->fetchAll($sql);
- if ($result === false) {
- return Util::returnArrEr('获取周边游数据失败!');
- } else {
- $results['list'] = $result;
- $results['page'] = $page + 1;
- $results['limit'] = $limit;
- return Util::returnArrSu('', $results);
- }
- }
-
- /**
- * Function Description:构造周边游详情返回的数据
- * Function Name: getdetailes
- * @param $pro_id
- *
- * @return array
- *
- * @author 娄梦宁
- */
- function getdetailes($pro_id)
- {
- $sql = '' . "SELECT
- a.line_id AS pro_id,
- a.LINE_DESCRIBE AS tickdes,
- a.line_name AS zname,
- a.line_sub_type AS type,
- floor(c.CUS_PRICE) AS price
- FROM
- opera_line a
- LEFT JOIN opera_tickets c ON c.LINE_ID = a.LINE_ID
- WHERE
- c.cancel_flag=0
- and c.cancel_flag=0
- and a.line_id = $pro_id";
- $result1 = $this->fetchAll($sql);
- $sql = '' . "SELECT
- img_url
- FROM
- base_img
- WHERE
- product_id = $pro_id
- AND IMG_TYPE = 369
- ORDER BY
- seq_id desc";
- $result2 = $this->fetchAll($sql);
- $sql = '' . "SELECT
- img_url
- FROM
- base_img
- WHERE
- product_id = $pro_id
- AND IMG_TYPE = 374
- ORDER BY
- seq_id desc ";
- $result3 = $this->fetchAll($sql);
- $sql = '' . "SELECT
- img_url
- FROM
- base_img
- WHERE
- product_id = $pro_id
- AND IMG_TYPE = 375
- ORDER BY
- seq_id desc";
- $result4 = $this->fetchAll($sql);
- if ($result1 === false || $result2 === false || $result3 === false) {
- return Util::returnArrEr("数据错误");
- } else {
- $result = $result1[0];
- foreach ($result2 as $key => $val) {
- $result2[$key] = $val['img_url'];
- }
- foreach ($result3 as $key => $val) {
- $result3[$key] = $val['img_url'];
- }
- foreach ($result4 as $key => $val) {
- $result4[$key] = $val['img_url'];
- }
- $result['topimg'] = $result2;
- $result['otherimg'] = $result3;
- $result['notice'] = $result4;
- return Util::returnArrSu("", $result);
- }
- }
-
- /**
- * Function Description:获取周边游下单详细数据
- * Function Name: getorders
- * @param $pro_id
- * @param $date
- * @param $pnum
- *
- * @return array
- *
- * @author 娄梦宁
- */
- function getorders($pro_id, $date, $pnum)
- {
- //周一至周四使用零售价CUS_PRICE,周567使用分销价PROD_PRICE
- $week1 = date('w', strtotime($date));
- if ($week1 >= 5 || $week1 === 0) {
- $pricetype = 'c.PROD_PRICE';
- } else {
- $pricetype = 'c.CUS_PRICE';
- }
- $sql = '' . "SELECT
- a.line_id AS pro_id,
- a.LINE_DESCRIBE AS tickdes,
- a.line_name AS zname,
- $pricetype AS price
- FROM
- opera_line a
- LEFT JOIN opera_tickets c ON c.LINE_ID = a.LINE_ID
- WHERE
- a.line_id = $pro_id
- and a.cancel_flag=0
- and c.cancel_flag=0
- ";
- $result1 = $this->fetchAll($sql);
- $sql = '' . "SELECT
- a.START_TIME,
- b.res_name,
- day_num
- FROM
- opera_line_group a
- LEFT JOIN base_resource b ON a.start_res_id = b.res_id
- WHERE
- a.line_id = $pro_id
- and a.cancel_flag=0
- and b.cancel_flag=0
- GROUP BY
- b.area_id
- ORDER BY
- day_num,seq_id
- ";
- $result2 = $this->fetchAll($sql);
- if ($result1 === false || $result2 === false) {
- return Util::returnArrEr("数据错误");
- } else {
- $result = $result1[0];
- $result['start_date'] = date("Y年m月d日", strtotime($date));
- $cnt = count($result2) - 1;
- $datenum = $result2[1]['day_num'] - 1;
- $result['end_date'] = date("Y年m月d日", strtotime("$date +$datenum day"));
- $result['price'] = $result['price'] * $pnum;
- $result['start_time'] = $result2[0]['START_TIME'];
- $result['start_area'] = $result2[0]['res_name'];
- $result['end_area'] = $result2[$cnt]['res_name'];
- $result['end_time'] = $result2[$cnt]['START_TIME'];
- return Util::returnArrSu("", $result);
- }
- }
-
- /**
- * Function Description:构造12.29之前的日期价格数组
- * Function Name: getdate
- * @param $pro_id
- *
- * @return array
- *
- * @author 娄梦宁
- */
- public function getdate($pro_id)
- {
- $sql = '' . "select CUS_PRICE,PROD_PRICE from opera_tickets where line_id=$pro_id
- and cancel_flag=0";
- $price = $this->fetchRow($sql);
- if ($price === false) {
- return Util::returnArrEr("数据查询错误");
- } else {
- $price1 = $price['CUS_PRICE'];
- $price2 = $price['PROD_PRICE'];
- $result = array();
- $timer = date('H', time());
- if ($timer > 13) {
- $timer1 = strtotime('+2 day');
- } else {
- $timer1 = strtotime('+1 day');
- }
- for ($i = $timer1; $i < strtotime('2018-01-01'); $i += 86400) {
- $thisdate = date('Y-m-d', $i);
- $week = date('w', $i);
- if ($week >= 5 || $week == 0) {
- $result[] = array(
- 'date' => $thisdate,
- 'price' => $price2
- );
- } else {
- $result[] = array(
- 'date' => $thisdate,
- 'price' => $price1
- );
- }
- }
- return Util::returnArrSu("", $result);
- }
- }
-
-
- public function makeorders($arr)
- {
- //判断价格是否正确
- $start_date = $arr['para_start_date'];
- $week_type = date('w', $start_date);
- if ($week_type < 5 || $week_type > 0) {
- $price_str = 'cus_price';
- } else {
- $price_str = 'prod_price';
- };
- $sql = '' . "select $price_str from opera_tickets where line_id=$arr[para_line_id] and cancel_flag=0";
- $check_price = $this->fetchOne($sql);
- if ($check_price != $arr['para_price']) {
- return Util::returnArrEr("数据错误");
- }
- //判断剩余座位是否足够
- $pro_id = $arr['para_line_id'];
-
- $p_num = $arr['para_count'];
- $sql = '' . "SELECT
- seat_count - saled_count as seat
- FROM
- run_bus
- WHERE
- run_id IN (
- SELECT
- run_id
- FROM
- run_main
- WHERE
- prod_id IN (
- SELECT
- sub_line_id
- FROM
- opera_line_group
- WHERE
- line_id = $pro_id
- )
- AND run_date = '$start_date' and run_status=138 and cancel_flag=0
- )
- ";
- $seat_count = $this->fetchAll($sql);
- foreach ($seat_count as $val) {
- if ($val['seat'] < $p_num) {
- return Util::returnArrEr('剩余座位不够');
- }
- }
- $sql = '' . "SELECT DISTINCT
- start_res_id,
- end_res_id
- FROM
- opera_line_group
- WHERE
- line_id = $pro_id
- and cancel_flag=0
- ";
- $res_id = $this->fetchAll($sql);
- $res_id_go = $res_id[0]['start_res_id'];
- $cnt = count($res_id) - 1;
- $res_back_id = $res_id[$cnt]['start_res_id'];
- $contacts = $arr['para_remark'];
- $sql = '' . "select `name`,id_num from wechat_customer where id in ($contacts)";
- $contacts = $this->fetchAll($sql);
- $count = count($contacts);
- while ($count < $p_num) {
- $contacts[] = $contacts[0];
- $count++;
- }
- $para_contact = '{';
- foreach ($contacts as $val) {
- $para_contact .= $val['name'] . ',' . $val['id_num'] . '|';
- }
- $para_contact = "'" . substr_replace($para_contact, '}', -1, 1) . "'";
- $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]) ";
- $result = $this->procQuery($sql);
- if ($result['code'] === 0) {
- $newid = $result['data'][0][0]['order_id'];
- $user_id = LoginTool::$userId;
- $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)";
- $result1 = $this->execSql($sql);
- $orderMain = new OrderMain();
- $result2 = $orderMain->updateBookStatus($newid);
- if ($result2['flag']) {
- if ($result1) {
- $siteConfig = Util::getSiteConfig();
- $url = "{$siteConfig['host_name']}/wechat/WxPay/realpay/weChatShopPay.php?order_id={$newid}";
- return Util::returnArrSu('', '', $url);
- } else {
- return Util::returnArrEr("修改订单状态出错");
- }
- }
- }
- return Util::returnArrEr("订单提交失败");
- }
- }
|