wesmiler 3 月之前
父節點
當前提交
17c6dfc7dd

+ 2 - 1
addons/admin/src/config/setting.js

@@ -5,7 +5,8 @@ export default {
     version: '1.0',
     name: '后台管理系统',  // 项目名称
     loginName: '后台登录',  // 项目名称
-    baseURL: 'http://129.204.44.254:8001/',  // 本地接口地址
+    baseURL: 'http://127.0.5.26/',  // 本地接口地址
+    // baseURL: 'http://129.204.44.254:8001/',  // 本地接口地址
     signKey: 'dshApp&688', // 签名密钥
     whiteList: ['/login', '/forget'],  // 路由白名单(不需要登录的)
     keepAliveList: [],  // 需要缓存的组件名称

+ 1 - 4
addons/admin/src/views/dashboard/workplace.vue

@@ -167,14 +167,11 @@
           </div>
         </el-card>
       </el-col>
-    </el-row>
 
-    <!-- 商家、代理、提现统计 -->
-    <el-row :gutter="15">
       <el-col :md="6" :sm="6" :xs="12" v-if="!isStoreUser">
         <el-card shadow="hover" body-style="padding:0;">
           <div class="app-link-block" @click="$router.push('/store/store')">
-            <i class="app-link-icon el-icon-store" style="color: #67c23a;"></i>
+            <i class="app-link-icon el-icon-place" style="color: #67c23a;"></i>
             <div class="app-link-title countFont">{{ datas.stores.count || 0 }}</div>
             <div class="app-link-title">总商家数</div>
           </div>

+ 34 - 0
app/Http/Controllers/Api/v1/AccountController.php

@@ -32,6 +32,40 @@ class AccountController extends webApp
     }
 
     /**
+     * 充值套餐
+     * @return array
+     */
+    public function payMeal()
+    {
+        $params =request()->post();
+        $pageSize = request()->post('pageSize', 15);
+        $datas = AccountService::make()->getPayMealList($params, $pageSize);
+        if($datas){
+            return message(1010, true, $datas);
+        }else{
+            return message(1009, false);
+        }
+    }
+
+    /**
+     * 充值记录
+     * @return array
+     */
+    public function payLog()
+    {
+        $params =request()->post();
+        $pageSize = request()->post('pageSize', 15);
+        $params['type'] = 2;
+        $params['user_id'] = isset($params['user_id'])? $params['user_id'] : $this->userId;
+        $datas = AccountService::make()->getDataList($params, $pageSize);
+        if($datas){
+            return message(1010, true, $datas);
+        }else{
+            return message(1009, false);
+        }
+    }
+
+    /**
      * 余额明细
      * @return array
      */

+ 145 - 0
app/Services/Api/AccountService.php

@@ -12,8 +12,13 @@
 namespace App\Services\Api;
 
 use App\Models\AccountLogModel;
+use App\Models\PayMealsModel;
+use App\Models\PayOrdersModel;
 use App\Services\BaseService;
+use App\Services\PaymentService;
 use App\Services\RedisService;
+use Illuminate\Support\Facades\DB;
+use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions\F;
 
 /**
  * 交易管理-服务类
@@ -166,4 +171,144 @@ class AccountService extends BaseService
 
         return $data;
     }
+
+    /**
+     * 充值套餐
+     * @param $type
+     * @return array|mixed
+     */
+    public function getPayMealList($type)
+    {
+        $cacheKey = "caches:accounts:mealList_{$type}";
+        $datas = RedisService::get($cacheKey);
+        if($datas){
+            return $datas;
+        }
+
+        $datas = PayMealsModel::where(['type'=>$type,'status'=>1,'mark'=>1])
+            ->orderBy('sort','desc')
+            ->orderBy('id','asc')
+            ->get();
+        $datas = $datas? $datas->toAray() :[];
+        if($datas){
+            RedisService::set($cacheKey, $datas, rand(300,600));
+        }
+
+        return $datas;
+    }
+
+    /**
+     * 生活充值
+     * @param $userId 用户ID
+     * @param $params
+     * @return array|false
+     */
+    public function recharge($userId, $params)
+    {
+        $mealId = isset($params['id']) ? $params['id'] : 0; // 套餐ID
+        $account = isset($params['account']) ? $params['account'] : ''; // 充值账号/手机号
+        $cacheKey = "caches:members:pay:{$userId}_{$mealId}";
+        if (RedisService::get($cacheKey . '_lock')) {
+            $this->error = '请不要频繁提交~';
+            return false;
+        }
+
+        if(empty($account)){
+            $this->error = '请输入充值账号';
+            return false;
+        }
+
+        RedisService::set($cacheKey, ['date' => date('Y-m-d H:i:s')], rand(2, 3));
+        $mealInfo = PayMealsModel::where(['id' => $mealId, 'status' => 1, 'mark' => 1])
+            ->select(['id','product_id', 'money', 'type', 'discount', 'remark', 'status'])
+            ->first();
+        $money = isset($mealInfo['money']) ? floatval($mealInfo['money']) : 0;
+        $discount = isset($mealInfo['discount']) ? intval($mealInfo['discount']) : 0;
+        $mealType = isset($mealInfo['type']) && $mealInfo['type'] ? intval($mealInfo['type']) : 1;
+        $productId= isset($mealInfo['product_id']) ? $mealInfo['product_id'] : 0;
+        $remark= isset($mealInfo['remark']) ? $mealInfo['remark'] : '';
+        $price = $discount?round($money*$discount/100,2): $money;
+        if (empty($mealInfo)) {
+            $this->error = '该套餐不存在';
+            RedisService::clear($cacheKey . '_lock');
+            return false;
+        }
+
+        if ($price <= 0 || $money <= 0 || $productId<=0) {
+            $this->error = '该套餐参数错误';
+            RedisService::clear($cacheKey . '_lock');
+            return false;
+        }
+
+        $info = $this->model->where(['id' => $userId, 'mark' => 1])
+            ->select(['id', 'openid', 'mobile', 'status'])
+            ->first();
+        $openid = isset($info['openid']) ? $info['openid'] : '';
+        if (!$info || $info['status'] != 1) {
+            $this->error = 1045;
+            RedisService::clear($cacheKey . '_lock');
+            return false;
+        }
+
+        if (empty($openid)) {
+            $this->error = '用户参数错误,请重新授权登录后尝试~';
+            RedisService::clear($cacheKey . '_lock');
+            return false;
+        }
+
+        // 创建订单
+        $orderNo = get_order_num('PR');
+        $types = ['','话费充值','电费充值','燃气充值'];
+        $remark = isset($types[$mealType])? $types[$mealType] : '生活充值';
+        $order = [
+            'order_no' => $orderNo,
+            'user_id' => $userId,
+            'meal_id' => $mealId,
+            'product_id' => $productId,
+            'total' => $price,
+            'type' => $mealType,
+            'pay_total' => $price,
+            'account' => $account,
+            'discount' => $discount,
+            'create_time' => time(),
+            'remark' => $remark,
+            'status' => 1,
+            'mark' => 1
+        ];
+
+        DB::beginTransaction();
+        if (!$orderId = PayOrdersModel::insertGetId($order)) {
+            $this->error = '创建充值订单失败';
+            return false;
+        }
+
+        /* TODO 支付处理 */
+        $payOrder = [
+            'type' => 1,
+            'order_no' => $orderNo,
+            'pay_money' => $price,
+            'body' => $remark,
+            'openid' => $openid
+        ];
+
+        // 调起支付
+        $payment = PaymentService::make()->minPay($info, $payOrder, 'pay');
+        if (empty($payment)) {
+            DB::rollBack();
+            RedisService::clear($cacheKey . '_lock');
+            $this->error = PaymentService::make()->getError();
+            return false;
+        }
+
+        // 用户操作记录
+        DB::commit();
+        $this->error = '创建充值订单成功,请前往支付~';
+        RedisService::clear($cacheKey . '_lock');
+        return [
+            'order_id' => $orderId,
+            'payment' => $payment,
+            'total' => $payOrder['pay_money'],
+            'pay_type' => 10,
+        ];
+    }
 }

+ 5 - 0
routes/api.php

@@ -63,6 +63,11 @@ Route::prefix('v1')->middleware('web.login')->group(function() {
     Route::post('/account/withdraw', [\App\Http\Controllers\Api\v1\AccountController::class, 'withdraw']);
     Route::post('/account/balance', [\App\Http\Controllers\Api\v1\AccountController::class, 'balance']);
 
+    // 生活充值
+    Route::post('/account/payMeal', [\App\Http\Controllers\Api\v1\AccountController::class, 'payMeal']);
+    Route::post('/account/recharge', [\App\Http\Controllers\Api\v1\AccountController::class, 'recharge']);
+    Route::post('/account/payLog', [\App\Http\Controllers\Api\v1\AccountController::class, 'payLog']);
+
     // 订单列表
     Route::post('/order/index', [\App\Http\Controllers\Api\v1\OrderController::class, 'index']);
     Route::get('/order/info', [\App\Http\Controllers\Api\v1\OrderController::class, 'info']);