bztang-admin/plugins/weight-value/src/admin/IndexController.php

192 lines
6.4 KiB
PHP

<?php
namespace Yunshop\WeightValue\admin;
use app\common\components\BaseController;
use app\common\helpers\PaginationHelper;
use app\common\models\Order;
use Illuminate\Support\Facades\DB;
use Yunshop\NewPoster\models\Poster;
use Yunshop\TeamDividend\models\TeamDividendAgencyModel;
use Yunshop\TeamDividend\models\TeamDividendLevelModel;
use Yunshop\TeamDividend\models\Uplog;
use Yunshop\WeightValue\models\WeightValue;
use Yunshop\WeightValue\models\WeightValueLog;
use app\common\facades\Setting;
use app\common\helpers\Url;
class IndexController extends BaseController{
/**
* Common: 进入权重值列表
* Author: wu-hui
* Time: 2023/10/12 15:40
* @return array|string
* @throws \Throwable
*/
public function index(){
//参数获取
$showType = request()->input('show_type','show_detail');
// 获取列表信息
$data = [
'show_type' => $showType,
'level_list' => TeamDividendLevelModel::getAll(['id','level_name'])
];
return view('Yunshop\WeightValue::index.index',$data)->render();
}
/**
* Common: 变更记录 - 变更记录明细
* Author: wu-hui
* Time: 2023/10/24 10:25
* @return array|\Illuminate\Http\JsonResponse|string
* @throws \Throwable
*/
public function changeRecord(){
// 参数获取
$memberId = (int)request()->input('member_id');
$levelId = (int)request()->input('level_id');
$isGet = (int)request()->input('is_get');
$search = request()->input('search');
if($isGet){
// 获取变更记录
$field = [
'id',
'member_id',
'team_dividend_agency_level_id',
'change_type',
'change_quantity',
'change_front',
'change_after',
'remark',
'created_at'
];
$result = WeightValueLog::getList(10,$search,$field);
// 根据经销商等级id分组 根据id大小排序 获取排序序号
$group = WeightValue::uniacid()->groupBy('team_dividend_agency_level_id')->pluck('team_dividend_agency_level_id');
$group = $group ? $group->toArray() : [];
sort($group);
$group = array_flip($group);
// 循环处理数据
foreach($result['data'] as &$item){
$item['sort'] = $group[(int)$item['team_dividend_agency_level_id']];
}
return $this->successJson('success',[
'current_page' => $result['current_page'],
'data' => $result['data'],
'last_page' => $result['last_page'],
]);
}
return view('Yunshop\WeightValue::index.change_record',[
'member_id' => $memberId,
'level_id' => $levelId,
'is_get' => $isGet,
])->render();
}
/**
* Common: 变更记录 - 根据用户及等级分组统计
* Author: wu-hui
* Time: 2023/10/24 10:27
* @return \Illuminate\Http\JsonResponse
*/
public function changeGroupRecord(){
// 参数获取
$pageSize = request()->input('page_size',10);
$search = request()->input('search');
$result = WeightValue::getList($pageSize,$search);
return $this->successJson('success',[
'current_page' => $result['current_page'],
'data' => $result['data'],
'last_page' => $result['last_page'],
]);
}
/**
* Common: 设置信息编辑
* Author: wu-hui
* Time: 2023/10/20 14:33
* @return array|mixed|string|void
* @throws \Throwable
*/
public function set(){
// 获取设置信息 判断是否为设置
$setInfo = request()->input('weight_value');
if ($setInfo) {
// 信息校验
if((int)$setInfo['is_open_commission'] == 1 && ((float)$setInfo['commission'] <= 0 || (float)$setInfo['commission'] > 100)){
return $this->message('手续费比例填写错误','','error');
}
// 设置信息
if (Setting::set('plugin.weight_value', $setInfo)) return $this->message('设置成功', Url::absoluteWeb('plugin.weight-value.admin.index.set'));
else $this->message('设置失败','','error');
}else{
// 获取信息
$set = Setting::get('plugin.weight_value');
$poster = Poster::uniacid()->select(['id','title'])->get()->toArray();
return view('Yunshop\WeightValue::index.set',[
'set' => $set,
'poster_list' => $poster,
])->render();
}
}
public function test(){
// (new WeightValue())->upgradeGiveInit(4,9);
// (new WeightValue())->giveInit(Order::find(143));
// (new \Yunshop\Commission\services\TimedTaskService)->handle();
// $hasNum = Uplog::uniacid()
// ->select(['uid'])
// ->where('after_level_id',6)
// ->where('uid','!=',4)
// ->count(DB::raw('DISTINCT(uid)'));
// (new \Yunshop\ShareholderDividend\services\TimedTaskService)->handle();
// debug($hasNum);
// (new WeightValue())->areaGiveInit(5,Order::find(161));
/* $teamList = TeamDividendAgencyModel::uniacid()
->select(['id','uid','cultural_level_id'])
->where('cultural_level_id','>',0)
// ->where('uid',182)
->get()
->toArray();
$notLogList = Uplog::uniacid()
->select(['id','uid','after_level_id'])
->whereIn('uid',array_column($teamList,'uid'))
->whereIn('after_level_id',array_column($teamList,'cultural_level_id'))
->get()
->toArray();
$hasUid = array_column($notLogList,'uid');
// debug([$notLogList,$teamList]);
foreach($teamList as $item){
if(!in_array($item['uid'],$hasUid)){
// 升级后等级
$c_c_level = TeamDividendLevelModel::with(['hasOneUpgradeSet'])->find((int)$item['cultural_level_id']);
// 升级前等级
$o_c_level = NULL;
// 升级日志
// debug($item);
Uplog::addLog(TeamDividendAgencyModel::find((int)$item['id']), $o_c_level, $c_c_level);
}
}*/
debug("调试中...");
}
}