TestController.php 33 KB

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