hasOne(Customer::class, 'id', 'customer_id')->field('id,name'); } //合同 public function contract() { return $this->hasOne(Contract::class, 'id', 'contract_id')->field('id,name,num'); } //负责人 public function ownerStaff() { return $this->hasOne(Staff::class, 'id', 'owner_staff_id')->field('id,name,img'); } public function createStaff() { return $this->hasOne(Staff::class, 'id', 'create_staff_id')->field('id,name,img'); } //添加 public static function createInvoice($params) { foreach ($params as $name => $val) { if($params[$name] === ''){ $params[$name]=NULL; } } $staff = Staff::info(); $staff_id = $staff->id; $params['create_staff_id'] = $staff_id; $params['owner_staff_id'] = $staff->id; $params['check_status'] = 1; $flow = Flow::getsteplist(Flow::INVOICE_STATUS); $params['flow_id'] = $flow['flow_id']; $params['order_id'] = $flow['order_id']; if ($flow['status'] == 0) {//发起人自选 $params['flow_staff_ids'] = trim($params['flow_staff_ids']??''); } else { $params['flow_staff_ids'] = trim($flow['flow_staff_ids']); } $Model = new self; $result = $Model->allowField(true)->save($params); if (false === $result) { // 验证失败 输出错误信息 throw new Exception($Model->getError()); } $lastId= $Model->getLastInsID(); $staff_id = explode(',', $params['flow_staff_ids'])[0]; ExamineRecord::addExaminse(ExamineRecord::INVOICE_TYPE,$lastId, $staff_id); return true; } //编辑 public static function updateInvoice($params) { $params['check_status'] = 1; $flow = Flow::getsteplist(Flow::INVOICE_STATUS); $params['flow_id'] = $flow['flow_id']; $params['order_id'] = $flow['order_id']; if ($flow['status'] == 0) {//发起人自选 if (empty($params['flow_staff_ids'])) { throw new Exception('审批人必须选择'); } $params['flow_staff_ids'] = trim($params['flow_staff_ids']); } else { $params['flow_staff_ids'] = trim($flow['flow_staff_ids']); } $Model = new self; // 调用当前模型对应的User验证器类进行数据验证 $result = $Model->save($params,['id'=>$params['id']]); if (false === $result) { // 验证失败 输出错误信息 throw new Exception($Model->getError()); } if ($flow['status'] == 1) {//固定审批 //发送审批通知 Flow::sendStepRecord($flow,Flow::INVOICE_STATUS, $params['id']); } else {//发起人自选 依次审批 $staff_id = explode(',', $params['flow_staff_ids'])[0]; if ($staff_id) { ExamineRecord::addExaminse(ExamineRecord::INVOICE_TYPE, $params['id'], $staff_id); } } return true; } //标记开票 public static function updateInfo($params){ $Model = new self; // 调用当前模型对应的User验证器类进行数据验证 $result = $Model->save($params,['id'=>$params['id']]); if (false === $result) { // 验证失败 输出错误信息 throw new Exception($Model->getError()); } $contractId = $Model->where(['id'=>$params['id']])->value('contract_id'); if($contractId){ $file =''; if($params['image']){ $file = File::where(['file_path'=>$params['image']])->value('id'); } $ret = array( 'invoice_date'=>$params['invoice_time'], 'invoice_logistics_number'=>$params['logistics'], 'invoice_file_ids'=>$file, ); Contract::where(['id'=>$contractId])->update($ret); } return true; } }