TestController.php 9.4 KB

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