Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

942 linhas
43 KiB

  1. <?php
  2. /**
  3. * Function Description:驴妈妈对应的接口
  4. * Function Name: ApiForLvmama
  5. * @return ${TYPE_HINT}
  6. * ${THROWS_DOC}
  7. *
  8. * @author 娄梦宁
  9. */
  10. namespace backend\modules\api\controllers;
  11. use backend\modules\api\models\LvmamaOrderConnect;
  12. use backend\modules\api\models\LvmamaPushInfo;
  13. use backend\modules\api\models\OperaProduct;
  14. use backend\modules\api\models\OrderMain;
  15. use backend\modules\api\models\OrderRefundLvmama;
  16. use backend\modules\api\models\OutsideTicket;
  17. use backend\modules\api\util\Util;
  18. use common\models\Msg;
  19. use common\models\Utils;
  20. use yii\base\Exception;
  21. use yii\web\Controller;
  22. use Yii;
  23. class LvmamaController extends Controller
  24. {
  25. public $enableCsrfValidation = false;
  26. public function actionIndex()
  27. {
  28. return 'HELLO';
  29. }
  30. /**
  31. * Function Description:获取 批量景区基本信息接口(暂无相关数据处理)
  32. * Function Name: actionGetScenicList
  33. *
  34. *
  35. * @author 娄梦宁
  36. */
  37. public function actionGetScenicList()
  38. {
  39. $util = new Util();
  40. //请求参数构建
  41. $time = time();
  42. $appKey = $util->getAppKey();
  43. $timestamp = $time;
  44. $sign = $util::SingForLvmama($time);
  45. $currentPage = 1;
  46. $url = $util->getBaseUrl() . '/ticketProd/scenicInfoListByPage' . "?appKey=" . $appKey . "&messageFormat=json&timestamp=" . $timestamp . "&sign=" . $sign . "&currentPage=" . $currentPage;
  47. $result = Utils::httpRequest($url);
  48. print_r($url);
  49. print_r(json_decode($result, true));
  50. }
  51. /**
  52. * Function Description:批量产品/商品信息接口
  53. * Function Name: actionGetProdList
  54. *
  55. *
  56. * @author 娄梦宁
  57. */
  58. public function actionGetProdList()
  59. {
  60. set_time_limit(0);
  61. $util = new Util();
  62. $opera_prod = new OperaProduct();
  63. $outside_ticket = new OutsideTicket();
  64. //请求参数构建
  65. $time = time();
  66. $appKey = $util->getAppKey();
  67. $timestamp = $time;
  68. $sign = $util::SingForLvmama($time);
  69. $currentPage = 1;
  70. $url = $util->getBaseUrl() . '/ticketProd/productInfoListByPage' . "?appKey=" . $appKey . "&messageFormat=json&timestamp=" . $timestamp . "&sign=" . $sign . "&currentPage=" . $currentPage;
  71. $result = Utils::httpRequest($url);
  72. $prod_list = json_decode($result, true);
  73. //查出opera_prod表中所有的主code(即驴妈妈的productId)
  74. $code_arr = $opera_prod->getCodeArr();
  75. $code_arr_son=$opera_prod->getCodeArrSon();
  76. for ($currentPage = 1; $currentPage <= $prod_list['totalPage']; $currentPage++) {
  77. if ($currentPage == 1) {//分页的循环
  78. $tmp_arr = $prod_list;
  79. } else {
  80. $url = $util->getBaseUrl() . '/ticketProd/productInfoListByPage' . "?appKey=" . $appKey . "&messageFormat=json&timestamp=" . $timestamp . "&sign=" . $sign . "&currentPage=" . $currentPage;
  81. $result = Utils::httpRequest($url);
  82. $tmp_arr = json_decode($result, true);
  83. }
  84. foreach ($tmp_arr['productList'] as $val) {
  85. //如果产品在opera_prod表中,即产品信息已添加
  86. if (array_key_exists($val['productId'], $code_arr)) {//产品已经存在
  87. if ($val['productStatus'] == true) {//当前产品在驴妈妈上架
  88. $tmp_prod_name = $util::doCdada($val['productName']);
  89. $remark = '';
  90. if (isset($val['bookingInfo'])) {
  91. foreach ($val['bookingInfo'] as $book) {
  92. $remark .= $util::doCdada($book);
  93. }
  94. }
  95. $remark .= $util::doCdada($val['goodsList'][0]['importentPoint']);
  96. $is_refund = $val['goodsList'][0]['rules'][0]['isChange'];
  97. $refund_limit_day = 1;
  98. $refund_limit_time = '23:00';
  99. if ($is_refund == 1 && isset($val['goodsList'][0]['rules'][0]['aheadTime'])) {//可以退款就同步退款规则
  100. $limit_day_time = $util::countRefundTime($val['goodsList'][0]['rules'][0]['aheadTime']);
  101. $refund_limit_day = $limit_day_time['day'];
  102. $refund_limit_time = $limit_day_time['time'];
  103. }
  104. $tmp_prod_code = $val['productId'];
  105. //
  106. $upt_main = $opera_prod->uptLvmamaProdDetail($tmp_prod_code, $tmp_prod_name, $remark, $refund_limit_day, $refund_limit_time, $is_refund);
  107. $parent_id = $code_arr[$val['productId']]['prod_id'];
  108. // }else{
  109. // $upt_main=$opera_prod->istLvmamaProdMain($tmp_prod_code, $tmp_prod_name, $remark, $refund_limit_day, $refund_limit_time, $is_refund);
  110. // $parent_id=$upt_main['prod_id'];
  111. // }
  112. if ($upt_main['code'] != 0) {
  113. 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);
  114. continue;
  115. }
  116. foreach ($val['goodsList'] as $goods) {//循环添加子产品
  117. if ($goods['status'] == true) {
  118. $prod_name_son = $util::doCdada($goods['goodsName']);
  119. $prod_code_son = $goods['goodsId'];
  120. if (array_key_exists($prod_code_son, $code_arr_son)) {//商品已经存在
  121. $son_prod = $opera_prod->uptLvmamaProdSon($prod_code_son, $prod_name_son, $remark, $refund_limit_day, $refund_limit_time, $is_refund, $parent_id);
  122. } else {
  123. $son_prod = $opera_prod->insLvmamaProdSon($parent_id, $prod_name_son, $prod_code_son, $refund_limit_day, $refund_limit_time, $is_refund);
  124. }
  125. if ($son_prod['code'] != 0) {
  126. 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);
  127. continue;
  128. }
  129. } else {//商品下架
  130. $outside_ticket->cancelGoods($val['productId'], $goods['goodsId']);
  131. }
  132. }
  133. } else {//产品下架
  134. $opera_prod->cancelProductByCode($val['productId']);
  135. }
  136. }
  137. }
  138. }
  139. }
  140. /**
  141. * Function Description:批量价格、库存信息
  142. * Function Name: actionGetProdPriceList
  143. *
  144. *
  145. * @author 娄梦宁
  146. */
  147. public function actionGetProdPriceList()
  148. {
  149. set_time_limit(0);
  150. $util = new Util();
  151. $opera_prod = new OperaProduct();
  152. $outside_ticket = new OutsideTicket();
  153. //请求参数构建
  154. $time = time();
  155. $appKey = $util->getAppKey();
  156. $timestamp = $time;
  157. $sign = $util::SingForLvmama($time);
  158. $currentPage = 1;
  159. $beginDate = date('Y-m-d');
  160. $endDate = date('Y-m-d', strtotime('+ 30 day'));
  161. $url = $util->getBaseUrl() . '/ticketProd/productPriceListByPage' . "?appKey=" . $appKey . "&messageFormat=json&timestamp=" . $timestamp . "&sign=" . $sign .
  162. "&currentPage=" . $currentPage . "&beginDate=" . $beginDate . "&endDate=" . $endDate;
  163. $prod_list = Utils::httpRequest($url);
  164. //查出opera_prod表中所有的code(即驴妈妈的productId)
  165. $code_arr = $opera_prod->getCodeArr();
  166. //循环所有页数,每次结果插入opera_ticket
  167. $prod_list = json_decode($prod_list, true);
  168. for ($currentPage = 1; $currentPage <= $prod_list['totalPage']; $currentPage++) {
  169. if ($currentPage == 1) {
  170. $tmp_arr = $prod_list;
  171. } else {
  172. $url = $util->getBaseUrl() . '/ticketProd/productPriceListByPage' . "?appKey=" . $appKey . "&messageFormat=json&timestamp=" . $timestamp . "&sign=" . $sign .
  173. "&currentPage=" . $currentPage . "&beginDate=" . $beginDate . "&endDate=" . $endDate;
  174. $tmp_arr = Utils::httpRequest($url);
  175. $tmp_arr = json_decode($tmp_arr, true);
  176. }
  177. foreach ($tmp_arr['priceList'] as $val) {
  178. //////////////////这层逻辑先不管
  179. // if (array_key_exists($val['productId'], $code_arr)) {//如果产品在opera_prod表中,即在售
  180. // }
  181. // else {//加一层逻辑,获取到的产品都加到opera_prod表中,(前提是驴妈妈接口反馈都是有效数据)
  182. // //添加主产品
  183. // $prod_id = $val['productId'];
  184. // $prod_info = $this->GetProdById($prod_id);
  185. // try {
  186. // $prod_name = $util::doCdada($prod_info['productList'][0]['productName']);
  187. // //$remark = $util::doCdada($prod_info['productList'][0]['introdution']);暂不需要简介
  188. // $remark = '';
  189. // foreach ($prod_info['productList'][0]['bookinginfo'] as $book) {
  190. // $remark .= $util::doCdada($book);
  191. // }
  192. // } catch (Exception $e) {
  193. // file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . $prod_id . " 添加产品获取详情出错" . PHP_EOL, FILE_APPEND);
  194. // continue;
  195. // }
  196. // $main_prod_id = $opera_prod->istLvmamaProdMain($prod_id, $prod_name, $remark);
  197. // if ($main_prod_id['code'] != 0) {
  198. // 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);
  199. // continue;
  200. // }
  201. // foreach ($val['goodsList']['goods'] as $goods) {//循环添加子产品
  202. // $parent_id_son = $main_prod_id['prod_id'];
  203. // $prod_name_son = $util::doCdada($goods['goodsName']);
  204. // $prod_code_son = $goods['goodsId'];
  205. // $son_prod = $opera_prod->insLvmamaProdSon($parent_id_son, $prod_name_son, $prod_code_son);
  206. // if ($son_prod['code'] != 0) {
  207. // 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);
  208. // continue;
  209. // }
  210. // }
  211. // $code_arr = $opera_prod->getCodeArr();
  212. // }
  213. if ($val['productStatus'] == true) {//产品上线中
  214. foreach ($val['goodsList']['goods'] as $v) {//循环prod下的商品,
  215. if ($v['goodsOnLine'] == true) {//商品上线中
  216. if (!empty($v['prices'])) {
  217. foreach ($v['prices']['price'] as $value) {//循环不同的价格日历
  218. $tmp_prod_code = $val['productId'];
  219. $tmp_prod_name = $code_arr[$tmp_prod_code]['prod_name'];
  220. $tmp_ticket_code = $v['goodsId'];
  221. $tmp_ticket_date = $value['date'];
  222. $tmp_ticket_name = $util::doCdada($v['goodsName']);
  223. $tmp_ticket_num = $value['stock'] == -1 ? 9999 : $value['stock'];
  224. $tmp_ticket_price = $value['b2bPrice'];
  225. $tmp_agent_price = $value['sellPrice'];
  226. $tmp_cs_prod_id = $code_arr[$tmp_prod_code]['prod_id'];
  227. $tmp_insert = $outside_ticket->InsertData($tmp_prod_code, $tmp_prod_name, $tmp_ticket_code, $tmp_ticket_date, $tmp_ticket_name,
  228. $tmp_ticket_num, $tmp_ticket_price, $tmp_agent_price, $tmp_cs_prod_id);
  229. if (!$tmp_insert) {
  230. 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
  231. . "批量接口插入更新失败" . PHP_EOL, FILE_APPEND);
  232. }
  233. }
  234. }
  235. } else {//商品已下线
  236. $outside_ticket->cancelGoods($val['productId'], $v['goodsId']);
  237. }
  238. }
  239. } else {//产品已下线
  240. $opera_prod->cancelProductByCode($val['productId']);
  241. }
  242. }
  243. }
  244. }
  245. /**
  246. * Function Description:通过id获取产品信息
  247. * Function Name: actionGetProdById
  248. *
  249. *
  250. * @author 娄梦宁
  251. */
  252. public function GetProdById($productIds)
  253. {
  254. $util = new Util();
  255. //请求参数构建
  256. $time = time();
  257. $appKey = $util->getAppKey();
  258. $timestamp = $time;
  259. $sign = $util::SingForLvmama($time);
  260. $url = $util->getBaseUrl() . '/ticketProd/productInfoList' . "?appKey=" . $appKey . "&messageFormat=json&timestamp=" . $timestamp . "&sign=" . $sign . "&productIds=" . $productIds;
  261. $result = Utils::httpRequest($url);
  262. return json_decode($result, true);
  263. }
  264. /**
  265. * Function Description:定时任务通过id同步产品信息
  266. * Function Name: actionGetProdById
  267. *
  268. *
  269. * @author 娄梦宁
  270. */
  271. public function actionUptProdById()
  272. {
  273. set_time_limit(0);
  274. $opera_prod = new OperaProduct();
  275. $util = new Util();
  276. //获取驴妈妈渠道下所有产品id
  277. $prod_arr = $opera_prod->getIdForLvmama();
  278. foreach ($prod_arr as $val) {//循环处理各产品
  279. if ($val['productStatus'] == true) {//产品在驴妈妈上架
  280. $prod_info = $this->GetProdById($val['prod_code']);
  281. try {
  282. $prod_name = $util::doCdada($prod_info['productList'][0]['productName']);
  283. $remark = '';
  284. foreach ($prod_info['productList'][0]['bookingInfo'] as $book) {
  285. $remark .= $util::doCdada($book);
  286. }
  287. } catch (Exception $e) {
  288. 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);
  289. continue;
  290. }
  291. $main_prod_id = $opera_prod->uptLvmamaProdMain($val['prod_code'], $prod_name, $remark);
  292. if ($main_prod_id['code'] != 0) {
  293. 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);
  294. continue;
  295. }
  296. }
  297. // else {//产品在驴妈妈下架
  298. // $opera_prod->cancelProductByCode($val['productId']);
  299. // }
  300. }
  301. }
  302. /**
  303. * Function Description:通过id获取商品信息
  304. * Function Name: actionGetGoodById
  305. *
  306. *
  307. * @author 娄梦宁
  308. */
  309. public function GetGoodById($goodsIds)
  310. {
  311. $util = new Util();
  312. //请求参数构建
  313. $time = time();
  314. $appKey = $util->getAppKey();
  315. $timestamp = $time;
  316. $sign = $util::SingForLvmama($time);
  317. $url = $util->getBaseUrl() . '/ticketProd/goodInfoList' . "?appKey=" . $appKey . "&messageFormat=json&timestamp=" . $timestamp . "&sign=" . $sign . "&goodsIds=" . $goodsIds;
  318. $result = Utils::httpRequest($url);
  319. return json_decode($result, true);
  320. }
  321. public function actionTest(){
  322. $util = new Util();
  323. //请求参数构建
  324. $time = time();
  325. $appKey = $util->getAppKey();
  326. $timestamp = $time;
  327. $beginDate = date('Y-m-d');
  328. $endDate = date('Y-m-d', strtotime('+ 60 day'));
  329. $sign = $util::SingForLvmama($time);
  330. $url = $util->getBaseUrl() . '/ticketProd/productInfoList' . "?appKey=" . $appKey . "&messageFormat=json&timestamp=" . $timestamp . "&sign=" . $sign . "&productIds=" . 1040730;
  331. // $url = $util->getBaseUrl() . '/ticketProd/goodInfoList' . "?appKey=" . $appKey . "&messageFormat=json&timestamp=" . $timestamp . "&sign=" . $sign . "&goodsIds=" . 934395;
  332. $url = $util->getBaseUrl() . '/ticketProd/goodPriceList' . "?appKey=" . $appKey . "&messageFormat=json&timestamp=" . $timestamp . "&sign=" . $sign . "&goodsIds=" . 9992857 . "&beginDate=" . $beginDate . "&endDate=" . $endDate;
  333. $result = Utils::httpRequest($url);
  334. print_r(json_decode($result, true));
  335. }
  336. /**
  337. * Function Description:定时任务通过id同步商品信息
  338. * Function Name: actionGetProdById
  339. *
  340. *
  341. * @author 娄梦宁
  342. */
  343. public function actionUptGoodById()
  344. {
  345. set_time_limit(0);
  346. $opera_prod = new OperaProduct();
  347. $outside_ticket = new OutsideTicket();
  348. $util = new Util();
  349. //获取驴妈妈渠道下所有子产品code
  350. $prod_arr = $opera_prod->getSonIdForLvmama();
  351. foreach ($prod_arr as $val) {
  352. $prod_info = $this->GetGoodById($val['prod_code']);
  353. if ($prod_info['goodsList'][0]['status'] == true) {//商品在驴妈妈上架则更新信息
  354. try {
  355. $prod_name = $util::doCdada($prod_info['goodsList'][0]['goodsName']);
  356. $remark = $util::doCdada($prod_info['goodsList'][0]['importentPoint']);
  357. $is_refund = $prod_info['goodsList'][0]['rules'][0]['isChange'];
  358. $refund_limit_day = 1;
  359. $refund_limit_time = '23:00';
  360. if ($is_refund == 1 && isset($prod_info['goodsList'][0]['rules'][0]['aheadTime'])) {//可以退款就同步退款规则
  361. $limit_day_time = $util::countRefundTime($prod_info['goodsList'][0]['rules'][0]['aheadTime']);
  362. $refund_limit_day = $limit_day_time['day'];
  363. $refund_limit_time = $limit_day_time['time'];
  364. }
  365. } catch (Exception $e) {
  366. 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);
  367. continue;
  368. }
  369. $main_prod_id = $opera_prod->uptLvmamaProdSon($val['prod_code'], $prod_name, $remark, $refund_limit_day, $refund_limit_time, $is_refund);
  370. if ($main_prod_id['code'] != 0) {
  371. 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);
  372. continue;
  373. }
  374. //同步两天后价格日历信息
  375. $this->GetGoodPriceList($val['prod_code']);
  376. } else {//商品在驴妈妈下架
  377. $outside_ticket->cancelGoods($val['productId'], $val['goodsId']);
  378. }
  379. }
  380. }
  381. /**
  382. * Function Description:按 ID 获取价格库存接口
  383. * Function Name: GetGoodPriceList
  384. * @param $goodsIds
  385. *
  386. *
  387. * @author 娄梦宁
  388. */
  389. public function GetGoodPriceList($goodsIds)
  390. {
  391. $util = new Util();
  392. $outside_ticket = new OutsideTicket();
  393. $opera_prod = new OperaProduct();
  394. //请求参数构建
  395. $time = time();
  396. $appKey = $util->getAppKey();
  397. $timestamp = $time;
  398. $beginDate = date('Y-m-d');
  399. $endDate = date('Y-m-d', strtotime('+ 2 day'));
  400. $sign = $util::SingForLvmama($time);
  401. $url = $util->getBaseUrl() . '/ticketProd/goodPriceList' . "?appKey=" . $appKey . "&messageFormat=json&timestamp=" . $timestamp . "&sign=" . $sign . "&goodsIds=" . $goodsIds . "&beginDate=" . $beginDate . "&endDate=" . $endDate;
  402. $result = Utils::httpRequest($url);
  403. $result = json_decode($result, true);
  404. //查出opera_prod表中所有的code(即驴妈妈的productId)
  405. $code_arr = $opera_prod->getCodeArr();
  406. if ($result['state']['code'] != 1000) {
  407. 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);
  408. }
  409. foreach ($result['priceList'] as $val) {
  410. if ($val['productStatus'] == true) {
  411. foreach ($val['goodsList']['goods'] as $v) {
  412. if ($v['goodsOnLine'] == true) {
  413. if ($v['prices']['price']) {
  414. foreach ($v['prices']['price'] as $value) {
  415. $tmp_prod_code = $val['productId'];
  416. $tmp_prod_name = $code_arr[$tmp_prod_code]['prod_name'];
  417. $tmp_ticket_code = $v['goodsId'];
  418. $tmp_ticket_date = $value['date'];
  419. $tmp_ticket_name = $util::doCdada($v['goodsName']);
  420. $tmp_ticket_num = $value['stock'] == -1 ? 9999 : $value['stock'];
  421. $tmp_ticket_price = $value['b2bPrice'];
  422. $tmp_agent_price = $value['sellPrice'];
  423. $tmp_cs_prod_id = $code_arr[$tmp_prod_code]['prod_id'];
  424. $tmp_insert = $outside_ticket->InsertData($tmp_prod_code, $tmp_prod_name, $tmp_ticket_code, $tmp_ticket_date, $tmp_ticket_name,
  425. $tmp_ticket_num, $tmp_ticket_price, $tmp_agent_price, $tmp_cs_prod_id);
  426. if (!$tmp_insert) {
  427. 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
  428. . "单产品插入更新失败" . PHP_EOL, FILE_APPEND);
  429. }
  430. }
  431. }
  432. } else {//商品下架不在此处理
  433. continue;
  434. }
  435. }
  436. } else {//产品下架不在此处理
  437. continue;
  438. }
  439. }
  440. }
  441. /**
  442. * Function Description:按 ID 获取景区信息接口(不通)
  443. * Function Name: actionGetScenicListById
  444. *
  445. *
  446. * @author 娄梦宁
  447. */
  448. public function actionGetScenicListById()
  449. {
  450. $util = new Util();
  451. //请求参数构建
  452. $time = time();
  453. $appKey = $util->getAppKey();
  454. $timestamp = $time;
  455. $scenicId = 1;
  456. $sign = $util::SingForLvmama($time);
  457. $url = $util->getBaseUrl() . '/ticketProd/scenicInfoList' . "?appKey=" . $appKey . "&messageFormat=json&timestamp=" . $timestamp . "&sign=" . $sign . "&scenicId=" . $scenicId;
  458. $result = Utils::httpRequest($url);
  459. print_r($result);
  460. }
  461. /**
  462. * Function Description:订单校验接口
  463. * Function Name: actionValidateOrder
  464. *
  465. *
  466. * @author 娄梦宁
  467. */
  468. public function actionValidateOrder()
  469. {
  470. $util = new Util();
  471. //请求参数构建
  472. $time = time();
  473. $appKey = $util->getAppKey();
  474. $timestamp = $time;
  475. $sign = $util::SingForLvmama($time);
  476. $order_info = [
  477. 'request' => [
  478. 'orderInfo' => [
  479. 'partnerOrderNo' => 5633325,
  480. 'orderAmount' => 160,
  481. 'product' => [
  482. 'productId' => 434492,
  483. 'goodsId' => 1646663,
  484. 'quantity' => 2,
  485. 'visitDate' => '2017-04-12',
  486. 'sellPrice' => 80
  487. ],
  488. 'booker' => [
  489. 'name' => '名字',
  490. 'mobile' => '18616307052',
  491. 'email' => '326017639@qq.com'
  492. ],
  493. 'travellers' => [
  494. 'traveller' => [
  495. 'name' => '中文',
  496. 'enName' => 'TYPE_NUM_NO',
  497. 'credentialsType' => 'ID_CARD',
  498. 'credentials' => '430321199212251717',
  499. 'mobile' => '18616307052',
  500. ],
  501. ]
  502. ]]];
  503. $order_info = $util::arrayToXml($order_info);
  504. $url = $util->getBaseUrl() . '/ticket/validateOrder' . "?appKey=" . $appKey . "&messageFormat=Xml&timestamp=" . $timestamp . "&sign=" . $sign . "&request=" . $order_info;
  505. $result = Utils::httpRequest($url);
  506. $result = $util::xmlToJson($result);
  507. print_r($url);
  508. print_r(json_decode($result, true));
  509. }
  510. /**
  511. * Function Description:创建订单接口
  512. * Function Name: actionCreateOrder
  513. *
  514. *
  515. * @author 娄梦宁
  516. */
  517. public function actionCreateOrder()
  518. {
  519. $util = new Util();
  520. //请求参数构建
  521. $time = time();
  522. $appKey = $util->getAppKey();
  523. $timestamp = $time;
  524. $sign = $util::SingForLvmama($time);
  525. $order_info = [
  526. 'request' => [
  527. 'orderInfo' => [
  528. 'partnerOrderNo' => 812437,
  529. 'orderAmount' => 20,
  530. 'product' => [
  531. 'productId' => 434492,
  532. 'goodsId' => 1646663,
  533. 'quantity' => 2,
  534. 'visitDate' => '2017-04-14',
  535. 'sellPrice' => 80
  536. ],
  537. 'booker' => [
  538. 'name' => '名字',
  539. 'mobile' => '18616307052',
  540. 'email' => '326017639@qq.com'
  541. ],
  542. 'travellers' => [
  543. 'traveller' => [
  544. 'name' => '中文',
  545. 'enName' => 'TYPE_NUM_NO',
  546. 'credentialsType' => 'ID_CARD',
  547. 'credentials' => '430321199212251717',
  548. 'mobile' => '18616307052',
  549. 'email' => '326017639@qq.com'
  550. ],
  551. ]
  552. ]]];
  553. $order_info = $util::arrayToXml($order_info);
  554. $url = $util->getBaseUrl() . '/ticket/createOrder' . "?appKey=" . $appKey . "&messageFormat=Xml&timestamp=" . $timestamp . "&sign=" . $sign . "&request=" . $order_info;
  555. $result = Utils::httpRequest($url);
  556. $result = $util::xmlToJson($result);
  557. print_r($url);
  558. print_r(json_decode($result, true));
  559. }
  560. /**
  561. * Function Description:订单支付接口
  562. * Function Name: actionOrderPayment
  563. *
  564. *
  565. * @author 娄梦宁
  566. */
  567. public function actionOrderPayment()
  568. {
  569. $util = new Util();
  570. //请求参数构建
  571. $time = time();
  572. $appKey = $util->getAppKey();
  573. $timestamp = $time;
  574. $sign = $util::SingForLvmama($time);
  575. $order = [
  576. 'request' => [
  577. 'order' => [
  578. 'partnerOrderNo' => 633333,
  579. 'orderId' => 20060214,
  580. 'serialNum' => 111111111111111111
  581. ]
  582. ]
  583. ];
  584. $order = $util::arrayToXml($order);
  585. $url = $util->getBaseUrl() . '/order/orderPayment' . "?appKey=" . $appKey . "&messageFormat=Xml&timestamp=" . $timestamp . "&sign=" . $sign . "&request=" . $order;
  586. $result = Utils::httpRequest($url);
  587. print_r($url);
  588. print_r($result);
  589. }
  590. /**
  591. * Function Description:获取订单详情
  592. * Function Name: actionGetOrderInfo
  593. *
  594. *
  595. * @author 娄梦宁
  596. */
  597. public function actionGetOrderInfo()
  598. {
  599. $main_order_id=Yii::$app->request->get('order_id');
  600. $order_ids=OrderMain::find()->select('order_id')->from(OrderMain::tableName())
  601. ->where(['parent_order_id'=>$main_order_id])->asArray()->all();
  602. $tmp_id=[];
  603. foreach($order_ids as $v){
  604. $tmp_id[]=$v['order_id'];
  605. }
  606. $ids=LvmamaOrderConnect::find()->select('GROUP_CONCAT(partner_id) as ids')->from(LvmamaOrderConnect::tableName())
  607. ->where(['in','partner_id',$tmp_id])
  608. ->asArray()->one();
  609. $util = new Util();
  610. //请求参数构建
  611. $time = time();
  612. $appKey = $util->getAppKey();
  613. $sign = $util::SingForLvmama($time);
  614. $order = [
  615. 'request' => [
  616. 'order' => [
  617. 'partnerOrderNos' => $ids['ids']
  618. ]
  619. ]
  620. ];
  621. $order = $util::arrayToXmlForLvmama($order);
  622. $get_data=array(
  623. "appKey" =>$appKey,
  624. 'messageFormat'=>'Xml',
  625. 'timestamp'=>$time,
  626. 'sign'=>$sign,
  627. 'request'=>$order,
  628. );
  629. $url_param = http_build_query($get_data);
  630. $result=file_get_contents( util::getBaseUrl(). 'order/getOrderInfo?'.$url_param);
  631. // $url = $util->getBaseUrl() . '/order/getOrderInfo' . "?appKey=" . $appKey . "&messageFormat=Xml&timestamp=" . $timestamp . "&sign=" . $sign . "&request=" . $order;
  632. // $result = Utils::httpRequest($url);
  633. $result=$util::xmlToArray($result);
  634. var_dump($result);
  635. }
  636. /**
  637. * Function Description:申请退款接口
  638. * Function Name: actionOrderCancel
  639. *
  640. *
  641. * @author 娄梦宁
  642. */
  643. public function actionOrderCancel()
  644. {
  645. $util = new Util();
  646. //请求参数构建
  647. $time = time();
  648. $appKey = $util->getAppKey();
  649. $timestamp = $time;
  650. $sign = $util::SingForLvmama($time);
  651. $PartnerOrderNo = 812499;
  652. $orderId = 20060329;
  653. $url = $util->getBaseUrl() . '/ticket/orderCancel' . "?appKey=" . $appKey . "&messageFormat=json&timestamp=" . $timestamp . "&sign=" . $sign . "&PartnerOrderNo=" . $PartnerOrderNo . "&orderId=" . $orderId;
  654. $result = Utils::httpRequest($url);
  655. $result = json_decode($result, true);
  656. print_r($url);
  657. print_r($result);
  658. if ($result['state']['code'] == '1000') {
  659. if ($result['order']['requestStatus'] == 'PASS') {
  660. return '已退款';
  661. } elseif ($result['order']['requestStatus'] == 'REVIEWING') {
  662. return '审核中';
  663. } else {
  664. return '申请驳回 ' . $result['order']['refundInfo'];
  665. }
  666. }
  667. return false;
  668. }
  669. /**
  670. * Function Description:退款推送接口
  671. * Function Name: actionPushOrderCancel
  672. *
  673. * @return string
  674. *
  675. * @author 娄梦宁
  676. */
  677. public function actionPushOrderCancel()
  678. {
  679. $util = new Util();
  680. $lvmama_push_info = new LvmamaPushInfo();
  681. $order = Yii::$app->request->post('order', '');
  682. $order = Util::xmlToJson($order);
  683. file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '退款推送接口 ' . $order . PHP_EOL, FILE_APPEND);
  684. $lvmama_push_info->istPush('退款推送接口', $order);
  685. $order = json_decode($order, true);
  686. $order_id = $order['body']['order']['orderId'];
  687. $secret = $util::getSecret();
  688. if (md5($secret . $order_id) == $order['header']['signed']) {
  689. if ($order) {
  690. if($order['requestStatus'] =='REJECT'){//申请已驳回,发送短信通知
  691. $content="预警:驴妈妈后台直连取消门票失败,订单号({$order['partnerOrderID']}),请及时处理。";
  692. $phone_arr=[
  693. '18367152515',
  694. '18667946782',
  695. '13872284051',
  696. // '18874559393',
  697. ];
  698. foreach($phone_arr as $phone){
  699. $send_result=Msg::sendTelMsg($phone,$content);
  700. if($send_result !==0){
  701. 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);
  702. }
  703. }
  704. }
  705. $result = [
  706. 'response' => [
  707. 'state' => [
  708. 'code' => 1000,
  709. 'message' => '接收成功'
  710. ]
  711. ]
  712. ];
  713. return '<?xml version="1.0" encoding="utf-8"?>' . Util::arrayToXml($result);
  714. }
  715. }
  716. $result = [
  717. 'response' => [
  718. 'state' => [
  719. 'code' => 25,
  720. 'message' => '签名错误'
  721. ]
  722. ]
  723. ];
  724. return '<?xml version="1.0" encoding="utf-8"?>' . Util::arrayToXml($result);
  725. }
  726. /**
  727. * Function Description:接收产品推送接口
  728. * Function Name: actionPushProductChange
  729. *
  730. * @return string
  731. *
  732. * @author 娄梦宁
  733. */
  734. public function actionPushProductChange()
  735. {
  736. $result = [
  737. 'response' => [
  738. 'state' => [
  739. 'code' => 1000,
  740. 'message' => '接收成功'
  741. ]
  742. ]
  743. ];
  744. return '<?xml version="1.0" encoding="utf-8"?>' . Util::arrayToXml($result);
  745. $lvmama_push_info = new LvmamaPushInfo();
  746. $product = Yii::$app->request->post('product', '');
  747. $product = Util::xmlToJson($product);
  748. file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '产品变更接收推送接口 ' . $product . PHP_EOL, FILE_APPEND);
  749. $lvmama_push_info->istPush('产品推送接口', $product);
  750. $product = json_decode($product, true);
  751. $secret = Util::getSecret();
  752. $changeType = $product['body']['changeType'];
  753. if (md5($secret . $changeType) != $product['header']['signed']) {
  754. $result = [
  755. 'response' => [
  756. 'state' => [
  757. 'code' => 25,
  758. 'message' => '签名错误'
  759. ]
  760. ]
  761. ];
  762. return '<?xml version="1.0" encoding="utf-8"?>' . Util::arrayToXml($result);
  763. }
  764. if ($changeType == 'price_change') {//价格日历变更时处理
  765. $prod=$product['body']['product'];
  766. if(isset($prod['productId'])){
  767. $this->GetGoodPriceList($prod['goodsId']);
  768. }else{
  769. foreach($prod as $val){
  770. $this->GetGoodPriceList($val['goodsId']);
  771. }
  772. }
  773. } elseif ($changeType == 'product_create') {//新增产品
  774. $this->AddNewProd($product['body']['product']['productId']);
  775. }
  776. $result = [
  777. 'response' => [
  778. 'state' => [
  779. 'code' => 1000,
  780. 'message' => '接收成功'
  781. ]
  782. ]
  783. ];
  784. return '<?xml version="1.0" encoding="utf-8"?>' . Util::arrayToXml($result);
  785. }
  786. /**
  787. * Function Description:新增产品时操作
  788. * Function Name: AddNewProd
  789. * @param $prod_id
  790. *
  791. * @return bool
  792. *
  793. * @author 娄梦宁
  794. */
  795. public function AddNewProd($prod_id)
  796. {
  797. //添加主产品
  798. $util = new Util();
  799. $opera_prod = new OperaProduct();
  800. $prod_info = $this->GetProdById($prod_id);
  801. try {
  802. $prod_name = $util::doCdada($prod_info['productList'][0]['productName']);
  803. $remark = $util::doCdada($prod_info['productList'][0]['introdution']);
  804. } catch (Exception $e) {
  805. return false;
  806. }
  807. $main_prod_id = $opera_prod->istLvmamaProdMain($prod_id, $prod_name, $remark);
  808. if ($main_prod_id['code'] != 0) {
  809. 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);
  810. }
  811. return true;
  812. }
  813. /**
  814. * Function Description:重发凭证接口
  815. * Function Name: actionResendCode
  816. *
  817. *
  818. * @author 娄梦宁
  819. */
  820. public function actionResendCode()
  821. {
  822. $util = new Util();
  823. //请求参数构建
  824. $time = time();
  825. $appKey = $util->getAppKey();
  826. $timestamp = $time;
  827. $sign = $util::SingForLvmama($time);
  828. $request = [
  829. 'request' => [
  830. 'order' => [
  831. 'partnerOrderNos' => 633333,
  832. 'orderId' => 20060214
  833. ]
  834. ]
  835. ];
  836. $request = $util::arrayToXml($request);
  837. $url = $util->getBaseUrl() . '/order/resendCode' . "?appKey=" . $appKey . "&messageFormat=xml&timestamp=" . $timestamp . "&sign=" . $sign . "&request=" . $request;
  838. $result = Utils::httpRequest($url);
  839. print_r($url);
  840. print_r($result);
  841. }
  842. /**
  843. * Function Description:订单信息推送接口
  844. * Function Name: actionPushOrderInfo
  845. *
  846. * @return string
  847. *
  848. * @author 娄梦宁
  849. */
  850. public function actionPushOrderInfo()
  851. {
  852. $util = new Util();
  853. $lvmama_push_info = new LvmamaPushInfo();
  854. $order_refund_lvmama = new OrderRefundLvmama();
  855. $order = Yii::$app->request->post('order', '');
  856. $order = Util::xmlToJson($order);
  857. file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '订单信息推送接收的json ' . $order . PHP_EOL, FILE_APPEND);
  858. // $order='{"header":{"signed":"dc0914aed23133d528ae4cd2779d484a"},"body":{"order":{"orderId":"20060214","status":"CANCEL","approveStatus":"true","paymentStatus":"PAYED","credenctStatus":"CREDENCE_SEND","waitPayment":{},"performStatus":"USED","credentials":"CREDENCE_SEND"}}}';
  859. $lvmama_push_info->istPush('订单信息推送接口', $order);
  860. $order = json_decode($order, true);
  861. $order_id = $order['body']['order']['orderId'];
  862. $secret = $util::getSecret();
  863. 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);
  864. 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);
  865. 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);
  866. if (md5($secret . $order_id) == $order['header']['signed']) {
  867. if ($order['body']['order']['status'] == 'CANCEL' || $order['body']['order']['status'] == 'REFUND') {//订单信息推送操作
  868. $status = $order['body']['order']['status'];
  869. $approve_status = $order['body']['order']['approveStatus'] == true ? 1 : 0;
  870. $payment_status = $order['body']['order']['paymentStatus'] == 'PAYED' ? 1 : 0;
  871. $istRefund = $order_refund_lvmama->istRefund($order_id, $status, $approve_status, $payment_status);
  872. if ($istRefund == false) {
  873. file_put_contents(__DIR__ . '/../log/lvmama/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '订单信息推送录入数据库失败 ' . $order_id . PHP_EOL, FILE_APPEND);
  874. }
  875. }
  876. $result = [
  877. 'response' => [
  878. 'state' => [
  879. 'code' => 1000,
  880. 'message' => '接收成功'
  881. ]
  882. ]
  883. ];
  884. } else {
  885. $result = [
  886. 'response' => [
  887. 'state' => [
  888. 'code' => 25,
  889. 'message' => '签名错误'
  890. ]
  891. ]
  892. ];
  893. }
  894. return '<?xml version="1.0" encoding="utf-8"?>' . Util::arrayToXml($result);
  895. }
  896. public function actionTest1(){
  897. // $time=time();
  898. //// $url="http://api.lvmama.com/distributorApi/2.0/api//ticket/createOrder?appKey=ZHIZHUCHUXING&messageFormat=Xml&timestamp=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>";
  899. // $sign=Util::SingForLvmama($time);
  900. // 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)');
  901. // $url='http://api.lvmama.com/distributorApi/2.0/api/ticket/createOrder?appKey=ZHIZHUCHUXING&messageFormat=Xml&timestamp=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>';
  902. // $result=file_get_contents($url);
  903. // // $result=Util::OrderPayment(56614790,1803444,'56614790'.'1803444_'.time());
  904. // print_r($result);
  905. $result=Util::OrderPayment(1804849,56626116,'1804849'.'56626116_'.time());
  906. print_r($result);
  907. }
  908. }