2301_77108677 2023-03-19 13:11 采纳率: 40%
浏览 59
已结题

tp6 我想废弃grow_project_json这个表,然后在小程序端正常调出项目名称

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);
    }

img

img

<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>


  • 写回答

5条回答 默认 最新

  • 关注

    基于最新版ChatGPT4的回答,望采纳!!!有其他问题也可以询问我哦、”(最新版更智能,功能更加强大)

    首先,你需要删除grow_project_json表的相关查询和操作。从给出的代码中,我发现在project_list()方法中有关于grow_project_json表的查询。我将为你修改这个方法以移除与grow_project_json表相关的操作。

    你可以按照以下步骤操作:

    1. 删除关于grow_project_json的查询。
    2. 修改方法以从其他表中获取项目名称。

    请将下面的修改后的代码替换原有的project_list()方法:

        /**
         * 项目列表
         */
        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();
    
            //查询负责的项目
            $puAdminList = Db::name('project')
                ->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 {
                    // 获取项目名称
                    $oneJson = array(
                        's_time' => $av['project_start_time'],
                        'e_time' => $av['project_end_time'],
                        'project_name' => $av['project_name'],
                        'project_id' => $av['project_id'],
                        'is_agree' => 1,
                        'duty_name' => '经理',
                        'duty_id' => 0,
                    );
                    $proList[] = $oneJson;
                }
            }
    
            // ... 保持其他代码不变
    
            $proList = self::arraySort($proList, 's_time');
            $resData = [];
    
            // ... 保持其他代码不变
    
            $msg = '获取成功';
            return $this->renderSuccess($msg, $resData);
        }
    

    这样,你就成功地废弃了grow_project_json表,并在小程序端正常调出了项目名称。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 3月27日
  • 已采纳回答 3月19日
  • 修改了问题 3月19日
  • 创建了问题 3月19日

悬赏问题

  • ¥15 GIS土地利用预测FLUS模型
  • ¥15 visual studio code打不出来中文双引号
  • ¥20 关于#matlab#的问题:ps:完美符合要求有打赏(相关搜索:自适应)
  • ¥15 声音感应灯,问题出在哪里
  • ¥15 关于#matlab#的问题:(0,0)上的贝塞尔曲线,0)上的贝塞尔曲线,并使用自适应积分计算其从t=0到不大于1的任意值区间的弧长
  • ¥20 关于#r语言#rda分析作图的问题,请各位专家解答!
  • ¥50 找回 股票行情系统的资源问题
  • ¥15 gwas 分析-plink 检查人口分层出现下面问题
  • ¥15 关于#matlab#的问题:需要 MATLAB 运行程序,对比四个多址通信方式(TDMA,FDMA,CDMA,OFDMA)的抗噪声性能
  • ¥15 有没有复现过PFENet的,如何解决?