Commit bf5e2ad1 by 杨树贤

案例相关接口

parent 4e7bf079
<?php
namespace App\Http\Controllers;
use App\Services\CaseService;
use Illuminate\Http\Request;
//案例
class CaseController extends Controller
{
public function index(Request $request, CaseService $service)
{
$page = $request->get('page');
$pageSize = $request->get('pageSize');
$list = $service->getCaseList($page, $pageSize);
return $this->Export(0, 'ok', ['data' => $list]);
}
public function show(Request $request, CaseService $service)
{
$id = $request->get('id');
$case = $service->getCase($id);
return $this->Export(0, 'ok', ['data' => $case]);
}
}
\ No newline at end of file
......@@ -13,56 +13,6 @@ class Controller extends BaseController
//请求参数错误
const INVALID_PARAMETER = 109004;
//用户无法进行兑换,未认证
const CAN_NOT_EXCHANGE = 109005;
//红包码无效
const INVALID_CODE = 109006;
//已经兑换过红包码,不能再兑换
const EXCHANGED_CODE = 109007;
//自己不能助力自己
const CAN_NOT_ASSIST_MYSELF = 109008;
//不能助力了(助力人数已满或者用户已经助力过)
const CAN_NOT_ASSIST = 109009;
//助力类型不能是话费的兑换
const EXCHANGE_TYPE_ERROR = 109011;
//助力人数不足
const ASSIST_NO_ENOUGH = 109012;
//不能助力了(助力人数已满或者用户已经助力过)
const CAN_NOT_INVITE_MYSELF = 109010;
const EXCHANGED_TODAY = 109100;
//这个是服务那边返回的错误码,代表已经超出了每日每人可领取的对应项的数额(比如每人每天只能签到一次)
const INTEGRAL_LIMIT = 509000;
//下面的都是这个接口项目的错误码
//签到
const CHECK_IN_FAIL = 509001;
//报价
const OFFER_FAIL = 509002;
//上传商品
const UPLOAD_GOODS_FAIL = 509003;
//添加好友邀请失败
const INVITE_FAIL = 509004;
//分享失败
const SHARE_FAIL = 509005;
//红包兑换失败
const EXCHANGE_CODE_FAIL = 509006;
//好友助力失败
const ASSIST_FAIL = 509007;
//确认兑换失败
const EXCHANGE_CONFIRM_FAILED = 509008;
public function Export($Errcode = 0, $ErrMsg = '', $dataArr = [])
{
......
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
//案例
class CaseController extends Controller
{
public function index(Request $request)
{
//因为是获取案例,所以要制定一个ID类型
$caseArticleArctypeId = 10;
}
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class ArctypeModel extends Model
{
protected $table = 'arctype';
public $timestamps = false;
public function articles()
{
return $this->hasMany(ArticleModel::class, 'top_type_id', 'type_id');
}
public function getFaqList()
{
$faqTypeId = config('config.faq_type_id');
}
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class ArticleAddonModel extends Model
{
protected $table = 'article_addon';
public $timestamps = false;
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Support\Facades\DB;
class ArticleModel extends BaseModel
{
protected $table = 'article';
public $timestamps = false;
public function article_tag()
{
return $this->hasMany(ArticleTagModel::class, 'art_id', 'art_id');
}
public function article_addon()
{
return $this->hasOne(ArticleAddonModel::class, 'art_id', 'art_id');
}
public function type()
{
return $this->belongsTo(ArctypeModel::class, 'type_id', 'type_id');
}
public function top_type()
{
return $this->belongsTo(ArctypeModel::class, 'top_type_id', 'type_id');
}
//获取案例列表
public function getCaseList($map, $page, $pageSize)
{
$field = [
'art_id',
'title',
'litpic',
'type_id',
'top_type_id',
'description',
'status',
'writer',
'banner_title',
'banner_img',
'publish_time',
];
$data = $this->select($field)
->with([
'article_tag' => function ($query) {
$query->select(['id', 'art_id', 'tag', 'url']);
},
'type' => function ($query) {
$query->select(['type_id', 'type_name']);
},
'top_type' => function ($query) {
$query->select(['type_id', 'type_name']);
},
])
->where($map)->page($page, $pageSize)
->orderBy('art_id', 'desc')
->get()->toArray();
return $data;
}
public function getCase($id)
{
$field = [
'art_id',
'title',
'litpic',
'type_id',
'top_type_id',
'description',
'status',
'writer',
'banner_title',
'banner_img',
'publish_time',
];
$data = $this->select($field)
->with([
'article_tag' => function ($query) {
$query->select(['id', 'art_id', 'tag', 'url']);
},
'type' => function ($query) {
$query->select(['type_id', 'type_name']);
},
'top_type' => function ($query) {
$query->select(['type_id', 'type_name']);
},
'article_addon',
])
->where('art_id', $id)
->first()
->toArray();
return $data;
}
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class ArticleTagModel extends Model
{
protected $table = 'article_tag';
public $timestamps = false;
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class BaseModel extends Model
{
public function scopePage($query, $page, $pageSize)
{
$page = $page ?: 1;
$pageSize = $pageSize ?: 10;
$pageSize = $pageSize < 50 ? $pageSize : 50;
$query->limit($pageSize)->offset(($page - 1) * $pageSize);
}
}
\ No newline at end of file
<?php
namespace App\Services;
use App\Model\ArticleModel;
class CaseService extends BaseService
{
public function getCaseList($page, $pageSize)
{
//因为是获取案例,所以要指定一个ID类型
$caseTypeId = 10;
$map = ['top_type_id' => $caseTypeId];
$model = new ArticleModel();
$list = $model->getCaseList($map, $page, $pageSize);
$list = $this->transform($list);
return $list;
}
private function transform($data)
{
foreach ($data as $key => &$item) {
$item['type'] = array_get($item['type'], 'type_name', '');
$item['top_type'] = array_get($item['top_type'], 'type_name', '');
$item['publish_time'] = $item['publish_time'] ? date('Y-m-d H:i:s', $item['publish_time']) : 0;
$item['brand'] = $item['writer'];
unset($item['writer']);
}
unset($item);
return $data;
}
public function getCase($id)
{
$model = new ArticleModel();
$case = $model->getCase($id);
$case = $this->caseTransform($case);
return $case;
}
private function caseTransform($item)
{
$item['type'] = array_get($item['type'], 'type_name', '');
$item['top_type'] = array_get($item['top_type'], 'type_name', '');
$item['publish_time'] = $item['publish_time'] ? date('Y-m-d H:i:s', $item['publish_time']) : 0;
$item['brand'] = $item['writer'];
unset($item['writer']);
return $item;
}
}
\ No newline at end of file
<?php
namespace App\Services;
class CodeService
{
//回复报价需要添加流水
public function addCode($map = [])
{
$url = config('website.BaseUrl') . '/codes/add';
$result = reportCurl($url, $map, true);
$result = json_decode($result, true);
return $result;
}
}
\ No newline at end of file
......@@ -15,7 +15,14 @@ $router->addRoute(['GET', 'POST'], '/', function () use ($router) {
return $router->app->version();
});
$router->addRoute(['GET', 'POST'], '/test','CheckInController@test');
$router->addRoute(['GET', 'POST'], '/test', 'CheckInController@test');
//第一个版本不需要登陆,所以不走中间件
$router->group(['middleware' => []], function () use ($router) {
$router->addRoute(['GET', 'POST'], '/case/list', 'CaseController@index');
$router->addRoute(['GET', 'POST'], '/case/info', 'CaseController@show');
$router->addRoute(['GET', 'POST'], '/faq/list', 'FaqController@index');
});
$router->group(['middleware' => ['web', 'login']], function () use ($router) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment