【正版多商户】小程序拼团之商家接口设计

写作背景:最近在写小程序拼团多商家版,从原先单商户改造。现在需要考虑在商品详情中,展示商家数据。那接口如何设计呢,是包含在商品详情,还是单独涉及一个商家详情的接口,简单数据包含复杂的数据需要调接口完成。

效果图:
【正版多商户】小程序拼团之商家接口设计_第1张图片

路由:

Route::group(['prefix' => 'api/v1.0', 'namespace' => "Api\\Air\\v_1_0"], function () {
    # ############### start merchant ###############
    Route::get('merchant/{merchant_id}',                         'MerchantController@detail');
    # ############### end merchant ###############
});

代码:


// +----------------------------------------------------------------------
namespace App\Http\Controllers\Api\Air\v_1_0;
use App\Http\Controllers\Core\ApiController;
use Illuminate\Support\Facades\DB;

class MerchantController extends ApiController {
    public function detail($merchant_id) {
        $MerchantDb = DB::table('merchant');
        $GoodsDb = DB::table('goods');
        $merchant = $MerchantDb->where('merchant_id',$merchant_id)->where('in_selling',1)->select("merchant_logo", "merchant_name", "merchant_id")->first();

        if(!$merchant) {
            return json_encode(array('result'=>'fail','error_code'=>41002,'error_info'=>'商家已下架或不存在'));
        }

        $merchant["sell_count"] = $GoodsDb->where("merchant_id", $merchant_id)->sum("sell_count");
        echo json_encode(['result'=>'ok','merchant'=>$merchant]);
    }
}

小程序代码:


            
                
                
                    {{ merchantData.merchant_name }}
                    已团{{ merchantData.sell_count }}件
                
            

            进店逛逛
        
.merchant-details-logo {
    width: 88rpx;
    height: 88rpx;
    margin-right: 16rpx;
}

.merchant-details {
    margin-top: 20rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    padding: 20rpx;
}

.merchant-details-base {
    display: flex;
}

.merchant-details-name {
    font-size: 30rpx;
    font-weight: 700;
    color: #151516;
}

.merchant-details-title {
    color: #58595b;
    font-size: 26rpx;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.merchant-details-button {
    border: 1px solid #9c9c9c;
    font-size: 30rpx;
    color: #151516;
    border-radius: 6rpx;
    text-align: center;
    height: 56rpx;
    width: 152rpx;
    display: flex;
    align-items: center;
    justify-content: center;
}

你可能感兴趣的:(laravel小程序)