| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\common\controllers;
- use app\models\AccountLog;
- use app\models\Cash;
- use app\models\Lg;
- use app\models\LocalDeliveryCash;
- use app\models\LocalDeliveryCourier;
- use app\models\Md;
- use app\models\ReOrder;
- use app\models\Shop;
- use app\models\ShopShare;
- use app\models\User;
- use app\modules\common\models\NotifyForm;
- use app\utils\LgApi;
- use app\utils\OrderNo;
- use app\utils\Wechat\Wechat;
- use app\utils\Wechat\WechatProfit;
- use app\utils\Wechat\WechatShare;
- use EasyWeChat\Kernel\Exceptions\Exception;
- use EasyWeChat\Kernel\BaseClient;
- use yii\web\Controller;
- use app\utils\IotCloudHelper;
- use app\models\Store;
- use app\models\OrderUnion;
- use app\models\Order;
- use app\models\WechatConfig;
- class LgCashNotifyController extends Controller
- {
- /**
- * 入口文件
- * @throws \Exception
- */
- public function actionIndex() {
- $store_id = get_params('store_id');
- $res = file_get_contents('php://input');
- $data = json_decode($res,true);
- $store = Store::findOne($store_id);
- $data = json_decode(self::decrypt($data['bizContent'],$store->lg_key),true);
- $orderNoHead = substr($data['outTradeNo'], 0, 3);
- if ($orderNoHead == OrderNo::ORDER_LOCAL_CASH){
- $cash = LocalDeliveryCash::find()->where(['order_no'=>$data['outTradeNo'],'status'=>6])->one();
- }else{
- $cash = Cash::find()->where(['order_no'=>$data['outTradeNo'],'status'=>6])->one();
- }
- if (!$cash){
- }
- if ($data['status'] == 300){
- //成功
- $cash->status = 2;
- $cash->updated_at = time();
- $cash->save();
- }
- if ($data['status'] == 999){
- //失败
- $cash = Cash::find()->where(['order_no'=>$data['outTradeNo']])->one();
- $cash->status = 3;//灵工提现失败
- $cash->updated_at = time();
- $cash->lg_refuse_desc = $data['msg'];
- if ($cash->save()){
- if ($cash->status == 3) {
- return;
- }
- //如果是骑手 把提现的钱返还
- if ($orderNoHead == OrderNo::ORDER_LOCAL_CASH){
- $courier = LocalDeliveryCourier::findOne(['saas_user_id' => $cash->saas_user_id]);
- $courier->money += $cash->price;
- $courier->save();
- }
- $user = User::findOne(['id' => $cash->user_id]);
- //把提现的钱返还
- if ($cash->cash_type == 0) {
- $user->price += $cash->price;
- $user->save();
- }elseif ($cash->cash_type == 17) {//全域提现
- $user->global_money += $cash->price;
- $user->save();
- } elseif ($cash->cash_type == Cash::IS_CASH_TYPE_BALANCE) {
- $saveLog = AccountLog::saveLog($cash->user_id, $cash->price, AccountLog::TYPE_BALANCE, AccountLog::LOG_TYPE_INCOME, 0, 0, "余额提现被驳回,单号:{$cash->order_no}");
- if (!$saveLog) {
- debug_log('网络异常,账户保存失败');
- }
- } elseif ($cash->cash_type == Cash::IS_CASH_TYPE_AREA_AGENT || $cash->cash_type == 3 ) {
- $user->price += $cash->price;
- $user->save();
- }elseif ($cash->cash_type == 2) {
- $md_info = Md::find()->where(['user_id' => $cash->user_id])->one();
- $md_info->cash_profit += $cash->price;
- $md_info->save();
- }elseif ($cash->cash_type == Cash::IS_CASH_TYPE_MCH) {
- $saveLog = \app\models\MchAccountLog::saveLog($cash->mch_id, $cash->user_id, $cash->price, AccountLog::LOG_TYPE_INCOME, 0, '', "提现被驳回,单号:{$cash->order_no}", 0, 0);
- if ($saveLog['code']) {
- debug_log($saveLog);
- }
- }
- }
- }
- }
- public static function decrypt($encryptData,$key){
- $privateKey = openssl_pkey_get_private(self::formatterPrivateKey($key));
- $privateKey or die('密钥不可用');
- $decryptData = '';
- $crypto = '';
- $ed = str_split(base64_decode($encryptData),256);
- foreach ($ed as $chunk) {
- if(openssl_private_decrypt($chunk, $decryptData, $privateKey)){
- $crypto .= $decryptData;
- }else{
- die('解密失败');
- }
- }
- return $crypto;
- }
- /**
- * 格式化私钥
- * @param $priKey string 私钥
- * @return string
- */
- public static function formatterPrivateKey($priKey)
- {
- $res = "-----BEGIN RSA PRIVATE KEY-----\n" .
- wordwrap($priKey, 64, "\n", true) .
- "\n-----END RSA PRIVATE KEY-----";
- return $res;
- }
- }
|