TestController.php 12 KB

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