TestController.php 33 KB

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