123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- namespace addons\qingdongams\model;
- use think\Exception;
- use think\Model;
- use traits\model\SoftDelete;
- /**
- *审批记录
- */
- class ExamineRecord Extends Model {
- use SoftDelete;
- // 表名,不含前缀
- protected $name = 'qingdongams_examine_record';
- const CONSUME_TYPE = 'consume';//费用
- const CONTRACT_TYPE = 'contract';//合同
- const RECEIVABLES_TYPE = 'receivables';//回款
- const ACHIEVEMENT_TYPE = 'achievement';//业绩目标
- const APPROVAL_TYPE = 'approval';//审批
- const CARD_TYPE = 'card';//补卡
- const LEAVE_TYPE = 'leave';//请假
- const PARTS_TYPE = 'parts';//零件
- const QUOTE_TYPE = 'quote';//报价单
- const WORKORDER_TYPE = 'workorder';//工单
- const INVOICE_TYPE = 'invoice';//发票
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = 'deletetime';
- public function getStatusTextAttr()
- {
- $a = [0 => __('待审批'), 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');
- }
- }
|