TestController.php 14 KB

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