CustomRechargeController.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. namespace hd\controllers;
  3. use bizGhs\custom\classes\CustomClass;
  4. use bizGhs\custom\classes\CustomRechargeClass;
  5. use bizGhs\ghs\classes\GhsRechargeClass;
  6. use bizHd\ghs\classes\GhsClass;
  7. use bizHd\shop\classes\ShopClass;
  8. use common\components\lakala\Lakala;
  9. use common\components\dict;
  10. use common\components\noticeUtil;
  11. use common\components\orderSn;
  12. use common\components\util;
  13. use bizHd\wx\classes\WxOpenClass;
  14. use Yii;
  15. class CustomRechargeController extends BaseController
  16. {
  17. public $guestAccess = ['recharge'];
  18. //充值 ssh 20240507
  19. public function actionRecharge()
  20. {
  21. ini_set('date.timezone', 'Asia/Shanghai');
  22. $post = Yii::$app->request->post();
  23. $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
  24. $actPrice = $post['actPrice'] ?? 0;
  25. $totalFee = $actPrice;
  26. $ghsId = $post['ghsId'] ?? 0;
  27. $salt = $post['salt'] ?? '';
  28. $ghs = GhsClass::getById($ghsId, true);
  29. if (empty($ghs)) {
  30. util::fail('没有找到供货商哦!');
  31. }
  32. if ($ghs->salt != $salt) {
  33. util::fail('不是你的供货商哦');
  34. }
  35. $customId = $ghs->customId ?? 0;
  36. $custom = CustomClass::getById($customId, true);
  37. if (empty($custom)) {
  38. util::fail('供货商信息不完整那');
  39. }
  40. $capitalType = dict::getDict('capitalType', 'customRechargeToGhs', 'id');
  41. $customOrderSn = orderSn::getGhsCustomRechargeSn();
  42. $customShopId = $custom->shopId ?? 0;
  43. $customMainId = $custom->mainId ?? 0;
  44. $customBalance = $custom->balance ?? 0;
  45. $customName = $custom->name ?? '';
  46. $ghsShopId = $ghs->shopId ?? 0;
  47. $ghsMainId = $ghs->mainId ?? 0;
  48. $ghsBalance = $ghs->balance ?? 0;
  49. $ghsName = $ghs->name ?? '';
  50. $ghsShop = ShopClass::getById($ghsShopId, true);
  51. if (empty($ghsShop)) {
  52. util::fail('供货商信息不完全哦');
  53. }
  54. $customStaffId = 0;
  55. $customStaffName = '';
  56. if (isset($this->shopAdmin) && !empty($this->shopAdmin)) {
  57. $staff = $this->shopAdmin;
  58. $customStaffId = $staff->id ?? 0;
  59. $customStaffName = $staff->name ?? '';
  60. }
  61. $cData = [
  62. 'orderSn' => $customOrderSn,
  63. 'onlinePay' => 2,
  64. 'payWay' => $payWay,
  65. 'shopId' => $ghsShopId,
  66. 'mainId' => $ghsMainId,
  67. 'amount' => $actPrice,
  68. 'balance' => $customBalance,
  69. 'side' => 0,
  70. 'staffId' => 0,
  71. 'staffName' => '',
  72. 'payStatus' => 0,
  73. 'status' => 0,
  74. 'remark' => '',
  75. 'ghsId' => $ghsId,
  76. 'ghsShopId' => $ghsShopId,
  77. 'ghsName' => $ghsName,
  78. 'customId' => $customId,
  79. 'customShopId' => $customShopId,
  80. 'customName' => $customName,
  81. 'remark' => '',
  82. ];
  83. $cRecharge = CustomRechargeClass::add($cData, true);
  84. $cRechargeId = $cRecharge->id ?? 0;
  85. $ghsOrderSn = orderSn::getGhsRechargeSn();
  86. $gData = [
  87. 'orderSn' => $ghsOrderSn,
  88. 'onlinePay' => 2,
  89. 'payWay' => $payWay,
  90. 'shopId' => $customShopId,
  91. 'mainId' => $customMainId,
  92. 'amount' => $actPrice,
  93. 'balance' => $ghsBalance,
  94. 'side' => 0,
  95. 'staffId' => $customStaffId,
  96. 'staffName' => $customStaffName,
  97. 'payStatus' => 0,
  98. 'status' => 0,
  99. 'remark' => '',
  100. 'ghsId' => $ghsId,
  101. 'ghsShopId' => $ghsShopId,
  102. 'ghsName' => $ghsName,
  103. 'customId' => $customId,
  104. 'customShopId' => $customShopId,
  105. 'customName' => $customName,
  106. 'remark' => '',
  107. ];
  108. $gRecharge = GhsRechargeClass::add($gData, true);
  109. $gRechargeId = $gRecharge->id ?? 0;
  110. $cRecharge->ghsRechargeId = $gRechargeId;
  111. $cRecharge->save();
  112. $gRecharge->customRechargeId = $cRechargeId;
  113. $gRecharge->save();
  114. $subject = '充值销账 单号' . $customOrderSn;
  115. if ($payWay == 0) {
  116. $openId = '';
  117. if (isset($post['currentMiniOpenId']) && !empty($post['currentMiniOpenId'])) {
  118. $openId = $post['currentMiniOpenId'];
  119. }
  120. if (empty($openId)) {
  121. if (isset($this->admin) && !empty($this->admin)) {
  122. if (isset($this->admin->miniOpenId) && !empty($this->admin->miniOpenId)) {
  123. $openId = $this->admin->miniOpenId;
  124. }
  125. }
  126. }
  127. if (empty($openId)) {
  128. $currentShop = ShopClass::getById($customShopId, true);
  129. $currentShopName = $currentShop->merchantName . ' ' . $currentShop->shopName;
  130. $currentMobile = $currentShop->mobile ?? '';
  131. noticeUtil::push("花店向供货商充值时,发现没有openId。{$currentShopName} {$currentMobile}", '15280215347');
  132. util::fail('用户信息不完整');
  133. }
  134. $merchantExtend = WxOpenClass::getWxInfo();
  135. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  136. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  137. $params = [
  138. 'appid' => 'OP00002119',
  139. 'serial_no' => '018b08cfddbd',
  140. 'merchant_no' => $ghsShop->lklSjNo,
  141. 'term_no' => $ghsShop->lklScanTermNo,
  142. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  143. 'lklCertificatePath' => $lklCertificatePath,
  144. ];
  145. $laResource = new Lakala($params);
  146. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  147. $wxParams = [
  148. 'orderSn' => $customOrderSn,
  149. 'amount' => $totalFee,
  150. 'capitalType' => $capitalType,
  151. 'notifyUrl' => $notifyUrl,
  152. 'wxAppId' => $merchantExtend['miniAppId'],
  153. 'openId' => $openId,
  154. 'subject' => $subject,
  155. 'couponId' => 0,
  156. ];
  157. $response = $laResource->driveWxPay($wxParams);
  158. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  159. $errMsg = $response['msg'] ?? '';
  160. noticeUtil::push('编号19881507:' . $errMsg .' | '. $ghsName .' | '. $customName.' | '. $actPrice, '15280215347');
  161. util::fail('支付失败');
  162. }
  163. $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : [];
  164. $appId = $newParams['app_id'] ?? '';
  165. $nonceStr = $newParams['nonce_str'] ?? '';
  166. $paySign = $newParams['pay_sign'] ?? '';
  167. $package = $newParams['package'] ?? '';
  168. $signType = $newParams['sign_type'] ?? '';
  169. $timeStamp = $newParams['time_stamp'] ?? '';
  170. $new = [
  171. 'id' => $gRechargeId,
  172. 'appId' => $appId,
  173. 'nonceStr' => $nonceStr,
  174. 'paySign' => $paySign,
  175. 'package' => $package,
  176. 'signType' => $signType,
  177. 'timeStamp' => $timeStamp,
  178. 'orderSn' => $customOrderSn,
  179. ];
  180. util::success($new);
  181. } elseif ($payWay == 1) {
  182. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  183. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  184. $params = [
  185. 'appid' => 'OP00002119',
  186. 'serial_no' => '018b08cfddbd',
  187. 'merchant_no' => $ghsShop->lklSjNo,
  188. 'term_no' => $ghsShop->lklB2BTermNo,
  189. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  190. 'lklCertificatePath' => $lklCertificatePath,
  191. ];
  192. $laResource = new Lakala($params);
  193. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/cash-pay-callback";
  194. $cashParams = [
  195. 'orderSn' => $customOrderSn,
  196. 'amount' => $totalFee,
  197. 'capitalType' => $capitalType,
  198. 'notifyUrl' => $notifyUrl,
  199. 'subject' => $subject,
  200. ];
  201. $response = $laResource->cashierPay($cashParams);
  202. if (isset($response['code']) == false || $response['code'] != '000000') {
  203. util::fail('支付失败了');
  204. }
  205. $url = $response['resp_data']['counter_url'] ? $response['resp_data']['counter_url'] : '';
  206. if (empty($url)) {
  207. util::fail('支付失败');
  208. }
  209. util::success(['url' => $url]);
  210. } else {
  211. util::fail('暂不支持的付款方式');
  212. }
  213. }
  214. }