tp6 我想废弃grow_project_json这个表,然后在小程序端正常调出项目名称
namespace app\api\controller\project;
use app\api\controller\Controller;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Log;
use think\facade\Request;
use think\facade\Session;
/**
* 收货地址控制器
*/
class Index extends Controller{
/**
* 获取本月天数
*/
public function get_month(){
$userId = Cache::get(Input('get.token'));
$nowYM=date('m',time());
$days = date("t",time());
$nowDay = date("j",time());
$dayArray=array();
//上二月
$oneMonth=strtotime("-2 month");
$oneYm=date("m",$oneMonth);
$onedays = date("t",$oneMonth);
for($i=1;$i<=$onedays;$i++){
$oneArray=array();
$oneArray['days']=$i;
if($i<10){
$oneArray['date']=$oneYm.'-0'.$i;
}else{
$oneArray['date']=$oneYm.'-'.$i;
}
$oneArray['is_today']=0;
$dayArray[]=$oneArray;
}
//上一月
$twoMonth=strtotime("-1 month");
$twodays = date("t",$twoMonth);
$twoYm=date("m",$twoMonth);
for($i=1;$i<=$twodays;$i++){
$oneArray=array();
$oneArray['days']=$i;
if($i<10){
$oneArray['date']=$twoYm.'-0'.$i;
}else{
$oneArray['date']=$twoYm.'-'.$i;
}
$oneArray['is_today']=0;
$dayArray[]=$oneArray;
}
//本月
for($i=1;$i<=$days;$i++){
$oneArray=array();
$oneArray['days']=$i;
if($i<10){
$oneArray['date']=$nowYM.'-0'.$i;
}else{
$oneArray['date']=$nowYM.'-'.$i;
}
if($i==$nowDay){
$oneArray['is_today']=1;
$oneArray['date']=$oneArray['date'];
}else{
$oneArray['is_today']=0;
}
$dayArray[]=$oneArray;
}
//下一月
for($k=1;$k<=2;$k++){
$nextMonth=strtotime("+".$k." month");
$nextdays = date("t",$nextMonth);
$nextYm=date("m",$nextMonth);
for($i=1;$i<=$nextdays;$i++){
$oneArray=array();
$oneArray['days']=$i;
if($i<10){
$oneArray['date']=$nextYm.'-0'.$i;
}else{
$oneArray['date']=$nextYm.'-'.$i;
}
$oneArray['is_today']=0;
$dayArray[]=$oneArray;
}
}
return_success($dayArray);
}
//指定数组以$keys键值排序
public function arraySort($array,$keys,$type='asc'){
//$array为要排序的数组,$keys为要用来排序的键名,$type默认为升序排序
$keysvalue = $new_array = array();
foreach ($array as $k=>$v){
$keysvalue[$k] = $v[$keys];
}
if($type == 'asc'){
asort($keysvalue);
}else{
arsort($keysvalue);
}
reset($keysvalue);
foreach ($keysvalue as $k=>$v){
$new_array[$k] = $array[$k];
}
return $new_array;
}
/**
* 项目列表
*/
public function project_list(){
$userId = Cache::get(Input('get.token'));
$timeStr=date('Y',time()).'-'.Input('get.datetime');
$ids=[];
$proList=[];
$clerkInfo=Db::name('store_clerk')->where('user_id',$userId)->order('clerk_id desc')->find();
//$postData['project_clerk_id']=$clerkInfo['clerk_id'];
//查询负责的项目
$puAdminList=Db::name('project')
//->where('project_userid',$userId)
->where('project_clerk_id',$clerkInfo['clerk_id'])
->select();
//pre($puAdminList);
foreach($puAdminList as $ak=>$av){
if($timeStr<$av['project_start_time'] || $timeStr>$av['project_end_time']){
}else{
$proJson=Db::name('project_json')->where([
'json_projectid'=>$av['project_id'],
'json_time'=>$timeStr,
])->select();
foreach($proJson as $jk=>$jv){
$oneJson=array(
's_time'=>$jv['json_start_time'],
'e_time'=>$jv['json_end_time'],
'project_name'=>$av['project_name'],
'project_id'=>$av['project_id'],
'json_id'=>$jv['json_id'],
'is_agree'=>1,
'duty_name'=>'经理',
'duty_id'=>0,
);
$proList[]=$oneJson;
}
}
}
$puWhere=array();
if(empty($clerkInfo)){
$puWhere['pu_userid']=$userId;
}else{
$puWhere['pu_clerk_id']=$clerkInfo['clerk_id'];
}
//查询参与的项目
$puList=Db::name('project_user')
->where($puWhere)
//->where('pu_clerk_id',$clerkInfo['clerk_id'])
->where('is_agree',1)
->group('pu_project_id')
->order('pu_duty_id desc')
->select();
foreach($puList as $k=>$v){
$proInfo=Db::name('project')
->where('project_id',$v['pu_project_id'])
->find();
$proJson=Db::name('project_json')->where([
'json_projectid'=>$v['pu_project_id'],
'json_time'=>$timeStr,
])->order('json_start_time asc')->select();
$dutyInfo=Db::name('project_duty')
->where('duty_id',$v['pu_duty_id'])
->find();
foreach($proJson as $jk=>$jv){
$oneJson=array(
's_time'=>$jv['json_start_time'],
'e_time'=>$jv['json_end_time'],
'project_name'=>$proInfo['project_name'],
'project_id'=>$proInfo['project_id'],
'is_agree'=>strval($v['is_agree']),
'json_id'=>$jv['json_id'],
'is_agree'=>$v['is_agree'],
'duty_name'=>$dutyInfo['duty_name'],
'duty_id'=>$dutyInfo['duty_id'],
);
$proList[]=$oneJson;
}
$ids[]=$v['pu_project_id'];
}
//查询参与的项目
$puListNoAgree=Db::name('project_user')
->where($puWhere)
//->where('pu_clerk_id',$clerkInfo['clerk_id'])
->where('is_agree',0)
->order('pu_duty_id desc')
->select();
foreach($puListNoAgree as $k=>$v){
$proInfo=Db::name('project')
->where('project_id',$v['pu_project_id'])
->find();
$proJson=Db::name('project_json')->where([
'json_projectid'=>$v['pu_project_id'],
'json_time'=>$timeStr,
])->order('json_start_time asc')->select();
$dutyInfo=Db::name('project_duty')
->where('duty_id',$v['pu_duty_id'])
->find();
foreach($proJson as $jk=>$jv){
$oneJson=array(
's_time'=>$jv['json_start_time'],
'e_time'=>$jv['json_end_time'],
'project_name'=>$proInfo['project_name'],
'project_id'=>$proInfo['project_id'],
'is_agree'=>strval($v['is_agree']),
'json_id'=>$jv['json_id'],
'is_agree'=>$v['is_agree'],
'duty_name'=>$dutyInfo['duty_name'],
'duty_id'=>$dutyInfo['duty_id'],
);
$proList[]=$oneJson;
}
$ids[]=$v['pu_project_id'];
}
$proList=self::arraySort($proList,'s_time');
$resData=[];
foreach($proList as $pk=>$pv){
if(empty($resData)){
$proList1=[];
$one=array(
'start_time'=>$pv['s_time'],
'end_time'=>$pv['e_time'],
);
$two=array(
'project_name'=>$pv['project_name'],
'project_id'=>$pv['project_id'],
'is_agree'=>$pv['is_agree'],
'json_id'=>$pv['json_id'],
'start_time'=>$pv['s_time'],
'is_agree'=>$pv['is_agree'],
'duty_name'=>$pv['duty_name'],
'duty_id'=>$pv['duty_id'],
);
$proList1[]=$two;
$one['list']=$proList1;
$resData[]=$one;
}else{
$proIndex=count($resData)-1;
//被上一级完全包围
if($resData[$proIndex]['end_time']>=$pv['e_time']){
$two=array(
'project_name'=>$pv['project_name'],
'project_id'=>$pv['project_id'],
'is_agree'=>$pv['is_agree'],
'json_id'=>$pv['json_id'],
'start_time'=>$pv['s_time'],
'is_agree'=>$pv['is_agree'],
'duty_name'=>$pv['duty_name'],
'duty_id'=>$pv['duty_id'],
);
$resData[$proIndex]['list'][]=$two;
}
//被上一级半包围
if($resData[$proIndex]['end_time']<$pv['e_time'] && $resData[$proIndex]['end_time']>=$pv['s_time']){ //被上一级完全包围
$two=array(
'project_name'=>$pv['project_name'],
'project_id'=>$pv['project_id'],
'is_agree'=>$pv['is_agree'],
'json_id'=>$pv['json_id'],
'start_time'=>$pv['s_time'],
'is_agree'=>$pv['is_agree'],
'duty_name'=>$pv['duty_name'],
'duty_id'=>$pv['duty_id'],
);
$resData[$proIndex]['list'][]=$two;
$resData[$proIndex]['end_time']=$pv['e_time'];
}
//没有被上一级包围
if($resData[$proIndex]['end_time']<$pv['s_time']){
$proList1=[];
$one=array(
'start_time'=>$pv['s_time'],
'end_time'=>$pv['e_time'],
);
$two=array(
'project_name'=>$pv['project_name'],
'project_id'=>$pv['project_id'],
'is_agree'=>$pv['is_agree'],
'json_id'=>$pv['json_id'],
'start_time'=>$pv['s_time'],
'is_agree'=>$pv['is_agree'],
'duty_name'=>$pv['duty_name'],
'duty_id'=>$pv['duty_id'],
);
$proList1[]=$two;
$one['list']=$proList1;
$resData[]=$one;
}
}
}
$msg='获取成功';
return $this->renderSuccess($msg, $resData);
}
<template>
<view>
<!-- 选项卡 -->
<view class="top-tabbar">
<scroll-view class="tabScroll" scroll-x="true" :scroll-left="scrollLeft" scroll-with-animation>
<view :class="item.date == datetime ? 'tab-item active' : 'tab-item'" v-for="(item,index) in dateList"
:key="index" @click="stateFunc(item.date)">
{{item.date}}<text v-if="item.is_today == '1'">(今天)</text>
</view>
</scroll-view>
</view>
<view class="projectList_box">
<view class="projectItem" v-for="(item,index) in projectList" :key="index">
<view class="projectWrap">
<view class="projectLi" v-for="(list,listIndex) in item.list" :key="listIndex"
@click="projectDetail(list.project_id,list.is_agree,list.duty_id)">
<text class="projectName">{{list.project_name}}</text>
<!-- <text class="projectDate" v-if="list.is_agree == 1">{{list.start_time}}</text> -->
<text class="projectDate" v-if="list.is_agree == 0">{{list.duty_name}}</text>
<image src="/static/projectMore.png" mode=""></image>
</view>
</view>
</view>
<view class="d-c-c p30" v-if="projectList.length == 0">
<text class="iconfont icon-wushuju"></text>
<text class="cont">亲,暂无相关记录哦</text>
</view>
</view>
<tabBar></tabBar>
</view>
</template>
<script>
export default {
components: {},
data() {
return {
// 日期
dateList: [],
// 当前日期滑动的位置
scrollLeft: '',
// 当前选中的日期
datetime: '',
// 我的项目数据
projectList: [],
};
},
created() {
uni.showLoading({
title: '加载中'
});
},
onShow() {
this.getTabDate();
},
methods: {
// 获取日期数据
getTabDate() {
let _this = this;
_this._get(
'project.index/get_month', {},
function(res) {
console.log("==获取日期数据==")
console.log(res)
_this.dateList = [];
_this.dateList = res.data;
for (var i = 0; i < res.data.length; i++) {
if (res.data[i].is_today == 1) {
// console.log(i);
if (i == 0) {
_this.scrollLeft = 0;
}
if (i == 1) {
_this.scrollLeft = (i * 160 - 640) / 2;
}
if (i > 1) {
_this.scrollLeft = (i * 160 - 960) / 2;
}
// console.log(_this.scrollLeft)
_this.datetime = res.data[i].date;
_this.getMyProject();
}
}
}
);
},
// 选项卡切换
stateFunc(date) {
// console.log("点击日期", date);
let _this = this;
_this.datetime = date;
uni.showLoading({
title: '加载中'
});
_this.projectList = [];
_this.getMyProject();
},
// 获取项目数据
getMyProject() {
let _this = this;
_this._get(
'project.index/project_list', {
datetime: _this.datetime,
},
function(res) {
console.log("==获取项目数据==")
console.log(res)
_this.projectList = [];
_this.projectList = res.data;
uni.hideLoading();
}
);
},
// 查看项目详情
projectDetail: function(project_id, is_agree,dutyID) {
console.log('is_agree的值:' + is_agree)
console.log('dutyID的值:' + dutyID)
if (is_agree == 0) {
uni.navigateTo({
url: '/workPackages/project/projectAgree/projectAgree?project_id=' + project_id+'&duty_id='+dutyID,
});
} else {
uni.navigateTo({
url: '/workPackages/project/projectDetail/projectDetail?project_id=' + project_id,
});
}
},
},
// 过滤器
filters: {
// 年月日去掉年(截取前5位字符)
sliceFormat(str) {
return str.slice(5);
}
},
}
</script>