TestController.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\sj\services\MerchantService;
  5. use bizGhs\express\services\DadaExpressServices;
  6. use bizGhs\order\classes\OrderClass;
  7. use bizHd\message\classes\InformAdminClass;
  8. use bizHd\order\services\OrderService;
  9. use bizHd\wx\classes\WxOpenClass;
  10. use bizGhs\express\services\MiniExpressService;
  11. use common\components\dict;
  12. use common\components\lakala\Lakala;
  13. use common\components\miniUtil;
  14. use common\components\noticeUtil;
  15. use common\components\orderSn;
  16. use common\components\wxUtil;
  17. use common\components\payUtil;
  18. use Yii;
  19. use common\components\util;
  20. class TestController extends BaseController
  21. {
  22. public $guestAccess = ['ls-trade-query', 'refund-query', 'inform', 'notice', 'order-query', 'add-order', 'index', 'get', 'trade-query', 'query', 'balance-query', 'refund'];
  23. //退款操作 ssh 20231029
  24. public function actionRefund()
  25. {
  26. $shopId = 36524;
  27. $shop = ShopClass::getById($shopId, true);
  28. if (empty($shop)) {
  29. util::fail('没有找到门店');
  30. }
  31. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  32. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  33. $params = [
  34. 'appid' => 'OP00002119',
  35. 'serial_no' => '018b08cfddbd',
  36. 'merchant_no' => $shop->lklSjNo,
  37. 'term_no' => $shop->lklB2BTermNo,
  38. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  39. 'lklCertificatePath' => $lklCertificatePath,
  40. ];
  41. $laResource = new Lakala($params);
  42. $refundReason = '暂无';
  43. $refundOrderSn = orderSn::getCgRefundSn();
  44. $refundPrice = 0.01;
  45. $refundFee = bcmul($refundPrice, 100);
  46. $orderSn = 'KD_CS61235203';
  47. $originTradeNo = '20231030110113230266215266468756';
  48. //$originLogNo = '66215266025626';
  49. $aliParams = [
  50. 'refundSn' => $refundOrderSn,
  51. 'orderSn' => $orderSn,
  52. 'refundAmount' => $refundFee,
  53. 'refundReason' => $refundReason,
  54. 'originTradeNo' => $originTradeNo,
  55. //'originLogNo' => $originLogNo,
  56. ];
  57. $response = $laResource->refund($aliParams);
  58. echo '<pre>';
  59. print_r($response);
  60. }
  61. public function actionApply()
  62. {
  63. $sjNo = '';
  64. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  65. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  66. $params = [
  67. 'appid' => 'OP00002119',
  68. 'serial_no' => '018b08cfddbd',
  69. 'merchant_no' => $sjNo,
  70. 'term_no' => 'C6337694',
  71. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  72. 'lklCertificatePath' => $lklCertificatePath,
  73. ];
  74. $data = [
  75. ];
  76. $laResource = new Lakala($params);
  77. $response = $laResource->applyInviteClear($data);
  78. }
  79. public function actionGet()
  80. {
  81. ini_set('memory_limit', '2045M');
  82. set_time_limit(0);
  83. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  84. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  85. $arr = [
  86. //['name' => '国兰花尚OK', 'merchantNo' => '82239305992006L', 'wx' => [600913569, 600907053], 'zfb' => '2088820709029782'],
  87. //['name' => '花掌柜OK', 'merchantNo' => '82240505992000P', 'wx' => [600466131, 600465187], 'zfb' => '2088820656569304'],
  88. //['name' => '纯彩花艺OK', 'merchantNo' => '82239305992006M', 'wx' => [600922790, 600915407], 'zfb' => '2088820710146836'],
  89. //['name' => '集美天天鲜花OK', 'merchantNo' => '82239305992006P', 'wx' => [601036538, 601036322], 'zfb' => '2088820726763339'],
  90. //['name' => '丰行花行OK', 'merchantNo' => '82260205992007P', 'wx' => [601053759, 601052157], 'zfb' => '2088820725885465'],
  91. //['name' => '独家花行OK', 'merchantNo' => '82239305992006Q', 'wx' => [601049483, 601048223], 'zfb' => '2088820725546555'],
  92. //['name' => '好多花海沧OK', 'merchantNo' => '82239305992006R', 'wx' => [601052177, 601053735], 'zfb' => '2088820725549695'],
  93. //['name' => '美天鲜花OK', 'merchantNo' => '82259505992003F', 'wx' => [601062064, 601138175], 'zfb' => '2088820729400990'],
  94. //['name' => '天天陈江店OK', 'merchantNo' => '82259505992003E', 'wx' => [601060616, 601059382], 'zfb' => '2088820725555368'],
  95. //['name' => '叶上花OK', 'merchantNo' => '82231805992002G', 'wx' => [601062892, 601062589], 'zfb' => '2088820728763546'],
  96. //['name' => '好又多(小明)OK', 'merchantNo' => '82239305992006S', 'wx' => [601135715, 601067347], 'zfb' => '2088820729698012'],
  97. //['name' => '我卖花OK', 'merchantNo' => '82227505992000R', 'wx' => [601177139, 601148755], 'zfb' => '2088820746424032'],
  98. //['name' => '问境OK', 'merchantNo' => '8226900599200KX', 'wx' => [601299388, 601299453], 'zfb' => '2088820787661843'],
  99. //['name' => '昱成OK', 'merchantNo' => '8226900599200KY', 'wx' => [601312993, 601325844], 'zfb' => '2088820788900240'],
  100. //['name' => '杭州斗南', 'merchantNo' => '杭州斗南', 'wx' => [601405963, 601405929], 'zfb' => '2088820793601705'],
  101. //['name' => '杭州斗南(没用)', 'merchantNo' => '8223310599200AD', 'wx' => [601254682, 601250805], 'zfb' => '2088820782666872'],
  102. //['name' => '珑松花卉长安店', 'merchantNo' => '82260205992007U', 'wx' => [602499045, 602497558], 'zfb' => '2088820959620797'],
  103. //['name' => '福州花福(个人)', 'merchantNo' => '82239105992007P', 'wx' => [603301197, 603302321], 'zfb' => '2088920058098261'],
  104. //['name' => '福州花福', 'merchantNo' => '82239105992007N', 'wx' => [602796807, 602774796], 'zfb' => '2088820996010582'],
  105. //['name' => '昆明新宏源', 'merchantNo' => '82239305992007H', 'wx' => [606098318, 606100317], 'zfb' => '2088920878302843'],
  106. //['name' => '昆明纯彩', 'merchantNo' => '82239905992003L', 'wx' => [604923629, 604922175], 'zfb' => '2088920533160795'],
  107. //['name' => '花优田(军兴旺)', 'merchantNo' => '8227310599200GX', 'wx' => [605191281, 605190492], 'zfb' => '2088920588715249'],
  108. ['name' => '云南珑松花卉珠海店', 'merchantNo' => '82258505992002U', 'wx' => [608062727, 608056474], 'zfb' => '2088030873238576'],
  109. ['name' => '买手很忙', 'merchantNo' => '8227310599200GJ', 'wx' => [601597167, 601595526], 'zfb' => '2088820818930267'],
  110. ['name' => '七彩花都', 'merchantNo' => '8227310599200GF', 'wx' => [601176481, 601148503], 'zfb' => '2088820748594478'],
  111. //['name' => '十年', 'merchantNo' => '82252305992001U', 'wx' => [601285154, 601261795], 'zfb' => '2088820782171763'],
  112. //['name' => '都市花季OK', 'merchantNo' => '82239305992006U', 'wx' => [601174342, 601147649], 'zfb' => '2088820748507346'],
  113. //['name' => '花样年华OK', 'merchantNo' => '82260205992007Q', 'wx' => [601134352, 601091710], 'zfb' => '2088820735043444'],
  114. //['name' => '精茂城OK', 'merchantNo' => '8225840599200TF', 'wx' => [601173752, 601143352], 'zfb' => '2088820746800005'],
  115. //['name' => '莱漫OK', 'merchantNo' => '82239305992007A', 'wx' => [601288494, 601288166], 'zfb' => '2088820783686611'],
  116. //['name' => '莱漫(没用)', 'merchantNo' => '82239305992006T', 'wx' => [601134065, 601125595], 'zfb' => '2088820743859918'],
  117. //['name' => '福州我要花OK', 'merchantNo' => '82239105992007J', 'wx' => [601134030, 601128111], 'zfb' => '2088820745276973'],
  118. //['name' => '泉城OK', 'merchantNo' => '82239705992004F', 'wx' => [601273270, 601272854], 'zfb' => '2088820784658561'],
  119. //['name' => '泉城(没用)', 'merchantNo' => '82239705992004E', 'wx' => [601133056, 601133821], 'zfb' => '2088820746111323'],
  120. //['name' => '美丽花行OK', 'merchantNo' => '82239305992006V', 'wx' => [601155249, 601149712], 'zfb' => '2088820747673312'],
  121. //['name' => '三叶OK', 'merchantNo' => '82236805992001Y', 'wx' => [601152233, 601151024], 'zfb' => '2088820747556725'],
  122. //['name' => '花大苪OK', 'merchantNo' => '8227310599200GG', 'wx' => [601174221, 601165136], 'zfb' => '2088820751181377'],
  123. //['name' => '十堰天天鲜花OK', 'merchantNo' => '82252305992001S', 'wx' => [601171131, 601170642], 'zfb' => '2088820750844626'],
  124. //['name' => '珑松花卉OK', 'merchantNo' => '82260205992007S', 'wx' => [601176093, 601174262], 'zfb' => '2088820754742492'],
  125. //['name' => '惠雅鲜花OK', 'merchantNo' => '82260205992007R', 'wx' => [601173390, 601174002], 'zfb' => '2088820753174540'],
  126. //['name' => '锦绣花卉OK', 'merchantNo' => '82252305992001T', 'wx' => [601176719, 601176660], 'zfb' => '2088820754751663'],
  127. //['name' => '祥瑞鲜花同安店OK', 'merchantNo' => '82239305992006W', 'wx' => [601178350, 601177795], 'zfb' => '2088820755715024'],
  128. //['name' => '祥瑞鲜花翔安店OK', 'merchantNo' => '82239305992006X', 'wx' => [601178260, 601178199], 'zfb' => '2088820754481553'],
  129. //['name' => '初见花季OK', 'merchantNo' => '82239305992006Y', 'wx' => [601178998, 601179605], 'zfb' => '2088820757223312'],
  130. //['name' => '荣发鲜花OK', 'merchantNo' => '82242705992000D', 'wx' => [601179681, 601179180], 'zfb' => '2088820756926593'],
  131. //['name' => '花千朵(多多)OK', 'merchantNo' => '82239305992006Z', 'wx' => [601223474, 601208096], 'zfb' => '2088820766783276'],
  132. //['name' => '花悠星OK', 'merchantNo' => '8225810599200NH', 'wx' => [601228194, 601227691], 'zfb' => '2088820774587446'],
  133. //['name' => '花悠星(没用)', 'merchantNo' => '8225810599200NG', 'wx' => [601223630, 601210952], 'zfb' => '2088820767072874'],
  134. //['name' => '源花汇OK', 'merchantNo' => '82222105992004A', 'wx' => [601221944, 601214269], 'zfb' => '2088820770594246'],
  135. //['name' => '源花汇2(没用)', 'merchantNo' => '8227310599200GD', 'wx' => [601136305, 601067016], 'zfb' => '2088820729832744'],
  136. ];
  137. $new = [];
  138. foreach ($arr as $item) {
  139. $wx = $item['wx'];
  140. $zfb = $item['zfb'];
  141. $merchantNo = $item['merchantNo'];
  142. $name = $item['name'] . ' ' . $merchantNo;
  143. $group = [];
  144. foreach ($wx as $oneWx) {
  145. $params = [
  146. 'appid' => 'OP00002119',
  147. 'serial_no' => '018b08cfddbd',
  148. 'merchant_no' => $merchantNo,
  149. 'term_no' => 'C6337694',
  150. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  151. 'lklCertificatePath' => $lklCertificatePath,
  152. ];
  153. $data = [
  154. 'subMerchantId' => $oneWx,
  155. 'tradeMode' => 'WECHAT',
  156. ];
  157. $laResource = new Lakala($params);
  158. $response = $laResource->openStateQuery($data);
  159. $statusName = '出错了';
  160. if ($response['retCode'] == '000000') {
  161. $checkResult = $response['respData']['checkResult'] ?? '';
  162. $statusName = '未确认';
  163. if ($checkResult == 'AUTHORIZE_STATE_AUTHORIZED') {
  164. $statusName = '已确认';
  165. }
  166. }
  167. $group[] = '微信 ' . $oneWx . ' ' . $statusName;
  168. }
  169. $params = [
  170. 'appid' => 'OP00002119',
  171. 'serial_no' => '018b08cfddbd',
  172. 'merchant_no' => $merchantNo,
  173. 'term_no' => 'C6337694',
  174. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  175. 'lklCertificatePath' => $lklCertificatePath,
  176. ];
  177. $data = [
  178. 'subMerchantId' => $zfb,
  179. 'tradeMode' => 'ALIPAY',
  180. ];
  181. $laResource = new Lakala($params);
  182. $response = $laResource->openStateQuery($data);
  183. $statusName = '出错了';
  184. if ($response['retCode'] == '000000') {
  185. $checkResult = $response['respData']['checkResult'] ?? '';
  186. $statusName = '未确认';
  187. if ($checkResult == 'AUTHORIZED') {
  188. $statusName = '已确认';
  189. }
  190. }
  191. $group[] = '支付宝 ' . $zfb . ' ' . $statusName;
  192. $new[] = ['name' => $name, 'status' => $group];
  193. }
  194. echo '<pre>';
  195. print_r($new);
  196. die;
  197. }
  198. public function actionRefundQuery()
  199. {
  200. $shopId = 36523;
  201. $shop = ShopClass::getById($shopId, true);
  202. if (empty($shop)) {
  203. util::stop('没有找到门店');
  204. }
  205. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  206. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  207. $params = [
  208. 'appid' => 'OP00002119',
  209. 'serial_no' => '018b08cfddbd',
  210. 'merchant_no' => $shop->lklSjNo,
  211. 'term_no' => $shop->lklScanTermNo,
  212. // 'merchant_no' => '82260205992007P',
  213. // 'term_no' => 'D7652397',
  214. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  215. 'lklCertificatePath' => $lklCertificatePath,
  216. ];
  217. $laResource = new Lakala($params);
  218. $orderSn = 'RD_CS28000336';
  219. $data = [
  220. 'orderSn' => $orderSn,
  221. ];
  222. $response = $laResource->refundQuery($data);
  223. echo "<pre>";
  224. print_r($response);
  225. }
  226. public function actionBalanceQuery()
  227. {
  228. $shopId = 1212;
  229. $shop = ShopClass::getById($shopId, true);
  230. if (empty($shop)) {
  231. util::stop('没有找到门店');
  232. }
  233. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  234. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  235. $params = [
  236. 'appid' => 'OP00002119',
  237. 'serial_no' => '018b08cfddbd',
  238. 'merchant_no' => $shop->lklSjNo,
  239. 'term_no' => $shop->lklScanTermNo,
  240. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  241. 'lklCertificatePath' => $lklCertificatePath,
  242. ];
  243. $laResource = new Lakala($params);
  244. $response = $laResource->accountBalanceQuery();
  245. echo "<pre>";
  246. print_r($response);
  247. }
  248. public function actionQuery()
  249. {
  250. // $shopId = 1527;
  251. // $shop = ShopClass::getById($shopId, true);
  252. // if (empty($shop)) {
  253. // util::stop('没有找到门店');
  254. // }
  255. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  256. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  257. $params = [
  258. 'appid' => 'OP00002119',
  259. 'serial_no' => '018b08cfddbd',
  260. //'merchant_no' => $shop->lklSjNo,
  261. 'merchant_no' => '82230505992009P',
  262. //'term_no' => $shop->lklScanTermNo,
  263. 'term_no' => 'H3814976',
  264. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  265. 'lklCertificatePath' => $lklCertificatePath,
  266. ];
  267. $laResource = new Lakala($params);
  268. $queryParams = [
  269. 'orderSn' => 'KD26452235',
  270. ];
  271. $response = $laResource->query($queryParams, 0);
  272. echo "<pre>";
  273. print_r($response);
  274. }
  275. //零售订单查询 ssh 20231031
  276. public function actionLsTradeQuery()
  277. {
  278. $shopId = 763;
  279. $shop = ShopClass::getById($shopId, true);
  280. if (empty($shop)) {
  281. util::stop('没有找到门店');
  282. }
  283. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  284. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  285. $params = [
  286. 'appid' => 'OP00002119',
  287. 'serial_no' => '018b08cfddbd',
  288. 'merchant_no' => $shop->lklSjNo,
  289. 'term_no' => $shop->lklScanTermNo,
  290. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  291. 'lklCertificatePath' => $lklCertificatePath,
  292. ];
  293. $laResource = new Lakala($params);
  294. $queryParams = [
  295. 'orderSn' => 'KD26456043',
  296. //'tradeNo' => '20231029110113130266215259252887',
  297. ];
  298. $response = $laResource->query($queryParams, 0);
  299. print_r($response);
  300. util::stop();
  301. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  302. $connection = Yii::$app->db;
  303. $transaction = $connection->beginTransaction();
  304. try {
  305. $postData = $response['resp_data'] ?? [];
  306. $orderSn = $postData['out_trade_no'] ?? '';
  307. $total_amount = $postData['total_amount'] ?? 0;
  308. $account_type = $postData['account_type'] ?? '';
  309. if (empty($account_type)) {
  310. noticeUtil::push('支付回调失败了,没有找到钱包类型,请注意,orderSn:' . $orderSn, '15280215347');
  311. util::end();
  312. }
  313. $totalFee = $total_amount / 100;
  314. $transactionId = $postData['trade_no'] ?? 0;
  315. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  316. $currentPayWay = null;
  317. if ($account_type == 'WECHAT') {
  318. $currentPayWay = dict::getDict('payWay', 'wxPay');
  319. } elseif ($account_type == 'ALIPAY') {
  320. $currentPayWay = dict::getDict('payWay', 'alipay');
  321. } else {
  322. noticeUtil::push('支付回调失败了,没有找到支付类型,orderSn:' . $orderSn, '15280215347');
  323. util::end();
  324. }
  325. $attach = '';
  326. payUtil::thirdPay($currentPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  327. $transaction->commit();
  328. echo 'OK';
  329. } catch (\Exception $e) {
  330. $transaction->rollBack();
  331. Yii::error("失败原因:" . $e->getMessage());
  332. }
  333. }
  334. }
  335. //交易查询 ssh 20231021
  336. public function actionTradeQuery()
  337. {
  338. $shopId = 12003;
  339. $shop = ShopClass::getById($shopId, true);
  340. if (empty($shop)) {
  341. util::stop('没有找到门店');
  342. }
  343. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  344. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  345. $params = [
  346. 'appid' => 'OP00002119',
  347. 'serial_no' => '018b08cfddbd',
  348. 'merchant_no' => $shop->lklSjNo,
  349. 'term_no' => $shop->lklScanTermNo,
  350. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  351. 'lklCertificatePath' => $lklCertificatePath,
  352. ];
  353. $laResource = new Lakala($params);
  354. $queryParams = [
  355. 'orderSn' => 'CG26714137',
  356. //'tradeNo' => '20231029110113130266215259252887',
  357. ];
  358. $response = $laResource->query($queryParams, 0);
  359. print_r($response);
  360. util::stop();
  361. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  362. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  363. $connection = Yii::$app->db;
  364. $transaction = $connection->beginTransaction();
  365. try {
  366. $account_type = $response['resp_data']['account_type'] ?? 0;
  367. if (empty($account_type)) {
  368. noticeUtil::push('支付回调失败了,没有找到钱包类型,请注意', '15280215347');
  369. util::end();
  370. }
  371. $currentPayWay = null;
  372. if ($account_type == 'WECHAT') {
  373. $currentPayWay = dict::getDict('payWay', 'wxPay');
  374. } elseif ($account_type == 'ALIPAY') {
  375. $currentPayWay = dict::getDict('payWay', 'alipay');
  376. } else {
  377. noticeUtil::push('支付回调失败了,没有找到支付类型', '15280215347');
  378. util::end();
  379. }
  380. $attach = '';
  381. $total_amount = $response['resp_data']['total_amount'] ?? 0;
  382. $orderSn = $response['resp_data']['out_trade_no'] ?? 0;
  383. $totalFee = $total_amount / 100;
  384. $transactionId = $response['resp_data']['trade_no'] ?? 0;
  385. payUtil::thirdPay($currentPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  386. $transaction->commit();
  387. echo 'OK';
  388. } catch (\Exception $e) {
  389. $transaction->rollBack();
  390. Yii::error("失败原因:" . $e->getMessage());
  391. }
  392. }
  393. }
  394. public function actionAliRun2()
  395. {
  396. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  397. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  398. $params = [
  399. 'appid' => 'OP00002119',
  400. 'serial_no' => '018b08cfddbd',
  401. 'merchant_no' => '82240505992000N',
  402. 'term_no' => 'C6337694',
  403. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  404. 'lklCertificatePath' => $lklCertificatePath,
  405. ];
  406. $outTradeNo = orderSn::getPurchaseSn();
  407. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  408. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  409. $aliParams = [
  410. 'orderSn' => $outTradeNo,
  411. 'amount' => 0.16,
  412. 'capitalType' => $currentCapitalType,
  413. 'notifyUrl' => $notifyUrl,
  414. ];
  415. $laResource = new Lakala($params);
  416. $response = $laResource->driveAliPay($aliParams);
  417. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  418. echo '<pre>';
  419. echo "下单成功<br/>";
  420. print_r($response);
  421. } else {
  422. echo '<pre>';
  423. echo "下单失败<br/>";
  424. print_r($response);
  425. }
  426. }
  427. public function actionAliRun3()
  428. {
  429. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  430. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  431. $params = [
  432. 'appid' => 'OP00002119',
  433. 'serial_no' => '018b08cfddbd',
  434. 'merchant_no' => '82240505992000N',
  435. 'term_no' => 'C6337694',
  436. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  437. 'lklCertificatePath' => $lklCertificatePath,
  438. ];
  439. $laResource = new Lakala($params);
  440. $outTradeNo = orderSn::getPurchaseSn();
  441. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  442. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  443. $wxParams = [
  444. 'orderSn' => $outTradeNo,
  445. 'amount' => 0.16,
  446. 'capitalType' => $currentCapitalType,
  447. 'notifyUrl' => $notifyUrl,
  448. ];
  449. $response = $laResource->driveWxPay($wxParams);
  450. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  451. echo '<pre>';
  452. echo "下单成功<br/>";
  453. print_r($response);
  454. } else {
  455. echo '<pre>';
  456. echo "下单失败<br/>";
  457. print_r($response);
  458. }
  459. }
  460. //dada 城市code
  461. public function actionDadaCityCode()
  462. {
  463. $res = dada::getCityCode(0);
  464. util::success($res);
  465. }
  466. //理由
  467. public function actionDadaReasons()
  468. {
  469. $res = dada::getCancelReason(0);
  470. util::success($res);
  471. }
  472. //达达 :下单
  473. public function actionDadaAddOrder()
  474. {
  475. $orderSn = 'XSD_CS26316851';
  476. $orderInfo = OrderClass::getByOrderSn($orderSn);
  477. $res = DadaExpressServices::addOrder($orderInfo);
  478. util::success($res);
  479. }
  480. //重发快递
  481. public function actionDadaReAdd()
  482. {
  483. $orderSn = 'XSD_CS26316851';
  484. $orderInfo = OrderClass::getByOrderSn($orderSn);
  485. $res = DadaExpressServices::reAddOrder($orderInfo);
  486. util::success($res);
  487. }
  488. //达达状态查询
  489. public function actionDadaOrderStatus()
  490. {
  491. $orderSn = 'XSD_CS26316851';
  492. $res = DadaExpressServices::statusOrder($orderSn);
  493. util::success($res);
  494. }
  495. //达达取消下单
  496. public function actionDadaCancelOrder()
  497. {
  498. $orderSn = 'XSD_CS26316851';
  499. $res = DadaExpressServices::cancelOrder($orderSn, 1);
  500. util::success($res);
  501. }
  502. //获取已支持的配送公司列表接口
  503. public function actionGetAllDelivery()
  504. {
  505. $data = MiniExpressService::getAllImmeDelivery();
  506. util::success($data);
  507. }
  508. //即时配送
  509. /*
  510. * Array
  511. (
  512. [resultcode] => 0
  513. [resultmsg] => OK
  514. [shop_list] => Array
  515. (
  516. [0] => Array
  517. (
  518. [shopid] => 1588714266
  519. [delivery_id] => SFTC
  520. [audit_result] => 0
  521. [create_time] => 1612172838
  522. [remark] =>
  523. [delivery_name] => 顺丰同城急送
  524. )
  525. )
  526. )
  527. */
  528. public function actionGetBindAccount()
  529. {
  530. $merchant = WxOpenClass::getGhsWxInfo();
  531. $isOpen = 2;
  532. $r = miniUtil::getBindAccount($merchant, $isOpen);
  533. dd($r);
  534. }
  535. //下单 (沙箱)
  536. /**
  537. * Array
  538. * (
  539. * [resultcode] => 0
  540. * [resultmsg] => ok
  541. * [fee] => 10
  542. * [waybill_id] => test_shop_id1612365974_waybillid
  543. * [order_status] => 101
  544. * [dispatch_duration] => 300
  545. * )
  546. */
  547. public function actionCreateWaybill()
  548. {
  549. $merchant = WxOpenClass::getGhsWxInfo();
  550. $isOpen = 2;
  551. $shopId = 'test_shop_id';
  552. $shopOrderId = 'test_shop_id' . time();
  553. $appSecret = 'test_app_secrect';
  554. $data = [
  555. 'shopid' => $shopId,
  556. 'shop_order_id' => $shopOrderId,
  557. 'shop_no' => '1',
  558. 'delivery_sign' => miniUtil::getDeliverySign($shopId, $shopOrderId, $appSecret), //,则delivery_sign=SHA1(shopid + shop_order_id + AppSecret)
  559. 'delivery_id' => "TEST",
  560. 'openid' => 'oGKMp45YLxewOTWEbpMFzWoVqdW0',
  561. 'sender' => [
  562. 'name' => 'test',
  563. 'city' => '厦门市',
  564. 'address' => '思明区',
  565. 'address_detail' => '软件园二期',
  566. 'phone' => '19959271111',
  567. 'lng' => 118.134343,
  568. 'lat' => 24.483566,
  569. 'coordinate_type' => 0,
  570. ],
  571. 'receiver' => [
  572. 'name' => 'test',
  573. 'city' => '厦门市',
  574. 'address' => '思明区',
  575. 'address_detail' => '软件园二期',
  576. 'phone' => '19959271111',
  577. 'lng' => 118.134343,
  578. 'lat' => 24.493566,
  579. 'coordinate_type' => 0,
  580. ],
  581. 'cargo' => [
  582. 'goods_value' => 1,
  583. 'goods_weight' => 0.1,
  584. 'cargo_first_class' => '鲜花',
  585. 'cargo_second_class' => '鲜花',
  586. ],
  587. 'order_info' => [
  588. 'order_type' => 0,
  589. ],
  590. 'shop' => [
  591. 'wxa_path' => '/shop',
  592. 'img_url' => 'http://www.baidu.com/test.png',
  593. 'goods_name' => 'test',
  594. 'goods_count' => 1,
  595. ],
  596. ];
  597. $r = miniUtil::addOrder($data, $merchant, $isOpen);
  598. dd($r);
  599. }
  600. //获取运单数据
  601. /**
  602. * Array
  603. * (
  604. * [resultcode] => 0
  605. * [resultmsg] => ok
  606. * [order_status] => 101
  607. * [agent_info] => Array
  608. * (
  609. * )
  610. *
  611. * [waybill_id] => test_shop_id1612365974_waybillid
  612. * [rider_name] =>
  613. * [rider_phone] =>
  614. * [order_token] => NsXweKCKhSyAEIhAdnX3TYZsVDES0-t-tymHDONG0MpRsF31dQvVxiP_JJvLFaKS-kwXuOG3D0hzKkl7o-gzew
  615. * )
  616. */
  617. public function actionGetOrder()
  618. {
  619. $shopId = 'test_shop_id';
  620. $shopOrderId = 'test_shop_id1612365974';
  621. $appSecret = 'test_app_secrect';
  622. $merchant = WxOpenClass::getGhsWxInfo();
  623. $isOpen = 2;
  624. $data = [
  625. 'shopid' => $shopId,
  626. 'shop_order_id' => $shopOrderId,
  627. 'shop_no' => '1',
  628. 'delivery_sign' => MiniExpressService::getDeliverySign($shopId, $shopOrderId, $appSecret),
  629. ];
  630. $r = miniUtil::getOrder($data, $merchant, $isOpen);
  631. dd($r);
  632. }
  633. //沙盒 更新快递状态
  634. public function actionMockUpdateOrder()
  635. {
  636. $merchant = WxOpenClass::getGhsWxInfo();
  637. $isOpen = 2;
  638. /**
  639. * {
  640. * "shopid": "test_shop_id",
  641. * "shop_order_id": "xxxxxxxxxxx",
  642. * "waybill_id": "xxxxxxxxxxxxx",
  643. * "action_time": 12345678,
  644. * "order_status": 101,
  645. * "action_msg": "",
  646. * }
  647. */
  648. $shopId = 'test_shop_id';
  649. $shopOrderId = 'test_shop_id1612365974';
  650. $data = [
  651. 'shop_order_id' => $shopOrderId,
  652. "shopid" => $shopId,
  653. "action_time" => time(),
  654. "order_status" => 302,
  655. 'action_msg' => '状态变更',
  656. ];
  657. $r = miniUtil::mockUpdateOrder($data, $merchant, $isOpen);
  658. dd($r);
  659. }
  660. public function actionTest()
  661. {
  662. }
  663. //新增订单
  664. public function actionAddOrder()
  665. {
  666. $dada = Yii::getAlias("@vendor/dada/");
  667. require_once $dada . 'api/addOrderApi.php';
  668. require_once $dada . 'client/dadaRequestClient.php';
  669. require_once $dada . 'client/dadaResponse.php';
  670. require_once $dada . 'config/config.php';
  671. require_once $dada . 'model/orderModel.php';
  672. // isOnline 判断是否是测试环境,会有不同的域名等
  673. $isOnline = false;
  674. $sourceId = 1000000;
  675. // 初始化一个config
  676. $config = new \Config($sourceId, $isOnline);
  677. $orderModel = new \OrderModel();
  678. $orderModel->setShopNo('11047059');
  679. $orderModel->setOriginId('2018091100000002');
  680. $orderModel->setCityCode('021');
  681. $orderModel->setCargoPrice(10);
  682. $orderModel->setIsPrepay(0);
  683. $orderModel->setReceiverName('测试达达');
  684. $orderModel->setReceiverAddress('上海市崇明岛');
  685. $orderModel->setReceiverLat(31.63);
  686. $orderModel->setReceiverLng(121.41);
  687. $orderModel->setReceiverPhone('18588888888');
  688. $orderModel->setCallback('http://api.b.huaml.com/data/request');
  689. // api主要有2个参数,一个是url, 一个是业务参数
  690. $addOrderApi = new \AddOrderApi(json_encode($orderModel));
  691. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  692. $resp = $dada_client->makeRequest();
  693. echo json_encode($resp);
  694. }
  695. //订单详情查询
  696. public function actionOrderQuery()
  697. {
  698. $dada = Yii::getAlias("@vendor/dada/");
  699. require_once $dada . 'api/OrderQueryApi.php';
  700. require_once $dada . 'client/dadaRequestClient.php';
  701. require_once $dada . 'client/dadaResponse.php';
  702. require_once $dada . 'config/config.php';
  703. require_once $dada . 'model/orderModel.php';
  704. // isOnline 判断是否是测试环境,会有不同的域名等
  705. $isOnline = false;
  706. $sourceId = 1000000;
  707. // 初始化一个config
  708. $config = new \Config($sourceId, $isOnline);
  709. $orderModel = new \OrderModel();
  710. $orderModel->setOrderId('2018091100000002');
  711. // api主要有2个参数,一个是url, 一个是业务参数
  712. $addOrderApi = new \OrderQueryApi(json_encode($orderModel));
  713. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  714. $resp = $dada_client->makeRequest();
  715. echo json_encode($resp);
  716. }
  717. public function actionFocus()
  718. {
  719. $name = '花卉宝';
  720. if (getenv('YII_ENV') == 'dev') {
  721. $name = '花美灵';
  722. }
  723. $merchant = MerchantService::getByCondition(['name' => $name]);
  724. $list = wxUtil::getSubscribeUserList($merchant);
  725. dd($list);
  726. }
  727. //宝贝售出提醒 ssh 2020.1.30
  728. public function actionInform()
  729. {
  730. $merchant = MerchantService::getMerchantById(12362);
  731. $order = OrderService::getById(214810);
  732. InformAdminClass::sendComplete($order);
  733. }
  734. public function actionNotice()
  735. {
  736. $data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
  737. $producer = Yii::$app->rabbitmq->getProducer('informProducer');
  738. echo '<pre>';
  739. print_r($data);
  740. $msg = serialize($data);
  741. $r = $producer->publish($msg, 'informExchange', 'informRoute');
  742. }
  743. }