TestController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\sj\services\MerchantService;
  4. use bizGhs\express\services\DadaExpressServices;
  5. use bizGhs\order\classes\OrderClass;
  6. use bizHd\message\classes\InformAdminClass;
  7. use bizHd\order\services\OrderService;
  8. use bizHd\wx\classes\WxOpenClass;
  9. use bizGhs\express\services\MiniExpressService;
  10. use common\components\dict;
  11. use common\components\lakala\Lakala;
  12. use common\components\miniUtil;
  13. use common\components\orderSn;
  14. use common\components\wxUtil;
  15. use Yii;
  16. use common\components\util;
  17. class TestController extends BaseController
  18. {
  19. public $guestAccess = ['inform', 'notice', 'order-query', 'add-order', 'index'];
  20. public function actionAliRun()
  21. {
  22. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  23. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  24. $params = [
  25. 'appid' => 'OP00002119',
  26. 'serial_no' => '018b08cfddbd',
  27. 'merchant_no' => '82240505992000N',
  28. 'term_no' => 'C6337694',
  29. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  30. 'lklCertificatePath' => $lklCertificatePath,
  31. ];
  32. $aliParams = [
  33. 'subMerchantId' => '601067347',
  34. ];
  35. $laResource = new Lakala($params);
  36. $response = $laResource->openStateQuery($aliParams);
  37. print_r($response);
  38. }
  39. public function actionAliRun2()
  40. {
  41. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  42. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  43. $params = [
  44. 'appid' => 'OP00002119',
  45. 'serial_no' => '018b08cfddbd',
  46. 'merchant_no' => '82240505992000N',
  47. 'term_no' => 'C6337694',
  48. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  49. 'lklCertificatePath' => $lklCertificatePath,
  50. ];
  51. $outTradeNo = orderSn::getPurchaseSn();
  52. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  53. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  54. $aliParams = [
  55. 'orderSn' => $outTradeNo,
  56. 'amount' => 0.16,
  57. 'capitalType' => $currentCapitalType,
  58. 'notifyUrl' => $notifyUrl,
  59. ];
  60. $laResource = new Lakala($params);
  61. $response = $laResource->driveAliPay($aliParams);
  62. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  63. echo '<pre>';
  64. echo "下单成功<br/>";
  65. print_r($response);
  66. } else {
  67. echo '<pre>';
  68. echo "下单失败<br/>";
  69. print_r($response);
  70. }
  71. }
  72. public function actionAliRun3()
  73. {
  74. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  75. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  76. $params = [
  77. 'appid' => 'OP00002119',
  78. 'serial_no' => '018b08cfddbd',
  79. 'merchant_no' => '82240505992000N',
  80. 'term_no' => 'C6337694',
  81. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  82. 'lklCertificatePath' => $lklCertificatePath,
  83. ];
  84. $laResource = new Lakala($params);
  85. $outTradeNo = orderSn::getPurchaseSn();
  86. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  87. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  88. $wxParams = [
  89. 'orderSn' => $outTradeNo,
  90. 'amount' => 0.16,
  91. 'capitalType' => $currentCapitalType,
  92. 'notifyUrl' => $notifyUrl,
  93. ];
  94. $response = $laResource->driveWxPay($wxParams);
  95. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  96. echo '<pre>';
  97. echo "下单成功<br/>";
  98. print_r($response);
  99. } else {
  100. echo '<pre>';
  101. echo "下单失败<br/>";
  102. print_r($response);
  103. }
  104. }
  105. //dada 城市code
  106. public function actionDadaCityCode()
  107. {
  108. $res = dada::getCityCode(0);
  109. util::success($res);
  110. }
  111. //理由
  112. public function actionDadaReasons()
  113. {
  114. $res = dada::getCancelReason(0);
  115. util::success($res);
  116. }
  117. //达达 :下单
  118. public function actionDadaAddOrder()
  119. {
  120. $orderSn = 'XSD_CS26316851';
  121. $orderInfo = OrderClass::getByOrderSn($orderSn);
  122. $res = DadaExpressServices::addOrder($orderInfo);
  123. util::success($res);
  124. }
  125. //重发快递
  126. public function actionDadaReAdd()
  127. {
  128. $orderSn = 'XSD_CS26316851';
  129. $orderInfo = OrderClass::getByOrderSn($orderSn);
  130. $res = DadaExpressServices::reAddOrder($orderInfo);
  131. util::success($res);
  132. }
  133. //达达状态查询
  134. public function actionDadaOrderStatus()
  135. {
  136. $orderSn = 'XSD_CS26316851';
  137. $res = DadaExpressServices::statusOrder($orderSn);
  138. util::success($res);
  139. }
  140. //达达取消下单
  141. public function actionDadaCancelOrder()
  142. {
  143. $orderSn = 'XSD_CS26316851';
  144. $res = DadaExpressServices::cancelOrder($orderSn, 1);
  145. util::success($res);
  146. }
  147. //获取已支持的配送公司列表接口
  148. public function actionGetAllDelivery()
  149. {
  150. $data = MiniExpressService::getAllImmeDelivery();
  151. util::success($data);
  152. }
  153. //即时配送
  154. /*
  155. * Array
  156. (
  157. [resultcode] => 0
  158. [resultmsg] => OK
  159. [shop_list] => Array
  160. (
  161. [0] => Array
  162. (
  163. [shopid] => 1588714266
  164. [delivery_id] => SFTC
  165. [audit_result] => 0
  166. [create_time] => 1612172838
  167. [remark] =>
  168. [delivery_name] => 顺丰同城急送
  169. )
  170. )
  171. )
  172. */
  173. public function actionGetBindAccount()
  174. {
  175. $merchant = WxOpenClass::getGhsWxInfo();
  176. $isOpen = 2;
  177. $r = miniUtil::getBindAccount($merchant, $isOpen);
  178. dd($r);
  179. }
  180. //下单 (沙箱)
  181. /**
  182. * Array
  183. * (
  184. * [resultcode] => 0
  185. * [resultmsg] => ok
  186. * [fee] => 10
  187. * [waybill_id] => test_shop_id1612365974_waybillid
  188. * [order_status] => 101
  189. * [dispatch_duration] => 300
  190. * )
  191. */
  192. public function actionCreateWaybill()
  193. {
  194. $merchant = WxOpenClass::getGhsWxInfo();
  195. $isOpen = 2;
  196. $shopId = 'test_shop_id';
  197. $shopOrderId = 'test_shop_id' . time();
  198. $appSecret = 'test_app_secrect';
  199. $data = [
  200. 'shopid' => $shopId,
  201. 'shop_order_id' => $shopOrderId,
  202. 'shop_no' => '1',
  203. 'delivery_sign' => miniUtil::getDeliverySign($shopId, $shopOrderId, $appSecret), //,则delivery_sign=SHA1(shopid + shop_order_id + AppSecret)
  204. 'delivery_id' => "TEST",
  205. 'openid' => 'oGKMp45YLxewOTWEbpMFzWoVqdW0',
  206. 'sender' => [
  207. 'name' => 'test',
  208. 'city' => '厦门市',
  209. 'address' => '思明区',
  210. 'address_detail' => '软件园二期',
  211. 'phone' => '19959271111',
  212. 'lng' => 118.134343,
  213. 'lat' => 24.483566,
  214. 'coordinate_type' => 0,
  215. ],
  216. 'receiver' => [
  217. 'name' => 'test',
  218. 'city' => '厦门市',
  219. 'address' => '思明区',
  220. 'address_detail' => '软件园二期',
  221. 'phone' => '19959271111',
  222. 'lng' => 118.134343,
  223. 'lat' => 24.493566,
  224. 'coordinate_type' => 0,
  225. ],
  226. 'cargo' => [
  227. 'goods_value' => 1,
  228. 'goods_weight' => 0.1,
  229. 'cargo_first_class' => '鲜花',
  230. 'cargo_second_class' => '鲜花',
  231. ],
  232. 'order_info' => [
  233. 'order_type' => 0,
  234. ],
  235. 'shop' => [
  236. 'wxa_path' => '/shop',
  237. 'img_url' => 'http://www.baidu.com/test.png',
  238. 'goods_name' => 'test',
  239. 'goods_count' => 1,
  240. ],
  241. ];
  242. $r = miniUtil::addOrder($data, $merchant, $isOpen);
  243. dd($r);
  244. }
  245. //获取运单数据
  246. /**
  247. * Array
  248. * (
  249. * [resultcode] => 0
  250. * [resultmsg] => ok
  251. * [order_status] => 101
  252. * [agent_info] => Array
  253. * (
  254. * )
  255. *
  256. * [waybill_id] => test_shop_id1612365974_waybillid
  257. * [rider_name] =>
  258. * [rider_phone] =>
  259. * [order_token] => NsXweKCKhSyAEIhAdnX3TYZsVDES0-t-tymHDONG0MpRsF31dQvVxiP_JJvLFaKS-kwXuOG3D0hzKkl7o-gzew
  260. * )
  261. */
  262. public function actionGetOrder()
  263. {
  264. $shopId = 'test_shop_id';
  265. $shopOrderId = 'test_shop_id1612365974';
  266. $appSecret = 'test_app_secrect';
  267. $merchant = WxOpenClass::getGhsWxInfo();
  268. $isOpen = 2;
  269. $data = [
  270. 'shopid' => $shopId,
  271. 'shop_order_id' => $shopOrderId,
  272. 'shop_no' => '1',
  273. 'delivery_sign' => MiniExpressService::getDeliverySign($shopId, $shopOrderId, $appSecret),
  274. ];
  275. $r = miniUtil::getOrder($data, $merchant, $isOpen);
  276. dd($r);
  277. }
  278. //沙盒 更新快递状态
  279. public function actionMockUpdateOrder()
  280. {
  281. $merchant = WxOpenClass::getGhsWxInfo();
  282. $isOpen = 2;
  283. /**
  284. * {
  285. * "shopid": "test_shop_id",
  286. * "shop_order_id": "xxxxxxxxxxx",
  287. * "waybill_id": "xxxxxxxxxxxxx",
  288. * "action_time": 12345678,
  289. * "order_status": 101,
  290. * "action_msg": "",
  291. * }
  292. */
  293. $shopId = 'test_shop_id';
  294. $shopOrderId = 'test_shop_id1612365974';
  295. $data = [
  296. 'shop_order_id' => $shopOrderId,
  297. "shopid" => $shopId,
  298. "action_time" => time(),
  299. "order_status" => 302,
  300. 'action_msg' => '状态变更',
  301. ];
  302. $r = miniUtil::mockUpdateOrder($data, $merchant, $isOpen);
  303. dd($r);
  304. }
  305. public function actionTest()
  306. {
  307. }
  308. //新增订单
  309. public function actionAddOrder()
  310. {
  311. $dada = Yii::getAlias("@vendor/dada/");
  312. require_once $dada . 'api/addOrderApi.php';
  313. require_once $dada . 'client/dadaRequestClient.php';
  314. require_once $dada . 'client/dadaResponse.php';
  315. require_once $dada . 'config/config.php';
  316. require_once $dada . 'model/orderModel.php';
  317. // isOnline 判断是否是测试环境,会有不同的域名等
  318. $isOnline = false;
  319. $sourceId = 1000000;
  320. // 初始化一个config
  321. $config = new \Config($sourceId, $isOnline);
  322. $orderModel = new \OrderModel();
  323. $orderModel->setShopNo('11047059');
  324. $orderModel->setOriginId('2018091100000002');
  325. $orderModel->setCityCode('021');
  326. $orderModel->setCargoPrice(10);
  327. $orderModel->setIsPrepay(0);
  328. $orderModel->setReceiverName('测试达达');
  329. $orderModel->setReceiverAddress('上海市崇明岛');
  330. $orderModel->setReceiverLat(31.63);
  331. $orderModel->setReceiverLng(121.41);
  332. $orderModel->setReceiverPhone('18588888888');
  333. $orderModel->setCallback('http://api.b.huaml.com/data/request');
  334. // api主要有2个参数,一个是url, 一个是业务参数
  335. $addOrderApi = new \AddOrderApi(json_encode($orderModel));
  336. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  337. $resp = $dada_client->makeRequest();
  338. echo json_encode($resp);
  339. }
  340. //订单详情查询
  341. public function actionOrderQuery()
  342. {
  343. $dada = Yii::getAlias("@vendor/dada/");
  344. require_once $dada . 'api/OrderQueryApi.php';
  345. require_once $dada . 'client/dadaRequestClient.php';
  346. require_once $dada . 'client/dadaResponse.php';
  347. require_once $dada . 'config/config.php';
  348. require_once $dada . 'model/orderModel.php';
  349. // isOnline 判断是否是测试环境,会有不同的域名等
  350. $isOnline = false;
  351. $sourceId = 1000000;
  352. // 初始化一个config
  353. $config = new \Config($sourceId, $isOnline);
  354. $orderModel = new \OrderModel();
  355. $orderModel->setOrderId('2018091100000002');
  356. // api主要有2个参数,一个是url, 一个是业务参数
  357. $addOrderApi = new \OrderQueryApi(json_encode($orderModel));
  358. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  359. $resp = $dada_client->makeRequest();
  360. echo json_encode($resp);
  361. }
  362. public function actionFocus()
  363. {
  364. $name = '花卉宝';
  365. if (getenv('YII_ENV') == 'dev') {
  366. $name = '花美灵';
  367. }
  368. $merchant = MerchantService::getByCondition(['name' => $name]);
  369. $list = wxUtil::getSubscribeUserList($merchant);
  370. dd($list);
  371. }
  372. //宝贝售出提醒 ssh 2020.1.30
  373. public function actionInform()
  374. {
  375. $merchant = MerchantService::getMerchantById(12362);
  376. $order = OrderService::getById(214810);
  377. InformAdminClass::sendComplete($order);
  378. }
  379. public function actionNotice()
  380. {
  381. $data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
  382. $producer = Yii::$app->rabbitmq->getProducer('informProducer');
  383. echo '<pre>';
  384. print_r($data);
  385. $msg = serialize($data);
  386. $r = $producer->publish($msg, 'informExchange', 'informRoute');
  387. }
  388. }