TestController.php 13 KB

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