| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace hd\controllers;
- use bizHd\meituan\classes\MtOrderClass;
- use common\components\arrayUtil;
- use Yii;
- use Abbotton\MeituanTakeaway\Application;
- use yii\helpers\Json;
- class MtController extends PublicController
- {
- public $guestAccess = [];
- private $config = [
- 'app_id' => '119094',
- 'app_secret' => 'b7e86d768391180f805621b40ec31e33',
- 'request_url' => '', // 默认 `https://waimaiopen.meituan.com/api/v1/`
- ];
- public function actionApi()
- {
- echo '开发中...';
- }
- public function actionNewOrder()
- {
- $post = Yii::$app->request->post();
- if(empty($post)) { // 无数据过来时,是美团对接口进行存活试探,请保留此段代码,好让请求在此被中断返回
- return Json::encode(['data' => 'ok']);
- }
- // 美团传入的订单数据,中文是 URL_encode 的,执行下解密
- foreach($post as $k => $val) {
- $post[$k] = urldecode($val);
- }
- $data = arrayUtil::humpUnderlineConversion($post, 1);
- $orderId = $data['orderId'];
- $mtOrder = MtOrderClass::getByCondition(['orderId' => $orderId]);
- if (!empty($mtOrder)) {
- Yii::warning('订单号已存在:' . $orderId);
- return Json::encode(['data' => 'ok']);
- }
- $mtOrder = MtOrderClass::add($data);
- $picArr = [];
- $app = new Application($this->config);
- $detail = $data['detail'];
- $items = json_decode($detail, true);
- foreach($items as $item){
- $appSpuCode = $item['app_spu_code'];
- $params = ['app_poi_code' => $data['appPoiCode'], 'app_spu_code' => $appSpuCode];
- $retailDetail = $app->retail->getDetail($params);
- $retailDetail = json_decode($retailDetail, true);
- if (is_set($retailDetail['error'])) {
- Yii::error('get retail fail:' . json_encode($params));
- } else {
- $picArr[$appSpuCode] = $retailDetail['data']['picture'];
- }
- }
- Yii::info('picture: ' . json_encode($picArr));
- return Json::encode(['data' => 'ok']);
- }
- public function actionCancelOrder()
- {
- $post = Yii::$app->request->post();
- if(!empty($post)) {
- Yii::warning('cancelOrder: ' . urldecode(json_encode($post)));
- }
- return Json::encode(['data' => 'ok']);
- }
- public function demo() {
- $app = new Application($this->config);
- $params = ['order_id' => '27061900338318741', 'is_mt_logistics' => 1];
- $orderDetail = $app->order->getOrderDetail($params);
- print_r(json_decode($orderDetail, true));
- // 商品类、活动类接口支持异步队列
- $app->goods->async()->create([]);
- }
- }
|