144 lines
5.3 KiB
PHP
144 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace Yunshop\Decorate\frotend;
|
|
|
|
use app\common\components\ApiController;
|
|
use app\common\models\Address;
|
|
use Yunshop\Decorate\models\DecorateAddressModel;
|
|
use Yunshop\Decorate\models\DecorateModel;
|
|
use Yunshop\Decorate\common\services\IndexPageService;
|
|
use Illuminate\Support\Facades\DB;
|
|
use app\common\helpers\Cache;
|
|
use Yunshop\Sign\Common\Services\SetService;
|
|
use Yunshop\Sign\Frontend\Services\SignAwardService;
|
|
use Yunshop\Sign\Frontend\Modules\Sign\Controllers\SignController;
|
|
|
|
class DecorateApiController extends ApiController
|
|
{
|
|
/**
|
|
* 获取页面列表
|
|
* @param int $pageID 页面id
|
|
* @return json
|
|
*/
|
|
public function getPage()
|
|
{
|
|
$pageId = \YunShop::request()->decorate_id; //装修ID
|
|
$page = isset(\YunShop::request()->decorate_page) ? \YunShop::request()->decorate_page : 0; //分页数
|
|
|
|
$decorateModel = Cache::get('decorate_' . $pageId);
|
|
if (!$decorateModel) {
|
|
$where = ['id' => $pageId, 'is_deleted' => 0, 'page_scene' => $page_scene];
|
|
$decorateModel = DecorateModel::getList(1, $where, '*', false); //获取单条装修数据
|
|
|
|
if (!$decorateModel) {
|
|
return $this->errorJson('error');;
|
|
}
|
|
|
|
$decorateModel = $decorateModel->toArray();
|
|
Cache::put('decorate_' . $pageId, $decorateModel, 4200);
|
|
}
|
|
// 装修组件模型(处理装修组件数据)
|
|
$decorate = $decorateModel;
|
|
$pageService = new IndexPageService($decorateModel);
|
|
$decorate = $pageService->getPageDate($page);
|
|
$decorate['datas'] = json_decode($decorate['datas']);
|
|
|
|
|
|
return $this->successJson('success', $decorate);
|
|
}
|
|
|
|
/**
|
|
* 获取签到信息
|
|
*/
|
|
public function getSign()
|
|
{
|
|
//判断插件是否开启
|
|
if (!app('plugins')->isEnabled('sign')) {
|
|
return $this->errorJson('签到插件未开启');
|
|
}
|
|
|
|
$set = SetService::getSignSet();
|
|
if ($set['sign_status'] != 1) {
|
|
return $this->errorJson('签到插件未开启');
|
|
}
|
|
|
|
$awardService = new SignAwardService();
|
|
|
|
$params = [
|
|
'nickname' => $awardService->signModel->member->realname ?: $awardService->signModel->member->nickname, //用户昵称
|
|
'cumulative_number' => $awardService->signModel->cumulative_name, //连续签到天数
|
|
'sign_status' => $awardService->signModel->sign_status, //是否签到
|
|
'success_link' => $set['success_link'], //签到成功链接
|
|
'sign_name' => empty($set['sign_name']) ? '签到' : $set['sign_name'], //签到名称
|
|
'award_point' => intval($set['award_point']), //积分数量
|
|
// 'award_coupon_name' => $set['award_coupon_name'], //优惠券名称
|
|
'award_coupon_num' => intval($set['award_coupon_num']), //优惠券数量
|
|
// 'cumulative' => [], //连续签到奖励
|
|
'love_name' => '', //爱心值名称
|
|
'award_love_max' => '', //爱心值最大数量
|
|
'award_love_min' => '', //爱心值最小数量
|
|
];
|
|
|
|
if ($params['sign_status']) {
|
|
//获取今天0时的时间戳
|
|
$dayTime = strtotime(date("Y-m-d"), time());
|
|
$signLog = \Yunshop\Sign\Frontend\Models\SignLog::select(['award_love'])->where('created_at', '>', $dayTime)->first()->toArray();
|
|
$params['get_love'] = isset($signLog['award_love']) ? $signLog['award_love'] : 0;
|
|
}
|
|
|
|
if (app('plugins')->isEnabled('love')) {
|
|
$love = \Yunshop\Love\Common\Services\SetService::getLoveSet(); //爱心值设置
|
|
$params['love_name'] = empty($love['name']) ? '爱心值' : $love['name'];
|
|
$params['award_love_max'] = $set['award_love_max'];
|
|
$params['award_love_min'] = $set['award_love_min'];
|
|
}
|
|
|
|
foreach ($set['cumulative'] as $key => $value) //计算连续签到奖励
|
|
{
|
|
if ($params['sign_status']) {
|
|
$days = intval($params['cumulative_number']);
|
|
} else {
|
|
$days = intval($params['cumulative_number']) + 1;
|
|
}
|
|
|
|
if ($value['days'] == $days) {
|
|
if ($value['award_type'] == '1') {
|
|
$params['award_point'] += $value['award_value'];
|
|
} elseif ($value['award_type'] == '2') {
|
|
$params['award_coupon_num'] += $value['award_value'];
|
|
}
|
|
$params['cumulative'] == $value;
|
|
}
|
|
}
|
|
|
|
return $this->successJson('success', $params);
|
|
|
|
}
|
|
|
|
/**
|
|
* 获取有装修的城市
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function getCity()
|
|
{
|
|
$city_ids = DecorateAddressModel::uniacid()
|
|
->where('city_id', '>', 0)
|
|
->pluck('city_id')
|
|
->unique();
|
|
|
|
$address_list = Address::select('areaname as full_address', 'id')->whereIn('id', $city_ids)->get();
|
|
|
|
$city_list = $address_list->groupBy(function ($address) {
|
|
return DecorateAddressModel::getFirstCharter($address->full_address);
|
|
})->map(function ($address, $initial) {
|
|
return [
|
|
'item' => $address,
|
|
'title' => $initial . ''
|
|
];
|
|
})->values();
|
|
$data['initials'] = $city_list;
|
|
return $this->successJson('ok', $data);
|
|
}
|
|
|
|
}
|