DSSHOP 功能-權(quán)限與側(cè)邊欄

2022-03-29 16:29 更新

說明

  • 項(xiàng)目通過后臺(tái)權(quán)限配置動(dòng)態(tài)實(shí)現(xiàn)側(cè)邊欄,無需自行修改代碼
  • 推薦通過插件的方式添加功能

添加權(quán)限

  • 先看下示例圖

jurisdiction_01

  • 第一步: “用戶管理” -> "權(quán)限管理" -> 添加一個(gè)頂級(jí)類目,如?demo?

jurisdiction_02

  • 第二步: 添加二級(jí)類目,上級(jí)類目選擇第一步添加的權(quán)限
  • 第三步: 添加三級(jí)類目,上級(jí)類目選擇第二步添加的權(quán)限
  • 第四步: 編輯 ?permission.js?文件,添加權(quán)限和對應(yīng)的模板路徑(一定要添加二級(jí)類目到?index?,這樣三級(jí)目錄才能正常訪問)

jurisdiction_03第五步: 添加權(quán)限文件,可復(fù)制一份文件,然后修改?list.vue?(列表),如果存在詳情頁,請?zhí)砑?components?目錄

jurisdiction_04

示例代碼:

public function weixinPayment($body,$fee,$openid,$trade_type='JSAPI'){
    $number= orderNumber();
    $config = config('wechat.payment.default');
    $config['notify_url'] = request()->root().'/api/v1/app/paymentNotify';
    $app = Factory::payment($config);
    $result = $app->order->unify([
        'body' => $body,
        'out_trade_no' => $number,
        'total_fee' => $fee,
        'trade_type' => $trade_type,
        'openid' => $openid,
    ]);
    $return =[
        'result'=>'error',
        'msg'=>'支付異常,請聯(lián)系管理員'
    ];
    if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
        $prepayId = $result['prepay_id'];
        $config = $app->jssdk->sdkConfig($prepayId);
        $return =[
            'result'=>'ok',
            'msg'=>$config,
            'number'=>$number
        ];
    }
    if ($result['return_code'] == 'FAIL' && array_key_exists('return_msg', $result)) {
        $return =[
            'result'=>'error',
            'msg'=>$result['return_msg']
        ];
    }
    return $return;
}

返回參數(shù)

屬性 類型 默認(rèn)值 必填 說明
result string 返回狀態(tài),成功:ok 失敗:error
code string 錯(cuò)誤碼,當(dāng)result為error時(shí)需填寫
msg string 錯(cuò)誤原因,當(dāng)result為error時(shí)需填寫
number string 訂單號(hào),當(dāng)result為ok時(shí)需填寫

新加支付說明

  • 首先得先確認(rèn)標(biāo)識(shí),在前端支付頁,添加支付平臺(tái),并設(shè)置唯一標(biāo)識(shí)
  • 后臺(tái)App\Models\v1\MiniProgram復(fù)制一份weixinPayment方法,將weixin換成上一步設(shè)置的標(biāo)識(shí)
  • 完成支付接口對接,按返回參數(shù)返回即可

新加支付類型說明

  • 首先在前端添加支付類型,如充值,然后設(shè)置唯一標(biāo)識(shí)
  • 后臺(tái)App\Http\Controllers\v1\Element\WeChatController在unifiedPayment方法中添加case,把標(biāo)識(shí)填寫進(jìn)去,參考如下代碼

switch ($request->type){
    case 'goodsIndent':  //商品訂單支付
        $reutn = (new GoodIndent())->payment($request);
        break;
}

  • 在對應(yīng)的Models中添加業(yè)務(wù)代碼,例如

public function payment($request){
    $openid=$request->header('openid');
    $GoodIndent=static::with(['goodsList'])->find($request->id);
    $body='對訂單:'.$GoodIndent->identification.'的付款';
    $fee=$GoodIndent->total;
    $trade_type="JSAPI";
    $MiniProgram = new MiniProgram();
    $payment=$MiniProgram->payment($request->platform,$body,$fee,$openid,$trade_type);
    if($payment['result']== 'error'){
        return $payment;
    }
    $PaymentLog = new PaymentLog();
    $PaymentLog->name = $body;
    $PaymentLog->number = $payment['number'];
    $PaymentLog->money = $GoodIndent->total;
    $PaymentLog->pay_id = $request->id; //訂單ID
    $PaymentLog->pay_type = 'App\Models\v1\GoodIndent';
    $PaymentLog->state = PaymentLog::PAYMENT_LOG_STATE_CREATE;
    $PaymentLog->save();
    //庫存判斷
    foreach ($GoodIndent->goodsList as $indentCommodity){
        $Good=Good::select('id','is_inventory','inventory')->find($indentCommodity['good_id']);
        if($Good && $Good->is_inventory == Good::GOOD_IS_INVENTORY_FILM){ //付款減庫存
            if(!$indentCommodity['good_sku_id']){ //非SKU商品
                if($Good->inventory-$indentCommodity['number']<0){
                    return [
                        'result'=>'error',
                        'msg'=>'存在庫存不足的商品,請重新購買'
                    ];
                }
                $Good->inventory = $Good->inventory-$indentCommodity['number'];
                $Good->save();
            }else{
                $GoodSku=GoodSku::find($indentCommodity['good_sku_id']);
                if($GoodSku->inventory-$indentCommodity['number']<0){
                    return [
                        'result'=>'error',
                        'msg'=>'存在庫存不足的SKU商品,請重新購買'
                    ];
                }
                $GoodSku->inventory = $GoodSku->inventory-$indentCommodity['number'];
                $GoodSku->save();
            }
        }
    }
    return $payment;
}


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)