TestController.php 12 KB

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