国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

求大神們指點(diǎn)我的屎山代碼,給出優(yōu)化思路!謝謝!

andyzu
    public function getVenueOrderinfoFromType(Request $request, int $type){
        // 獲取 TokenVerifyMiddleware 里已經(jīng)解密好的用戶數(shù)據(jù)
        $userinfo = $request->data;

        $param = [
            'page' => $request->input('page', 1),
            'perPage' => $request->input('perPage', 10),
            'mobile' => $request->get('mobile'),
            'venueinfo_type' => $request->get('venueinfo_type'),
            'type' => $type,
        ];

        // 進(jìn)行參數(shù)校驗(yàn)
        $validate = new GetVenueOrderinfoFromTypeValidate();
        if (!$validate->check($param)) {
            return json($validate->getError());
        }

        // 去除傳遞過(guò)來(lái)參數(shù)的前后空格
        $param = array_map('trim', $param);
        if ($param['mobile'] != $userinfo['mobile']){
            return json([
                // 'HTTP_FAIL_REQUEST' => [200112, '非法請(qǐng)求,請(qǐng)確認(rèn)請(qǐng)求者身份。'],
                'code' => config('myconfig.statusCode.HTTP_FAIL_REQUEST')[0],
                'msg' => config('myconfig.statusCode.HTTP_FAIL_REQUEST')[1],
                'data' => [],
            ]);
        }

        // 從 redis 里獲取 待付款的數(shù)據(jù)
        if ($param['type'] == 0){
            Redis::select(1);
            $redis_key = $param['mobile'].':*';
            $redis_keys = Redis::keys($param['mobile'].':*');
            $data = [];
            foreach ($redis_keys as $key) {
                $data[$key] = json_decode(Redis::get($key),true);
                $data[$key]['button']['支付'] = true;
            }

            return json([
                // 'HTTP_OK' => [200100, '請(qǐng)求成功'],
                'code' => config('myconfig.statusCode.HTTP_OK')[0],
                'msg' => config('myconfig.statusCode.HTTP_OK')[1],
                'data' => $data,
            ]);
        }

        $venueOrderinfo = Db::table('venue_orderinfo')
            ->where('type', '=', $param['type'])
            ->where('venueinfo_type', '=', $param['venueinfo_type'])
            ->whereNull('deleted_at')
            ->get()
            ->forPage($param['page'], $param['perPage'])
            ->map(function ($res) {
                $res->order_time_fieldTrans = date('Y-m-d H:i:s', $res->order_time);
                $res->type_fieldTrans = trans('venue_orderinfo_type.' . $res->type);
                // 訂單類型(0=待支付,1=待入場(chǎng),2=已完成,3=已退款)
                if ($res->type == 0){
                    $res->button[0]['title'] = '支付';
                    $res->button[0]['is_enabled'] = true;
                    $res->button[0]['url'] = 'api/v1/wechatpay/payOrderinfo';
                    $res->button[0]['type'] = $res->type;
                }

                if ($res->type == 1){
                    $res->button[0]['title'] = '查看二維碼';
                    $res->button[0]['is_enabled'] = true;
                    $res->button[0]['url'] = 'api/v1/wechatpay/chakanerweima';
                    $res->button[0]['type'] = $res->type;

                    // 查詢退款的時(shí)限
                    $refundinfo = Db::table('refundinfo')
                        ->whereNull('deleted_at')
                        ->first();
                    $refund_time = $refundinfo->refund_time * 3600;     // 單位是小時(shí) * 3600 就是秒數(shù)
                    // 可以退款的最后時(shí)限 UNIX時(shí)間戳
                    $is_refund_time = $res->order_time - $refund_time;
                    // 如果當(dāng)前時(shí)間小于退款時(shí)間,那說(shuō)明可以退款,否則不能退款
                    if (time() < $is_refund_time){
                        $res->button[1]['title'] = '查看二維碼';
                        $res->button[1]['is_enabled'] = true;
                        $res->button[1]['url'] = 'api/v1/wechatpay/tuikuan';
                        $res->button[1]['type'] = $res->type;

                    }else{
                        $res->button[1]['title'] = '已過(guò)退款時(shí)限';
                        $res->button[1]['is_enabled'] = false;
                    }

                }
                // TODO 還得在后臺(tái)上傳電子發(fā)票
                if ($res->type == 2){
                    $res->button[0]['title'] = '開(kāi)發(fā)票';
                    $res->button[0]['is_enabled'] = true;
                    $res->button[0]['url'] = '';
                    $res->button[0]['type'] = $res->type;
                }

                if ($res->type == 3){
                    $res->button[0]['title'] = '稍后討論';
                    $res->button[0]['is_enabled'] = true;
                    $res->button[0]['url'] = 'api/v1/wechatpay/shaohoutaolun';
                    $res->button[0]['type'] = $res->type;
                }
                return $res;
            })->toArray();

        $venueOrderinfo = array_values($venueOrderinfo) ?? [];

        return json([
            // 'HTTP_OK' => [200100, '請(qǐng)求成功'],
            'code' => config('myconfig.statusCode.HTTP_OK')[0],
            'msg' => config('myconfig.statusCode.HTTP_OK')[1],
            'data' => $venueOrderinfo,
        ]);
    }
1327 5 1
5個(gè)回答

三冬四夏

寫(xiě)的不錯(cuò)啊,能看懂,這證明它并不是屎山屙

胡桃
// ...
Redis::select(1);
$redis_key = $param['mobile'].':*'; // 只使用一次的變量沒(méi)有必要單獨(dú)賦值,而且這個(gè)`$redis_key`后面沒(méi)用到
$redis_keys = Redis::keys($param['mobile'].':*');
// ...

// 循環(huán)使用get是一大忌,建議改成mget
$data = array_combine($redis_keys, Redis::mget($redis_keys));
array_walk($data, function (&$v, $k) {
    $v = json_decode($v, true);
    $v['button']['支付'] = true;
});
  • andyzu 2023-12-07

    $redis_key = $param['mobile'].':*'; 這個(gè)是疏忽,下次一定注意,的確沒(méi)用到。

  • andyzu 2023-12-07

    array_walk 我學(xué)會(huì)了。謝謝大神!

tanhongbin

兄弟你這代碼 不錯(cuò)了,結(jié)構(gòu)清晰 邏輯清晰,還有簡(jiǎn)單的注釋,你是真沒(méi)見(jiàn)過(guò)屎山代碼呀

  • andyzu 2023-12-07

    大神,我覺(jué)得我寫(xiě)的好屎,因?yàn)槲腋杏X(jué)一個(gè)方法里太多內(nèi)容了,我覺(jué)得閱讀起來(lái)復(fù)雜。

Chance
  1. $userinfo 的數(shù)據(jù)可以放在 Context 中,定義幾個(gè)助手函數(shù)來(lái)獲取 userInfo、userId、userMobile 等數(shù)據(jù)

  2. $param 不必一個(gè)個(gè)構(gòu)建,可以直接 $param = $request->all()

  3. statusCode 不要放在配置中,可以用枚舉或者類常量,這樣子會(huì)有代碼提示

  4. 定義并調(diào)用一個(gè)統(tǒng)一的返回方法,可以只傳 code,在方法里通過(guò) code 獲取對(duì)應(yīng)的 message

  • andyzu 2023-12-20

    感謝,2 里的 ->all() 方法,是 get 和 post 都獲取,我這淺薄的知識(shí)感覺(jué)不安全。

kspade

真強(qiáng)啊 我只會(huì) find 然后 if create 或者 update 逐條 操作

  • 暫無(wú)評(píng)論
年代過(guò)于久遠(yuǎn),無(wú)法發(fā)表回答
??