diff --git a/app/order/controller/TbRefund.php b/app/order/controller/TbRefund.php index c2d42bd..bca8a64 100644 --- a/app/order/controller/TbRefund.php +++ b/app/order/controller/TbRefund.php @@ -5,7 +5,7 @@ * @Author: kangkang * @Date: 2020-10-13 19:52:37 * @LastEditors: kangkang - * @LastEditTime: 2020-10-14 20:12:00 + * @LastEditTime: 2020-10-14 22:10:49 */ /* * @Descripttion: @@ -19,6 +19,7 @@ namespace app\order\controller; use app\order\model\TbRefund as RefundMOdel; +use app\order\model\User as UserModel; use enum\order\TbRefund as RefundEnum; use fastphp\base\Controller; @@ -105,14 +106,45 @@ class TbRefund extends Controller /** * @description: 处理退款 - * @param {type} - * @return {type} + * @param {type} + * @return {type} + * */ public function handle() { - $data = json_decode(file_get_contents("php://input"), true)['info']; + $data = json_decode(file_get_contents("php://input"), true)['row']; $id = $data['Id']; - dump($data); + $user = $this->userinfo; + $refund = new RefundMOdel; + $update_data['handle_user'] = $user['LoginName']; + + $refund_info = $refund->getOne(['Id'=>$id]); + + $userModel = new UserModel; + $user_info = $userModel->getOne(['LoginCode' => $refund_info['Phone']]); + //判断余额是否大于退款金额 + $returnOk = $user_info['RestAmount'] - $refund_info["RefundFee"]; + if($returnOk < 0){ + $return = [ + 'Code' => 30000, + 'msg' => '余额不足', + ]; + echo json_encode($return); + die; + } else { + $update_data['f_balance'] = $user_info['RestAmount']; + if ($refund->updateOne(['Id' => $id],$update_data)) { + $userModel->updateOne(['LoginCode' => $refund_info['Phone']],['RestAmount' => $returnOk]); + } + } + + + $return = [ + 'Code' => 30000, + 'msg' => '操作成功', + 'balance' => $update_data['f_balance'] + ]; + echo json_encode($return); } } diff --git a/app/order/model/User.php b/app/order/model/User.php new file mode 100644 index 0000000..cfe9cec --- /dev/null +++ b/app/order/model/User.php @@ -0,0 +1,19 @@ + [ 'http://www.juip.wyk', - 'http://admin.juip.wyk' + 'http://admin.juip.wyk', + 'http://www.juip.com', + 'http://juip.com', + 'http://hl957admin.juip.com', ], //支付宝 'alipay' => [ diff --git a/enum/order/TbRefund.php b/enum/order/TbRefund.php index 256fd11..6907b79 100644 --- a/enum/order/TbRefund.php +++ b/enum/order/TbRefund.php @@ -5,7 +5,7 @@ * @Author: kangkang * @Date: 2020-10-14 19:32:50 * @LastEditors: kangkang - * @LastEditTime: 2020-10-14 19:44:19 + * @LastEditTime: 2020-10-14 21:13:48 */ namespace enum\order; @@ -14,7 +14,7 @@ class TbRefund { //淘宝退款状态 public static $refundStatus = [ - 0 => '待处理', + 0 => '申请中', 1 => '已同意', 2 => '已拒绝', 3 => '已关闭', diff --git a/fastphp/base/Jwt.php b/fastphp/base/Jwt.php index 47e6747..5c6a2fd 100644 --- a/fastphp/base/Jwt.php +++ b/fastphp/base/Jwt.php @@ -34,7 +34,7 @@ class Jwt { * ] * @return bool|string */ - public static function getToken(array $payload) + public static function getToken($payload) { if(is_array($payload)) { @@ -53,7 +53,7 @@ class Jwt { * @param string $Token 需要验证的token * @return bool|string */ - public static function verifyToken(string $Token) + public static function verifyToken($Token) { $tokens = explode('.', $Token); if (count($tokens) != 3) @@ -95,7 +95,7 @@ class Jwt { * @param string $input 需要编码的字符串 * @return string */ - private static function base64UrlEncode(string $input) + private static function base64UrlEncode($input) { return str_replace('=', '', strtr(base64_encode($input), '+/', '-_')); } @@ -105,7 +105,7 @@ class Jwt { * @param string $input 需要解码的字符串 * @return bool|string */ - private static function base64UrlDecode(string $input) + private static function base64UrlDecode($input) { $remainder = strlen($input) % 4; if ($remainder) { @@ -122,7 +122,7 @@ class Jwt { * @param string $alg 算法方式 * @return mixed */ - private static function signature(string $input, string $key, string $alg = 'HS256') + private static function signature($input, $key, $alg) { $alg_config=array( 'HS256'=>'sha256' diff --git a/fastphp/base/Model.php b/fastphp/base/Model.php index 72e951d..63d4943 100644 --- a/fastphp/base/Model.php +++ b/fastphp/base/Model.php @@ -2,7 +2,7 @@ /* * @Author: your name * @Date: 2020-09-30 17:32:46 - * @LastEditTime: 2020-10-14 20:02:14 + * @LastEditTime: 2020-10-14 20:40:36 * @LastEditors: kangkang * @Description: In User Settings Edit * @FilePath: /phptest/fastphp/base/Model.php @@ -61,5 +61,14 @@ class Model extends Sql { return $this->field($fields)->where($where)->limit('1')->fetch(); } + /** + * @description: 更新一条数据 + * @param {type} + * @return {type} + */ + public function updateOne($where = [], $data = []) + { + return $this->where($where)->update($data); + } }