|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941 |
- <?php
- /**
- * Function Description:驴妈妈对应的接口
- * Function Name: ApiForLvmama
- * @return ${TYPE_HINT}
- * ${THROWS_DOC}
- *
- * @author 娄梦宁
- */
-
- namespace backend\modules\api\controllers;
-
- use backend\modules\api\models\LvmamaOrderConnect;
- use backend\modules\api\models\LvmamaPushInfo;
- use backend\modules\api\models\OperaProduct;
- use backend\modules\api\models\OrderMain;
- use backend\modules\api\models\OrderRefundLvmama;
- use backend\modules\api\models\OutsideTicket;
- use backend\modules\api\util\Util;
- use common\models\Msg;
- use common\models\Utils;
- use yii\base\Exception;
- use yii\web\Controller;
- use Yii;
-
-
- class LvmamaController extends Controller
- {
- public $enableCsrfValidation = false;
-
- public function actionIndex()
- {
- return 'HELLO';
- }
-
- /**
- * Function Description:获取 批量景区基本信息接口(暂无相关数据处理)
- * Function Name: actionGetScenicList
- *
- *
- * @author 娄梦宁
- */
- public function actionGetScenicList()
- {
- $util = new Util();
- //请求参数构建
- $time = time();
- $appKey = $util->getAppKey();
- $timestamp = $time;
- $sign = $util::SingForLvmama($time);
- $currentPage = 1;
- $url = $util->getBaseUrl() . '/ticketProd/scenicInfoListByPage' . "?appKey=" . $appKey . "&messageFormat=json×tamp=" . $timestamp . "&sign=" . $sign . "¤tPage=" . $currentPage;
- $result = Utils::httpRequest($url);
- print_r($url);
- print_r(json_decode($result, true));
- }
-
- /**
- * Function Description:批量产品/商品信息接口
- * Function Name: actionGetProdList
- *
- *
- * @author 娄梦宁
- */
- public function actionGetProdList()
- {
- set_time_limit(0);
- $util = new Util();
- $opera_prod = new OperaProduct();
- $outside_ticket = new OutsideTicket();
- //请求参数构建
- $time = time();
- $appKey = $util->getAppKey();
- $timestamp = $time;
- $sign = $util::SingForLvmama($time);
- $currentPage = 1;
- $url = $util->getBaseUrl() . '/ticketProd/productInfoListByPage' . "?appKey=" . $appKey . "&messageFormat=json×tamp=" . $timestamp . "&sign=" . $sign . "¤tPage=" . $currentPage;
- $result = Utils::httpRequest($url);
- $prod_list = json_decode($result, true);
- //查出opera_prod表中所有的主code(即驴妈妈的productId)
- $code_arr = $opera_prod->getCodeArr();
- $code_arr_son=$opera_prod->getCodeArrSon();
- for ($currentPage = 1; $currentPage <= $prod_list['totalPage']; $currentPage++) {
- if ($currentPage == 1) {//分页的循环
- $tmp_arr = $prod_list;
- } else {
- $url = $util->getBaseUrl() . '/ticketProd/productInfoListByPage' . "?appKey=" . $appKey . "&messageFormat=json×tamp=" . $timestamp . "&sign=" . $sign . "¤tPage=" . $currentPage;
- $result = Utils::httpRequest($url);
- $tmp_arr = json_decode($result, true);
- }
- foreach ($tmp_arr['productList'] as $val) {
- //如果产品在opera_prod表中,即产品信息已添加
- if (array_key_exists($val['productId'], $code_arr)) {//产品已经存在
- if ($val['productStatus'] == true) {//当前产品在驴妈妈上架
- $tmp_prod_name = $util::doCdada($val['productName']);
- $remark = '';
- if (isset($val['bookingInfo'])) {
- foreach ($val['bookingInfo'] as $book) {
- $remark .= $util::doCdada($book);
- }
- }
- $remark .= $util::doCdada($val['goodsList'][0]['importentPoint']);
- $is_refund = $val['goodsList'][0]['rules'][0]['isChange'];
- $refund_limit_day = 1;
- $refund_limit_time = '23:00';
- if ($is_refund == 1 && isset($val['goodsList'][0]['rules'][0]['aheadTime'])) {//可以退款就同步退款规则
- $limit_day_time = $util::countRefundTime($val['goodsList'][0]['rules'][0]['aheadTime']);
- $refund_limit_day = $limit_day_time['day'];
- $refund_limit_time = $limit_day_time['time'];
- }
- $tmp_prod_code = $val['productId'];
- //
- $upt_main = $opera_prod->uptLvmamaProdDetail($tmp_prod_code, $tmp_prod_name, $remark, $refund_limit_day, $refund_limit_time, $is_refund);
- $parent_id = $code_arr[$val['productId']]['prod_id'];
- // }else{
- // $upt_main=$opera_prod->istLvmamaProdMain($tmp_prod_code, $tmp_prod_name, $remark, $refund_limit_day, $refund_limit_time, $is_refund);
- // $parent_id=$upt_main['prod_id'];
- // }
- if ($upt_main['code'] != 0) {
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . $upt_main['msg'] . $val['prod_code'] . " 批量定时更新产品出错" . PHP_EOL, FILE_APPEND);
- continue;
- }
- foreach ($val['goodsList'] as $goods) {//循环添加子产品
- if ($goods['status'] == true) {
- $prod_name_son = $util::doCdada($goods['goodsName']);
- $prod_code_son = $goods['goodsId'];
- if (array_key_exists($prod_code_son, $code_arr_son)) {//商品已经存在
- $son_prod = $opera_prod->uptLvmamaProdSon($prod_code_son, $prod_name_son, $remark, $refund_limit_day, $refund_limit_time, $is_refund, $parent_id);
- } else {
- $son_prod = $opera_prod->insLvmamaProdSon($parent_id, $prod_name_son, $prod_code_son, $refund_limit_day, $refund_limit_time, $is_refund);
- }
- if ($son_prod['code'] != 0) {
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . $son_prod['msg'] . $prod_code_son . " 批量定时添加子门票产品出错" . PHP_EOL, FILE_APPEND);
- continue;
- }
- } else {//商品下架
- $outside_ticket->cancelGoods($val['productId'], $goods['goodsId']);
- }
- }
- } else {//产品下架
- $opera_prod->cancelProductByCode($val['productId']);
- }
- }
- }
- }
- }
-
- /**
- * Function Description:批量价格、库存信息
- * Function Name: actionGetProdPriceList
- *
- *
- * @author 娄梦宁
- */
- public function actionGetProdPriceList()
- {
- set_time_limit(0);
- $util = new Util();
- $opera_prod = new OperaProduct();
- $outside_ticket = new OutsideTicket();
- //请求参数构建
- $time = time();
- $appKey = $util->getAppKey();
- $timestamp = $time;
- $sign = $util::SingForLvmama($time);
- $currentPage = 1;
- $beginDate = date('Y-m-d');
- $endDate = date('Y-m-d', strtotime('+ 30 day'));
- $url = $util->getBaseUrl() . '/ticketProd/productPriceListByPage' . "?appKey=" . $appKey . "&messageFormat=json×tamp=" . $timestamp . "&sign=" . $sign .
- "¤tPage=" . $currentPage . "&beginDate=" . $beginDate . "&endDate=" . $endDate;
- $prod_list = Utils::httpRequest($url);
- //查出opera_prod表中所有的code(即驴妈妈的productId)
- $code_arr = $opera_prod->getCodeArr();
- //循环所有页数,每次结果插入opera_ticket
- $prod_list = json_decode($prod_list, true);
- for ($currentPage = 1; $currentPage <= $prod_list['totalPage']; $currentPage++) {
- if ($currentPage == 1) {
- $tmp_arr = $prod_list;
- } else {
- $url = $util->getBaseUrl() . '/ticketProd/productPriceListByPage' . "?appKey=" . $appKey . "&messageFormat=json×tamp=" . $timestamp . "&sign=" . $sign .
- "¤tPage=" . $currentPage . "&beginDate=" . $beginDate . "&endDate=" . $endDate;
- $tmp_arr = Utils::httpRequest($url);
- $tmp_arr = json_decode($tmp_arr, true);
- }
- foreach ($tmp_arr['priceList'] as $val) {
- //////////////////这层逻辑先不管
- // if (array_key_exists($val['productId'], $code_arr)) {//如果产品在opera_prod表中,即在售
- // }
- // else {//加一层逻辑,获取到的产品都加到opera_prod表中,(前提是驴妈妈接口反馈都是有效数据)
- // //添加主产品
- // $prod_id = $val['productId'];
- // $prod_info = $this->GetProdById($prod_id);
- // try {
- // $prod_name = $util::doCdada($prod_info['productList'][0]['productName']);
- // //$remark = $util::doCdada($prod_info['productList'][0]['introdution']);暂不需要简介
- // $remark = '';
- // foreach ($prod_info['productList'][0]['bookinginfo'] as $book) {
- // $remark .= $util::doCdada($book);
- // }
- // } catch (Exception $e) {
- // file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . $prod_id . " 添加产品获取详情出错" . PHP_EOL, FILE_APPEND);
- // continue;
- // }
- // $main_prod_id = $opera_prod->istLvmamaProdMain($prod_id, $prod_name, $remark);
- // if ($main_prod_id['code'] != 0) {
- // file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . $main_prod_id['msg'] . $prod_id . " 添加主门票产品出错" . PHP_EOL, FILE_APPEND);
- // continue;
- // }
- // foreach ($val['goodsList']['goods'] as $goods) {//循环添加子产品
- // $parent_id_son = $main_prod_id['prod_id'];
- // $prod_name_son = $util::doCdada($goods['goodsName']);
- // $prod_code_son = $goods['goodsId'];
- // $son_prod = $opera_prod->insLvmamaProdSon($parent_id_son, $prod_name_son, $prod_code_son);
- // if ($son_prod['code'] != 0) {
- // file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . $son_prod['msg'] . $prod_code_son . " 添加子门票产品出错" . PHP_EOL, FILE_APPEND);
- // continue;
- // }
- // }
- // $code_arr = $opera_prod->getCodeArr();
- // }
- if ($val['productStatus'] == true) {//产品上线中
- foreach ($val['goodsList']['goods'] as $v) {//循环prod下的商品,
- if ($v['goodsOnLine'] == true) {//商品上线中
- if (!empty($v['prices'])) {
- foreach ($v['prices']['price'] as $value) {//循环不同的价格日历
- $tmp_prod_code = $val['productId'];
- $tmp_prod_name = $code_arr[$tmp_prod_code]['prod_name'];
- $tmp_ticket_code = $v['goodsId'];
- $tmp_ticket_date = $value['date'];
- $tmp_ticket_name = $util::doCdada($v['goodsName']);
- $tmp_ticket_num = $value['stock'] == -1 ? 9999 : $value['stock'];
- $tmp_ticket_price = $value['b2bPrice'];
- $tmp_agent_price = $value['sellPrice'];
- $tmp_cs_prod_id = $code_arr[$tmp_prod_code]['prod_id'];
- $tmp_insert = $outside_ticket->InsertData($tmp_prod_code, $tmp_prod_name, $tmp_ticket_code, $tmp_ticket_date, $tmp_ticket_name,
- $tmp_ticket_num, $tmp_ticket_price, $tmp_agent_price, $tmp_cs_prod_id);
- if (!$tmp_insert) {
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . $tmp_prod_code . $tmp_prod_name . $tmp_ticket_date
- . "批量接口插入更新失败" . PHP_EOL, FILE_APPEND);
- }
- }
- }
- } else {//商品已下线
- $outside_ticket->cancelGoods($val['productId'], $v['goodsId']);
- }
- }
- } else {//产品已下线
- $opera_prod->cancelProductByCode($val['productId']);
- }
- }
- }
- }
-
-
- /**
- * Function Description:通过id获取产品信息
- * Function Name: actionGetProdById
- *
- *
- * @author 娄梦宁
- */
- public function GetProdById($productIds)
- {
- $util = new Util();
- //请求参数构建
- $time = time();
- $appKey = $util->getAppKey();
- $timestamp = $time;
- $sign = $util::SingForLvmama($time);
- $url = $util->getBaseUrl() . '/ticketProd/productInfoList' . "?appKey=" . $appKey . "&messageFormat=json×tamp=" . $timestamp . "&sign=" . $sign . "&productIds=" . $productIds;
- $result = Utils::httpRequest($url);
- return json_decode($result, true);
- }
-
- /**
- * Function Description:定时任务通过id同步产品信息
- * Function Name: actionGetProdById
- *
- *
- * @author 娄梦宁
- */
- public function actionUptProdById()
- {
- set_time_limit(0);
- $opera_prod = new OperaProduct();
- $util = new Util();
- //获取驴妈妈渠道下所有产品id
- $prod_arr = $opera_prod->getIdForLvmama();
- foreach ($prod_arr as $val) {//循环处理各产品
- if ($val['productStatus'] == true) {//产品在驴妈妈上架
- $prod_info = $this->GetProdById($val['prod_code']);
- try {
- $prod_name = $util::doCdada($prod_info['productList'][0]['productName']);
- $remark = '';
- foreach ($prod_info['productList'][0]['bookingInfo'] as $book) {
- $remark .= $util::doCdada($book);
- }
- } catch (Exception $e) {
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . $val['prod_code'] . " 定时更新产品id获取详情出错" . PHP_EOL, FILE_APPEND);
- continue;
- }
- $main_prod_id = $opera_prod->uptLvmamaProdMain($val['prod_code'], $prod_name, $remark);
- if ($main_prod_id['code'] != 0) {
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . $main_prod_id['msg'] . $val['prod_code'] . " 定时更新产品id出错" . PHP_EOL, FILE_APPEND);
- continue;
- }
- }
- // else {//产品在驴妈妈下架
- // $opera_prod->cancelProductByCode($val['productId']);
- // }
- }
- }
-
- /**
- * Function Description:通过id获取商品信息
- * Function Name: actionGetGoodById
- *
- *
- * @author 娄梦宁
- */
- public function GetGoodById($goodsIds)
- {
- $util = new Util();
- //请求参数构建
- $time = time();
- $appKey = $util->getAppKey();
- $timestamp = $time;
- $sign = $util::SingForLvmama($time);
- $url = $util->getBaseUrl() . '/ticketProd/goodInfoList' . "?appKey=" . $appKey . "&messageFormat=json×tamp=" . $timestamp . "&sign=" . $sign . "&goodsIds=" . $goodsIds;
- $result = Utils::httpRequest($url);
- return json_decode($result, true);
- }
-
- public function actionTest(){
- $util = new Util();
- //请求参数构建
- $time = time();
- $appKey = $util->getAppKey();
- $timestamp = $time;
- $beginDate = date('Y-m-d');
- $endDate = date('Y-m-d', strtotime('+ 60 day'));
- $sign = $util::SingForLvmama($time);
- $url = $util->getBaseUrl() . '/ticketProd/productInfoList' . "?appKey=" . $appKey . "&messageFormat=json×tamp=" . $timestamp . "&sign=" . $sign . "&productIds=" . 1040730;
- // $url = $util->getBaseUrl() . '/ticketProd/goodInfoList' . "?appKey=" . $appKey . "&messageFormat=json×tamp=" . $timestamp . "&sign=" . $sign . "&goodsIds=" . 934395;
- $url = $util->getBaseUrl() . '/ticketProd/goodPriceList' . "?appKey=" . $appKey . "&messageFormat=json×tamp=" . $timestamp . "&sign=" . $sign . "&goodsIds=" . 9992857 . "&beginDate=" . $beginDate . "&endDate=" . $endDate;
- $result = Utils::httpRequest($url);
- print_r(json_decode($result, true));
- }
-
- /**
- * Function Description:定时任务通过id同步商品信息
- * Function Name: actionGetProdById
- *
- *
- * @author 娄梦宁
- */
- public function actionUptGoodById()
- {
- set_time_limit(0);
- $opera_prod = new OperaProduct();
- $outside_ticket = new OutsideTicket();
- $util = new Util();
- //获取驴妈妈渠道下所有子产品code
- $prod_arr = $opera_prod->getSonIdForLvmama();
- foreach ($prod_arr as $val) {
- $prod_info = $this->GetGoodById($val['prod_code']);
- if ($prod_info['goodsList'][0]['status'] == true) {//商品在驴妈妈上架则更新信息
- try {
- $prod_name = $util::doCdada($prod_info['goodsList'][0]['goodsName']);
- $remark = $util::doCdada($prod_info['goodsList'][0]['importentPoint']);
- $is_refund = $prod_info['goodsList'][0]['rules'][0]['isChange'];
- $refund_limit_day = 1;
- $refund_limit_time = '23:00';
- if ($is_refund == 1 && isset($prod_info['goodsList'][0]['rules'][0]['aheadTime'])) {//可以退款就同步退款规则
- $limit_day_time = $util::countRefundTime($prod_info['goodsList'][0]['rules'][0]['aheadTime']);
- $refund_limit_day = $limit_day_time['day'];
- $refund_limit_time = $limit_day_time['time'];
- }
- } catch (Exception $e) {
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . $val['prod_code'] . " 定时更新产品id获取详情出错" . PHP_EOL, FILE_APPEND);
- continue;
- }
- $main_prod_id = $opera_prod->uptLvmamaProdSon($val['prod_code'], $prod_name, $remark, $refund_limit_day, $refund_limit_time, $is_refund);
- if ($main_prod_id['code'] != 0) {
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . $main_prod_id['msg'] . $val['prod_code'] . " 定时更新产品id出错" . PHP_EOL, FILE_APPEND);
- continue;
- }
- //同步两天后价格日历信息
- $this->GetGoodPriceList($val['prod_code']);
- } else {//商品在驴妈妈下架
- $outside_ticket->cancelGoods($val['productId'], $val['goodsId']);
- }
- }
- }
- /**
- * Function Description:按 ID 获取价格库存接口
- * Function Name: GetGoodPriceList
- * @param $goodsIds
- *
- *
- * @author 娄梦宁
- */
- public function GetGoodPriceList($goodsIds)
- {
- $util = new Util();
- $outside_ticket = new OutsideTicket();
- $opera_prod = new OperaProduct();
- //请求参数构建
- $time = time();
- $appKey = $util->getAppKey();
- $timestamp = $time;
- $beginDate = date('Y-m-d');
- $endDate = date('Y-m-d', strtotime('+ 2 day'));
- $sign = $util::SingForLvmama($time);
- $url = $util->getBaseUrl() . '/ticketProd/goodPriceList' . "?appKey=" . $appKey . "&messageFormat=json×tamp=" . $timestamp . "&sign=" . $sign . "&goodsIds=" . $goodsIds . "&beginDate=" . $beginDate . "&endDate=" . $endDate;
- $result = Utils::httpRequest($url);
- $result = json_decode($result, true);
- //查出opera_prod表中所有的code(即驴妈妈的productId)
-
- $code_arr = $opera_prod->getCodeArr();
- if ($result['state']['code'] != 1000) {
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '按 ID 获取商品价格库存接口接口访问失败 ' . $result['state']['solution'] . PHP_EOL, FILE_APPEND);
- }
- foreach ($result['priceList'] as $val) {
- if ($val['productStatus'] == true) {
- foreach ($val['goodsList']['goods'] as $v) {
- if ($v['goodsOnLine'] == true) {
- if ($v['prices']['price']) {
- foreach ($v['prices']['price'] as $value) {
- $tmp_prod_code = $val['productId'];
- $tmp_prod_name = $code_arr[$tmp_prod_code]['prod_name'];
- $tmp_ticket_code = $v['goodsId'];
- $tmp_ticket_date = $value['date'];
- $tmp_ticket_name = $util::doCdada($v['goodsName']);
- $tmp_ticket_num = $value['stock'] == -1 ? 9999 : $value['stock'];
- $tmp_ticket_price = $value['b2bPrice'];
- $tmp_agent_price = $value['sellPrice'];
- $tmp_cs_prod_id = $code_arr[$tmp_prod_code]['prod_id'];
- $tmp_insert = $outside_ticket->InsertData($tmp_prod_code, $tmp_prod_name, $tmp_ticket_code, $tmp_ticket_date, $tmp_ticket_name,
- $tmp_ticket_num, $tmp_ticket_price, $tmp_agent_price, $tmp_cs_prod_id);
- if (!$tmp_insert) {
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . $tmp_prod_code . $tmp_prod_name . $tmp_ticket_date
- . "单产品插入更新失败" . PHP_EOL, FILE_APPEND);
- }
- }
- }
- } else {//商品下架不在此处理
- continue;
- }
- }
- } else {//产品下架不在此处理
- continue;
- }
- }
- }
-
- /**
- * Function Description:按 ID 获取景区信息接口(不通)
- * Function Name: actionGetScenicListById
- *
- *
- * @author 娄梦宁
- */
- public function actionGetScenicListById()
- {
- $util = new Util();
- //请求参数构建
- $time = time();
- $appKey = $util->getAppKey();
- $timestamp = $time;
- $scenicId = 1;
- $sign = $util::SingForLvmama($time);
- $url = $util->getBaseUrl() . '/ticketProd/scenicInfoList' . "?appKey=" . $appKey . "&messageFormat=json×tamp=" . $timestamp . "&sign=" . $sign . "&scenicId=" . $scenicId;
- $result = Utils::httpRequest($url);
- print_r($result);
- }
-
- /**
- * Function Description:订单校验接口
- * Function Name: actionValidateOrder
- *
- *
- * @author 娄梦宁
- */
- public function actionValidateOrder()
- {
- $util = new Util();
- //请求参数构建
- $time = time();
- $appKey = $util->getAppKey();
- $timestamp = $time;
- $sign = $util::SingForLvmama($time);
- $order_info = [
- 'request' => [
- 'orderInfo' => [
- 'partnerOrderNo' => 5633325,
- 'orderAmount' => 160,
- 'product' => [
- 'productId' => 434492,
- 'goodsId' => 1646663,
- 'quantity' => 2,
- 'visitDate' => '2017-04-12',
- 'sellPrice' => 80
- ],
- 'booker' => [
- 'name' => '名字',
- 'mobile' => '18616307052',
- 'email' => '326017639@qq.com'
- ],
- 'travellers' => [
- 'traveller' => [
- 'name' => '中文',
- 'enName' => 'TYPE_NUM_NO',
- 'credentialsType' => 'ID_CARD',
- 'credentials' => '430321199212251717',
- 'mobile' => '18616307052',
- ],
- ]
- ]]];
- $order_info = $util::arrayToXml($order_info);
- $url = $util->getBaseUrl() . '/ticket/validateOrder' . "?appKey=" . $appKey . "&messageFormat=Xml×tamp=" . $timestamp . "&sign=" . $sign . "&request=" . $order_info;
- $result = Utils::httpRequest($url);
- $result = $util::xmlToJson($result);
- print_r($url);
- print_r(json_decode($result, true));
- }
-
- /**
- * Function Description:创建订单接口
- * Function Name: actionCreateOrder
- *
- *
- * @author 娄梦宁
- */
- public function actionCreateOrder()
- {
- $util = new Util();
- //请求参数构建
- $time = time();
- $appKey = $util->getAppKey();
- $timestamp = $time;
- $sign = $util::SingForLvmama($time);
- $order_info = [
- 'request' => [
- 'orderInfo' => [
- 'partnerOrderNo' => 812437,
- 'orderAmount' => 20,
- 'product' => [
- 'productId' => 434492,
- 'goodsId' => 1646663,
- 'quantity' => 2,
- 'visitDate' => '2017-04-14',
- 'sellPrice' => 80
- ],
- 'booker' => [
- 'name' => '名字',
- 'mobile' => '18616307052',
- 'email' => '326017639@qq.com'
- ],
- 'travellers' => [
- 'traveller' => [
- 'name' => '中文',
- 'enName' => 'TYPE_NUM_NO',
- 'credentialsType' => 'ID_CARD',
- 'credentials' => '430321199212251717',
- 'mobile' => '18616307052',
- 'email' => '326017639@qq.com'
- ],
- ]
- ]]];
- $order_info = $util::arrayToXml($order_info);
- $url = $util->getBaseUrl() . '/ticket/createOrder' . "?appKey=" . $appKey . "&messageFormat=Xml×tamp=" . $timestamp . "&sign=" . $sign . "&request=" . $order_info;
- $result = Utils::httpRequest($url);
- $result = $util::xmlToJson($result);
- print_r($url);
- print_r(json_decode($result, true));
- }
-
- /**
- * Function Description:订单支付接口
- * Function Name: actionOrderPayment
- *
- *
- * @author 娄梦宁
- */
- public function actionOrderPayment()
- {
- $util = new Util();
- //请求参数构建
- $time = time();
- $appKey = $util->getAppKey();
- $timestamp = $time;
- $sign = $util::SingForLvmama($time);
- $order = [
- 'request' => [
- 'order' => [
- 'partnerOrderNo' => 633333,
- 'orderId' => 20060214,
- 'serialNum' => 111111111111111111
- ]
- ]
- ];
- $order = $util::arrayToXml($order);
- $url = $util->getBaseUrl() . '/order/orderPayment' . "?appKey=" . $appKey . "&messageFormat=Xml×tamp=" . $timestamp . "&sign=" . $sign . "&request=" . $order;
- $result = Utils::httpRequest($url);
- print_r($url);
- print_r($result);
- }
-
- /**
- * Function Description:获取订单详情
- * Function Name: actionGetOrderInfo
- *
- *
- * @author 娄梦宁
- */
- public function actionGetOrderInfo()
- {
- $main_order_id=Yii::$app->request->get('order_id');
- $order_ids=OrderMain::find()->select('order_id')->from(OrderMain::tableName())
- ->where(['parent_order_id'=>$main_order_id])->asArray()->all();
- $tmp_id=[];
- foreach($order_ids as $v){
- $tmp_id[]=$v['order_id'];
- }
- $ids=LvmamaOrderConnect::find()->select('GROUP_CONCAT(partner_id) as ids')->from(LvmamaOrderConnect::tableName())
- ->where(['in','partner_id',$tmp_id])
- ->asArray()->one();
- $util = new Util();
- //请求参数构建
- $time = time();
- $appKey = $util->getAppKey();
- $sign = $util::SingForLvmama($time);
- $order = [
- 'request' => [
- 'order' => [
- 'partnerOrderNos' => $ids['ids']
- ]
- ]
- ];
- $order = $util::arrayToXmlForLvmama($order);
- $get_data=array(
- "appKey" =>$appKey,
- 'messageFormat'=>'Xml',
- 'timestamp'=>$time,
- 'sign'=>$sign,
- 'request'=>$order,
- );
- $url_param = http_build_query($get_data);
- $result=file_get_contents( util::getBaseUrl(). 'order/getOrderInfo?'.$url_param);
- // $url = $util->getBaseUrl() . '/order/getOrderInfo' . "?appKey=" . $appKey . "&messageFormat=Xml×tamp=" . $timestamp . "&sign=" . $sign . "&request=" . $order;
- // $result = Utils::httpRequest($url);
- $result=$util::xmlToArray($result);
- var_dump($result);
- }
-
- /**
- * Function Description:申请退款接口
- * Function Name: actionOrderCancel
- *
- *
- * @author 娄梦宁
- */
- public function actionOrderCancel()
- {
- $util = new Util();
- //请求参数构建
- $time = time();
- $appKey = $util->getAppKey();
- $timestamp = $time;
- $sign = $util::SingForLvmama($time);
- $PartnerOrderNo = 812499;
- $orderId = 20060329;
- $url = $util->getBaseUrl() . '/ticket/orderCancel' . "?appKey=" . $appKey . "&messageFormat=json×tamp=" . $timestamp . "&sign=" . $sign . "&PartnerOrderNo=" . $PartnerOrderNo . "&orderId=" . $orderId;
- $result = Utils::httpRequest($url);
- $result = json_decode($result, true);
- print_r($url);
- print_r($result);
- if ($result['state']['code'] == '1000') {
- if ($result['order']['requestStatus'] == 'PASS') {
- return '已退款';
- } elseif ($result['order']['requestStatus'] == 'REVIEWING') {
- return '审核中';
- } else {
- return '申请驳回 ' . $result['order']['refundInfo'];
- }
- }
- return false;
- }
-
- /**
- * Function Description:退款推送接口
- * Function Name: actionPushOrderCancel
- *
- * @return string
- *
- * @author 娄梦宁
- */
- public function actionPushOrderCancel()
- {
- $util = new Util();
- $lvmama_push_info = new LvmamaPushInfo();
- $order = Yii::$app->request->post('order', '');
- $order = Util::xmlToJson($order);
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '退款推送接口 ' . $order . PHP_EOL, FILE_APPEND);
- $lvmama_push_info->istPush('退款推送接口', $order);
- $order = json_decode($order, true);
- $order_id = $order['body']['order']['orderId'];
- $secret = $util::getSecret();
- if (md5($secret . $order_id) == $order['header']['signed']) {
- if ($order) {
- if($order['requestStatus'] =='REJECT'){//申请已驳回,发送短信通知
- $content="预警:驴妈妈后台直连取消门票失败,订单号({$order['partnerOrderID']}),请及时处理。";
- $phone_arr=[
- '18367152515',
- '18667946782',
- '13872284051',
- // '18874559393',
- ];
- foreach($phone_arr as $phone){
- $send_result=Msg::sendTelMsg($phone,$content);
- if($send_result !==0){
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '退款推送接口 短信发送失败 ' . $order .' '.$send_result. PHP_EOL, FILE_APPEND);
- }
- }
- }
- $result = [
- 'response' => [
- 'state' => [
- 'code' => 1000,
- 'message' => '接收成功'
- ]
- ]
- ];
- return '<?xml version="1.0" encoding="utf-8"?>' . Util::arrayToXml($result);
- }
- }
- $result = [
- 'response' => [
- 'state' => [
- 'code' => 25,
- 'message' => '签名错误'
- ]
- ]
- ];
- return '<?xml version="1.0" encoding="utf-8"?>' . Util::arrayToXml($result);
- }
-
- /**
- * Function Description:接收产品推送接口
- * Function Name: actionPushProductChange
- *
- * @return string
- *
- * @author 娄梦宁
- */
- public function actionPushProductChange()
- {
- $result = [
- 'response' => [
- 'state' => [
- 'code' => 1000,
- 'message' => '接收成功'
- ]
- ]
- ];
- return '<?xml version="1.0" encoding="utf-8"?>' . Util::arrayToXml($result);
- $lvmama_push_info = new LvmamaPushInfo();
- $product = Yii::$app->request->post('product', '');
- $product = Util::xmlToJson($product);
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '产品变更接收推送接口 ' . $product . PHP_EOL, FILE_APPEND);
- $lvmama_push_info->istPush('产品推送接口', $product);
- $product = json_decode($product, true);
- $secret = Util::getSecret();
- $changeType = $product['body']['changeType'];
- if (md5($secret . $changeType) != $product['header']['signed']) {
- $result = [
- 'response' => [
- 'state' => [
- 'code' => 25,
- 'message' => '签名错误'
- ]
- ]
- ];
- return '<?xml version="1.0" encoding="utf-8"?>' . Util::arrayToXml($result);
- }
- if ($changeType == 'price_change') {//价格日历变更时处理
- $prod=$product['body']['product'];
- if(isset($prod['productId'])){
- $this->GetGoodPriceList($prod['goodsId']);
- }else{
- foreach($prod as $val){
- $this->GetGoodPriceList($val['goodsId']);
- }
- }
- } elseif ($changeType == 'product_create') {//新增产品
- $this->AddNewProd($product['body']['product']['productId']);
- }
- $result = [
- 'response' => [
- 'state' => [
- 'code' => 1000,
- 'message' => '接收成功'
- ]
- ]
- ];
- return '<?xml version="1.0" encoding="utf-8"?>' . Util::arrayToXml($result);
- }
-
- /**
- * Function Description:新增产品时操作
- * Function Name: AddNewProd
- * @param $prod_id
- *
- * @return bool
- *
- * @author 娄梦宁
- */
- public function AddNewProd($prod_id)
- {
- //添加主产品
- $util = new Util();
- $opera_prod = new OperaProduct();
- $prod_info = $this->GetProdById($prod_id);
- try {
- $prod_name = $util::doCdada($prod_info['productList'][0]['productName']);
- $remark = $util::doCdada($prod_info['productList'][0]['introdution']);
- } catch (Exception $e) {
- return false;
- }
- $main_prod_id = $opera_prod->istLvmamaProdMain($prod_id, $prod_name, $remark);
- if ($main_prod_id['code'] != 0) {
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . $main_prod_id['msg'] . $prod_id . " 添加单个主门票产品出错" . PHP_EOL, FILE_APPEND);
- }
- return true;
- }
-
- /**
- * Function Description:重发凭证接口
- * Function Name: actionResendCode
- *
- *
- * @author 娄梦宁
- */
- public function actionResendCode()
- {
- $util = new Util();
- //请求参数构建
- $time = time();
- $appKey = $util->getAppKey();
- $timestamp = $time;
- $sign = $util::SingForLvmama($time);
- $request = [
- 'request' => [
- 'order' => [
- 'partnerOrderNos' => 633333,
- 'orderId' => 20060214
- ]
- ]
- ];
- $request = $util::arrayToXml($request);
- $url = $util->getBaseUrl() . '/order/resendCode' . "?appKey=" . $appKey . "&messageFormat=xml×tamp=" . $timestamp . "&sign=" . $sign . "&request=" . $request;
- $result = Utils::httpRequest($url);
- print_r($url);
- print_r($result);
- }
-
- /**
- * Function Description:订单信息推送接口
- * Function Name: actionPushOrderInfo
- *
- * @return string
- *
- * @author 娄梦宁
- */
- public function actionPushOrderInfo()
- {
- $util = new Util();
- $lvmama_push_info = new LvmamaPushInfo();
- $order_refund_lvmama = new OrderRefundLvmama();
- $order = Yii::$app->request->post('order', '');
- $order = Util::xmlToJson($order);
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '订单信息推送接收的json ' . $order . PHP_EOL, FILE_APPEND);
- // $order='{"header":{"signed":"dc0914aed23133d528ae4cd2779d484a"},"body":{"order":{"orderId":"20060214","status":"CANCEL","approveStatus":"true","paymentStatus":"PAYED","credenctStatus":"CREDENCE_SEND","waitPayment":{},"performStatus":"USED","credentials":"CREDENCE_SEND"}}}';
- $lvmama_push_info->istPush('订单信息推送接口', $order);
- $order = json_decode($order, true);
- $order_id = $order['body']['order']['orderId'];
- $secret = $util::getSecret();
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '订单信息推送接收的json ' . $order_id . PHP_EOL, FILE_APPEND);
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '订单信息推送接收的json ' . md5($secret . $order_id) . PHP_EOL, FILE_APPEND);
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '订单信息推送接收的json ' . $order['header']['signed'] . PHP_EOL, FILE_APPEND);
-
-
-
- if (md5($secret . $order_id) == $order['header']['signed']) {
- if ($order['body']['order']['status'] == 'CANCEL' || $order['body']['order']['status'] == 'REFUND') {//订单信息推送操作
- $status = $order['body']['order']['status'];
- $approve_status = $order['body']['order']['approveStatus'] == true ? 1 : 0;
- $payment_status = $order['body']['order']['paymentStatus'] == 'PAYED' ? 1 : 0;
- $istRefund = $order_refund_lvmama->istRefund($order_id, $status, $approve_status, $payment_status);
- if ($istRefund == false) {
- file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '订单信息推送录入数据库失败 ' . $order_id . PHP_EOL, FILE_APPEND);
- }
- }
- $result = [
- 'response' => [
- 'state' => [
- 'code' => 1000,
- 'message' => '接收成功'
- ]
- ]
- ];
- } else {
- $result = [
- 'response' => [
- 'state' => [
- 'code' => 25,
- 'message' => '签名错误'
- ]
- ]
- ];
- }
- return '<?xml version="1.0" encoding="utf-8"?>' . Util::arrayToXml($result);
- }
-
- public function actionTest1(){
-
-
- // $time=time();
- //// $url="http://api.lvmama.com/distributorApi/2.0/api//ticket/createOrder?appKey=ZHIZHUCHUXING&messageFormat=Xml×tamp=1510279231&sign=eb2c9be41fc8b923d1e81a6f7594f68a&request=<request><orderInfo><partnerOrderNo>1803444</partnerOrderNo><orderAmount>453</orderAmount><product><productId>622407</productId><goodsId>3081796</goodsId><quantity>1</quantity><visitDate>2017-11-11</visitDate><sellPrice>453.00</sellPrice></product><booker><name>陈梦云</name><mobile>18951971757</mobile></booker><travellers><traveller><name>陈梦云</name><credentialsType>ID_CARD</credentialsType><credentials>46010319920707034X</credentials><mobile>18951971757</mobile></traveller></travellers></orderInfo></request>";
- // $sign=Util::SingForLvmama($time);
- // ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; GreenBrowser)');
- // $url='http://api.lvmama.com/distributorApi/2.0/api/ticket/createOrder?appKey=ZHIZHUCHUXING&messageFormat=Xml×tamp=1510292787&sign=6a9c59bb3b273b7e3b41e7baa23a003b&request=<request><orderInfo><partnerOrderNo>1804849</partnerOrderNo><orderAmount>453</orderAmount><product><productId>622407</productId><goodsId>3081796</goodsId><quantity>1</quantity><visitDate>2017-11-11</visitDate><sellPrice>453.00</sellPrice></product><booker><name>丁倩</name><mobile>13815403234</mobile></booker><travellers><traveller><name>丁倩</name><credentialsType>ID_CARD</credentialsType><credentials>330903199209090226</credentials><mobile>13815403234</mobile></traveller></travellers></orderInfo></request>';
- // $result=file_get_contents($url);
- // // $result=Util::OrderPayment(56614790,1803444,'56614790'.'1803444_'.time());
- // print_r($result);
- $result=Util::OrderPayment(1804849,56626116,'1804849'.'56626116_'.time());
- print_r($result);
- }
-
- }
|