关于#小程序#的问题,如何解决?

当我在小程序端质检时提示,造成无法质检,我想要质检成功
PS:我不是技术员,我删除一些不想要的功能(另一个提问,已解决),但质检出现这个问题,希望答题时写细点
在线帮解决,可以红包答谢

img


工时价格是存在的

img

img

    //项目签到
    public function project_sign(){
        $userId = Cache::get(Input('post.token'));
        //pre($userId);
        $time=time();
        $postData=Input('post.');
        $postData['step_date']=date('Y-m-d',$time);
        $postData['step_sign']=$time;
        $postData['step_add_time']=$time;
        $postData['step_userid']=$userId;
        $postData['step_type']=1;

        unset($postData['token']);
        
        //禁用状态和项目暂停状态不能签到
        $proUser=Db::name('project_user')->where([
            'pu_project_id'=>$postData['step_project_id'],
            'pu_userid'=>$userId,
        ])->find();
        if($proUser['is_lock']==1){
            return $this->renderError('禁止签到');
        }
        $proInfo=Db::name('project')->where([
            'project_id'=>$postData['step_project_id'],
        ])->find();
        if($proInfo['project_status']==3){
            return $this->renderError('项目已完成');
        }
        if($proInfo['project_status']==4){
            return $this->renderError('项目已暂停');
        }
        
        
        $checkWhere=array(
            'step_userid'=>$postData['step_userid'],
            'step_date'=>$postData['step_date'],
            'step_project_id'=>$postData['step_project_id'],
            'step_type'=>1,
        );
        $countSign=Db::name('project_step')->where($checkWhere)->count();
        // if($countSign>0){
        //     return $this->renderError('今天已签到');
        // }
        $res=Db::name('project_step')->insert($postData);
        $msg='签到成功';
        return $this->renderSuccess($msg, $res);
    }



    //项目质检
    public function project_quality(){
        $userId = Cache::get(Input('post.token'));
        //pre($userId);
        $time=time();
        $postData=Input('post.');
        $postData['step_date']=date('Y-m-d',$time);
        $postData['step_check']=$time;
        $postData['step_add_time']=$time;
        $postData['step_check_userid']=$userId;
        $postData['step_type']=3;

        $duty=Db::name('project_user')->where([
                'pu_project_id'=>$postData['step_project_id'],
                'pu_userid'=>$postData['step_userid'],
                'is_delete'=>0,
                'pu_duty_id'=>$postData['step_duty'],
            ])->find();
        $moneyInfo=Db::name('project_manhour')->where([
                'manhour_project_id'=>$postData['step_project_id'],
                'manhour_duty_id'=>$duty['pu_duty_id'],
                'is_delete'=>0,
            ])->order('manhour_id desc')->find();
        
        unset($postData['token']);
        $checkWhere=array(
            'step_check_userid'=>$postData['step_check_userid'],
            'step_date'=>$postData['step_date'],
            'step_project_id'=>$postData['step_project_id'],
            'step_type'=>3,
        );
        
        //pre($duty);
        $postData['step_money']=$moneyInfo['manhour_price'];
        $postData['step_money_reality']=$postData['step_money']*$postData['step_num'];
        
        $res=Db::name('project_step')->insertGetId($postData);
        
        
        

        //余额被质检人变动
        $moneyData=array(
            'user_id'=>$postData['step_userid'],
            'scene'=>50,
            'money'=>$postData['step_money_reality'],
            'describe'=>'质检:'.$res,
            'app_id'=>$postData['app_id'],
            'create_time'=>$time,
        );
        Db::name('user_balance_log')->insertGetId($moneyData);


        $userInfo=Db::name('user')->where('user_id',$postData['step_userid'])->find();
        
        $userMoney=$userInfo['balance']+$postData['step_money_reality'];
        $userMoneyData=array(
            'balance'=>$userMoney,
        );
        Db::name('user')->where('user_id',$postData['step_userid'])->update($userMoneyData);
        
        //把所有的未质检的标记未质检
        $updateCheck=array(
            'is_check'=>time(),
        );
        Db::name('project_step')->where([
            'step_project_id'=>$postData['step_project_id'],
            'step_type'=>1,
            'is_check'=>0,
            'step_userid'=>$postData['step_userid'],
            'step_duty'=>$postData['step_duty'],
        ])->update($updateCheck);
        $msg='提交成功';
        return $this->renderSuccess($msg, $res);
    }
    
    
    /**
     * 更新项目总工时
     */
    public function updataTotal($proID){
        $practical_day=Db::name('project_step')->where([
            'step_project_id'=>$proID,
            'step_type'=>3
        ])->sum('step_num');
        
        $proInfo=Db::name('project')->where('project_id',$proID)->find();
        $isChao=0;
        if($practical_day>$proInfo['total_day']){
            $isChao=1;
        }
        if(time()>\strtotime($proInfo['project_end_time']) && $proInfo['project_status']!=3){
            $isChao=1;
        }
        
        Db::name('project')->where('project_id',$proID)->update(['total_day'=>$totalDay,'is_chao'=>$isChao]);
        
    }
    

    


    function prDates($start,$end){
        $dt_start = strtotime($start);
        $dt_end = strtotime($end);
        $dataArray=[];
        while ($dt_start<=$dt_end){
            $dataArray[]=date('Y-m-d',$dt_start);
            $dt_start = strtotime('+1 day',$dt_start);
        }
        return $dataArray;
    }


    //签到,质检
    public function step_detail(){
        $app_id = Input('get.app_id');
        $where = array(
            'step_id'=>Input('get.step_id'),
        );
        $detail=Db::name('project_step')->where($where)->find();
        if($detail['step_sign']!=0){
            $detail['step_sign_str']=date('H:i:s',$detail['step_sign']);
        }else{
            $detail['step_sign_str']='--';
        }
        if($detail['step_check']!=0){
            $detail['step_check_str']=date('H:i:s',$detail['step_check']);
        }else{
            $detail['step_check_str']='--';
        }
        /* if($detail['step_task']!=0){
            $detail['step_task_str']=date('H:i:s',$detail['step_task']);
        }else{
            $detail['step_task_str']='--';
        } */

        if($detail['step_task_imgs']!=0){
            $imgsArray=\explode(',',$detail['step_task_imgs']);
            $detail['imgs_arr']=Db::name('upload_file')->wherein('file_id',$imgsArray)->select();
        }
        
        $userInfo=Db::name('user')->where('user_id',$detail['step_userid'])->find();
        $detail['userInfo']=$userInfo;
        if($detail['step_type']==3){
            $clerkInfo=Db::name('store_clerk')->where('user_id',$detail['step_check_userid'])->find();
            $detail['clerkInfo']=$clerkInfo;
        }
        return_success($detail);

    }


    //项目成员
    public function project_user(){
        $projectId=Input('get.project_id');
        
        
        
        $userList=Db::name('project_manhour')->where('manhour_project_id',$projectId)->select();
        //pre($userList);
        foreach ($userList as $k => $v) {
            $v['duty']=Db::name('project_duty')->where(['duty_id'=>$v['manhour_duty_id']])->find();
            $puList=Db::name('project_user')
            ->where(['pu_project_id'=>$projectId,'pu_duty_id'=>$v['manhour_duty_id']])
            ->where('is_agree','in',[1])
            ->select();
            $v['user_num']=count($puList);
            $userIds=[];
            foreach($puList as $pk=>$pv){
                $userIds[]=$pv['pu_userid'];
                $puStep3Where=array(
                    'step_project_id'=>$projectId,
                    'step_type'=>3,
                    'step_userid'=>$pv['pu_userid'],
                    'step_duty'=>$pv['pu_duty_id'],
                );
                $pv['isSelect']=0;
                //质检数据
                $pv['check_num']=Db::name('project_step')
                    ->where($puStep3Where)
                    ->sum('step_num');
                //实际支付
                $pv['money_reality']=Db::name('project_step')
                    ->where($puStep3Where)
                    ->sum('step_money_reality');
                

                $puStep1Where=array(
                    'step_project_id'=>$projectId,
                    'step_type'=>1,
                    'step_userid'=>$pv['pu_userid'],
                    //'is_check'=>0,
                    'step_duty'=>$pv['pu_duty_id'],
                );
                //签到数据
                $pv['step_sign_num']=Db::name('project_step')
                    ->where($puStep1Where)
                    ->count();
                
                
                $userInfo=    Db::name('user')
                    ->where('user_id',$pv['pu_userid'])
                    ->find();
                $pv['nickName']=$userInfo['nickName'];
                if($userInfo['realName']){
                    $pv['nickName']=$userInfo['realName'];
                }
                $pv['mobile']=$userInfo['mobile'];
                $pv['avatarUrl']=$userInfo['avatarUrl'];
                //$pv['is_lock']=1;
                
                $puList[$pk]=$pv;
            }
            $v['step_num']=Db::name('project_step')
            ->where(['step_project_id'=>$projectId,'step_type'=>3])
            ->where('step_userid','in',$userIds)
            ->count();
            
            
            $v['step_money_reality']=Db::name('project_step')
            ->where(['step_project_id'=>$projectId,'step_type'=>3])
            ->where('step_userid','in',$userIds)
            ->sum('step_money_reality');
            
            $v['list']=$puList;
            
            
            
            $userList[$k]=$v;
            
            
        }

        $data['list']=$userList;
        //总工时
        $totle_work=Db::name('project_manhour')
        ->where(['manhour_project_id'=>$projectId])
        ->sum('manhour_length');
        //总职责
        $totle_duty=Db::name('project_manhour')
        ->where(['manhour_project_id'=>$projectId])
        ->count();
        //总人数
        $totle_people=Db::name('project_user')
        ->where(['pu_project_id'=>$projectId,'is_agree'=>1])
        ->count();
        

        $data['total_work']=$totle_work;
        $data['total_people']=$totle_people;
        $data['total_duty']=$totle_duty;
        //$data['clerk_name']=$clerk['real_name'];


        $data['step_num']=Db::name('project_step')
        ->where(['step_project_id'=>$projectId,'step_type'=>3])
        ->sum('step_num');
        
        
        $data['step_money_reality']=Db::name('project_step')
        ->where(['step_project_id'=>$projectId,'step_type'=>3])
        ->sum('step_money_reality');


        return_success($data);
        //pre($userList);

    }
    
<template>
    <view>

        <view class="applyLeave_box">
            <form @submit="formSubmit" @reset="formReset">
                <view class="formCon">
                    <view class="formItem">
                        <textarea class="textarea" name="step_check_text" placeholder="请填写质检内容" />
                    </view>
                    <view class="formItem">
                        <view class="upload-list d-s-c" v-model="image_list">
                            <view class="item" v-for="(imgs, img_num) in image_list" :key="img_num"
                                @click="deleteFunc(imgs)">
                                <image :src="imgs.file_path" mode="aspectFit"></image>
                            </view>
                            <view class="item upload-btn d-c-c d-c" @click="openUpload(index)"
                                v-if="image_list.length < 9">
                                <text class="icon iconfont icon-xiangji"></text>
                                <text class="gray9">上传图片</text>
                            </view>
                        </view>
                    </view>
                </view>

                <view class="formCon">
                    <view class="formItem">
                        <text class="label">质检数量</text>
                        <view class="controls">
                            <input type="digit" class="input" name="step_num" placeholder="请填写质检数量">
                        </view>
                    </view>
                    <!-- <view class="formItem">
                        <text class="label">处罚金额</text>
                        <view class="controls">
                            <input type="digit" class="input" name="step_money_fine" value="0" placeholder="请填写处罚金额">
                        </view>
                    </view> -->
                </view>

                <view class="foot-btns">
                    <button form-type="submit" hover-class="none" class="btn-red">提 交</button>
                </view>

            </form>
        </view>

        <!--上传图片-->
        <Upload v-if="isUpload" @getImgs="getImgsFunc"></Upload>

    </view>
</template>

<script>
    import Upload from '@/components/upload/upload.vue';

    export default {
        data() {
            return {
                // 项目id
                project_id: '',
                user_id: '',
                sign_num: '',
                duty_id:'',
                
                /* longitude: '',
                latitude: '', */

                /*是否打开上传图片*/
                isUpload: false,
                image_list: [],
                image_id: [],
            };
        },
        components: {
            Upload,
        },
        /* created() {
            let _this = this;
            _this.getMapKey();
        }, */
        onLoad(option) {
            console.log(option);
            let _this = this;
            _this.project_id = option.project_id;
            _this.user_id = option.user_id;
            _this.sign_num = option.sign_num;
            _this.duty_id=option.duty_id;
        },
        onShow() {

        },
        methods: {
            

            /*打开上传图片*/
            openUpload() {
                let _this = this;
                
                    _this.isUpload = true;
                
            },

            /*获取上传的图片*/
            getImgsFunc(e) {
                console.log("==当前上传图片==")
                console.log(e);
                let _this = this;
                _this.isUpload = false;

                if (e.length != 0) {
                    _this.image_list.push(e[0]);
                    console.log("==上传后的图片==")
                    console.log(_this.image_list)
                } else {
                    uni.showToast({
                        title: '图片上传失败',
                        duration: 2000
                    });
                }
            },

            /*删除图片*/
            deleteFunc(e) {
                // console.log(e);
                let _this = this;
                for (let i = 0; i < _this.image_list.length; i++) {
                    if (_this.image_list[i].file_id == e.file_id) {
                        _this.image_list.splice(i, 1);
                    }
                }
                console.log("==删除图片后的数据==")
                console.log(_this.image_list);
            },

            /*提交*/
            formSubmit: function(e) {
                let _this = this;
                let formdata = e.detail.value;

                if (!formdata.step_check_text) {
                    wx.showModal({
                        content: '质检内容不能为空',
                        showCancel: false,
                    })
                    return;
                }

                if (!formdata.step_num) {
                    wx.showModal({
                        content: '质检数量不能为空',
                        showCancel: false,
                    })
                    return;
                }


                let image_list = _this.image_list;
                let image_id = [];
                
                for (var i = 0; i < image_list.length; i++) {
                    // console.log(image_list[i].file_id);
                    image_id.push(image_list[i].file_id)
                }
                console.log("==图片id数组==");
                console.log(image_id);

                formdata.step_project_id = _this.project_id;
                formdata.step_userid = _this.user_id;
                formdata.step_duty = _this.duty_id;
                
                
                formdata.step_task_imgs = image_id.join(',');

                console.log("==提交的参数==")
                console.log(formdata)

                _this._post(
                    'project.index/project_quality',
                    formdata,
                    function(res) {
                        console.log(res);
                        uni.showToast({
                            title: res.msg,
                            duration: 2000,
                            success(){
                                setTimeout(function () {
                                    uni.navigateBack({
                                        delta: 1
                                    });
                                }, 2000);
                            }
                        });
                    }
                );
            },

        },
    }
</script>

<style lang="scss">
    @import "/workPackages/common/common.css";
    
    .formItem .controls {
        float: right;
    }
</style>


```

参考GPT:根据错误提示来看,问题出在 step_money 列上,该列不能为 null,但是在执行 project_quality() 函数时,出现了该错误。

在 project_quality() 函数中,首先获取 $moneyInfo 变量,该变量从 project_manhour 表中获取 manhour_price 值,但是该变量可能会为空,因此在插入 project_step 表中时,step_money 值会变成 null,从而导致上述错误。

为了解决该问题,可以先添加一个条件判断,如果 $moneyInfo 为空,则返回错误提示。

例如,可以在以下位置添加该判断:

$moneyInfo=Db::name('project_manhour')->where([
        'manhour_project_id'=>$postData['step_project_id'],
        'manhour_duty_id'=>$duty['pu_duty_id'],
        'is_delete'=>0,
    ])->order('manhour_id desc')->find();
    
if(empty($moneyInfo)){
    return $this->renderError('工时价格不存在');
}


这样,当 $moneyInfo 为空时,就会返回错误提示,避免了插入 null 值的问题。

$moneyInfo['manhour_price'] 是不是没有数据

基于最新版ChatGPT4的回答,望采纳!!!有其他问题也可以询问我哦💕(最新版更智能,功能更加强大)
这是一个使用uni-app框架编写的Vue组件,包含以下功能:

提交表单数据
打开上传图片的功能
获取上传的图片列表,并允许删除已上传的图片
对表单数据进行必填项校验
具体实现细节如下:

在页面加载时,获取传递过来的参数 option,包括 project_id, user_id, sign_num, duty_id。
点击上传图片按钮,调用 openUpload 方法,将 isUpload 设置为 true,显示上传图片的组件 Upload。
当用户上传图片后,Upload 组件会通过事件 @getImgs 向父组件传递上传的图片列表 e。在 getImgsFunc 方法中,将 isUpload 设置为 false,关闭上传图片的组件,将上传的图片添加到 image_list 数组中。
在表单提交时,执行 formSubmit 方法,对表单数据进行必填项校验,如果校验通过,将上传的图片 id 信息提取出来,作为参数提交到服务器端。

$postDta 打出来看看 ,$moneyInfo 打出来看看 ,再把 编辑数据库 step_money 空 的 否 改为 是。具体应用的时候注意一下。

1.简单的问题
这明显是数据层抛出来的异常,字段step_money为空了。数据库表中这个字段有约束不为null

以下答案由GPT-3.5大模型与博主波罗歌共同编写:
根据给出的代码,我看到了两个方法,一个是 project_sign(),用于项目签到,一个是 project_quality(),用于项目质检。结合代码中的注释和方法名称,可以看出这两个方法的功能。

解决问题的方法取决于质检失败的原因。根据你的问题描述,首先需要在小程序端查看提示信息。如果提示信息不明确,需要在后台代码中添加日志打印,以便跟踪问题。一般情况下,质检失败的原因可能包括但不限于以下几种情况:

  1. 参数错误:检查参数是否正确,包括参数是否
    如果我的回答解决了您的问题,请采纳!
不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 帮你找了个相似的问题, 你可以看下: https://ask.csdn.net/questions/1070183
  • 这篇博客你也可以参考下:关于虚拟机黑屏的问题,解决了我长大三个月的烦恼
  • 除此之外, 这篇博客: 如何设置线程池的大小?中的 一、线程池是每个程序员要掌握的一项技能,我们要如何去理解线程池呢,可以看下线程池是如何创建的。 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:
     public ThreadPoolExecutor(int corePoolSize,
                                  int maximumPoolSize,
                                  long keepAliveTime,
                                  TimeUnit unit,
                                  BlockingQueue<Runnable> workQueue,
                                  ThreadFactory threadFactory,
                                  RejectedExecutionHandler handler) {
           
      }

    ThreadPoolExecutor 的构造函数中,有几个很重要的参数。

    • corePoolSize: 核心线程数量最大值
    • maximumPoolSize: 最大线程数量
    • keepAliveTime: 非核心线程存活时间
    • unit: keepAliveTime时间单位
    • workQueue:在任务执行之前用于保存任务的队列
    • threadFactory: 线程工厂可用于创建新线程
    • handler: 当达到线程界限和队列容量线程池的拒绝策略

         线程池的工作原理如下图所示:

         

    1.   当线程池小于 corePoolSize 时,新提交任务将创建一个新线程执行任务,即使此时线程池中存在空闲线程。
    2.   当线程池达到 corePoolSize 时,新提交任务将被放入 workQueue 中,等待线程池中任务调度执行
    3.   当 workQueue 已满,且 maximumPoolSize > corePoolSize时,新提交任务会创建新线程执行任务
    4.   当提交任务数超过 maximumPoolSize 时,新提交任务由 RejectedExecutionHandler 处理
    5.   当线程池中超过 corePoolSize 线程,空闲时间达到 keepAliveTime 时,关闭空闲线程
    6.   当设置 allowCoreThreadTimeOut(true) 时,线程池中 corePoolSize 线程空闲时间达到 keepAliveTime 也将关闭
  • 您还可以看一下 2017CCTC大会老师的【微服务专场】实施微服务架构的关键技术课程中的 实施微服务架构的关键技术小节, 巩固相关知识点

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^