__('待审批'), 1 => __('审核通过'), 2 => __('审核拒绝'), 3 => __('撤销')]; return $a[$this->status ?? ''] ?? ''; } public function checkStaff() { return $this->hasOne(Staff::class, 'id', 'check_staff_id')->field('id,name,img'); } //获取审批记录 public static function getList($relation_type, $relation_id) { return self::where([ 'relation_type' => $relation_type, 'relation_id' => $relation_id ])->with(['checkStaff'])->field('content,check_staff_id,check_time,status,createtime')->order('id asc')->select(); } public function getCheckTimeAttr($value) { if ($value) { return date('Y-m-d H:i', $value); } return $value; } public function getCreatetimeAttr($value) { if ($value) { return date('Y-m-d H:i', $value); } return $value; } /** * 添加审批 * @param $relation_type string 关联类型 * @param $relation_id int 关联id * @param $staff_id int 审批人ID */ public static function addExaminse($relation_type, $relation_id, $staff_id) { $staff = Staff::info(); $data = [ 'relation_type' => $relation_type, 'relation_id' => $relation_id, 'check_staff_id' => $staff_id, 'status' => 0 ]; if (self::where($data)->find()) {//已发送过审批通知 return true; } $Model = new self; $result = $Model->save($data); if (false === $result) { // 验证失败 输出错误信息 throw new Exception($Model->getError()); } //发送通知 Message::addMessage(Message::EXAMINE_TYPE, $Model->getLastInsID(), $staff_id, $staff->id); return true; } /** *是否审批 */ public static function isExaminse($relation_type, $relation_id) { $staff = Staff::info(); if (self::where([ 'relation_type' => $relation_type, 'relation_id' => $relation_id, 'status' => 0, 'check_staff_id' => $staff->id ])->find()) { return 1; } return 0; } //合同 public function contract() { return $this->hasOne(Contract::class, 'id', 'relation_id') ->field('id,name,owner_staff_id'); } //费用 public function consume() { return $this->hasOne(Consume::class, 'id', 'relation_id'); } //回款 public function receivables() { return $this->hasOne(Receivables::class, 'id', 'relation_id')->field('id,return_time,return_type,number,create_staff_id,money'); } //业绩目标 public function achievement() { return $this->hasOne(AchievementRecords::class, 'id', 'relation_id'); } //办公审批 public function approval() { return $this->hasOne(Approval::class, 'id', 'relation_id')->field('id,formapproval_id,create_staff_id'); } //发票 public function invoice() { return $this->hasOne(Invoice::class, 'id', 'relation_id'); } public static function cancelExaminse($relation_type, $relation_id) { $record = ExamineRecord::where([ 'relation_type' => $relation_type, 'relation_id' => $relation_id, 'status' => 0 ])->find(); if(empty($record)){ return true; } if ($message = Message::where([ 'relation_type' => 'examine', 'relation_id' => $record['id'], ])->find()) { Message::where(['id' => $message['id']])->update(['status' => 1, 'read_time' => time()]); } ExamineRecord::where([ 'relation_type' => $relation_type, 'relation_id' => $relation_id, 'status' => 0 ])->update(['status' => 3]); return true; } //产品入库申请记录 public function partsstock() { return $this->hasOne(PartsStockReload::class, 'id', 'relation_id')->where(array('type'=>1))->field('id,type,check_status'); } //产品出库申请记录 public function partsstockout() { return $this->belongsTo(PartsStockReload::class, 'id', 'relation_id')->where(array('type' => 2)); } //费用 public function quote() { return $this->hasOne(Quote::class, 'id', 'relation_id')->field('id,quote_amount,contract_id,quote_date,owner_staff_id,number,customer_id'); } //出入库 public function parts() { return $this->hasOne(PartsStockReload::class, 'id', 'relation_id')->field('id,type,odd_numbers,storage_time,desc,parts,create_staff_id,check_status'); } }