<?php namespace App\Model; use Illuminate\Database\Eloquent\Model; use Request; class SupplierContactModel extends Model { protected $connection = 'web'; protected $table = 'supplier_contact'; public $timestamps = false; public function AddInfo($SupplierID = '', $data = '') { if (empty($SupplierID) || empty($data) || !is_array($data)) { return false; } $Add = array(); foreach ($data as $k => $v) { foreach ($v as $kk => $vv) { $Add[$kk][$k] = $vv; $Add[$kk]['supplier_id'] = $SupplierID; } } foreach ($Add as $v) { $this->insert($v); } return true; } public function AddContactInfo($data = '', $is_update = false) { if (empty($data) || !is_array($data)) { return false; } if ($is_update) { // 更新 $supplier_id = $data['supplier_id']; unset($data['supplier_id']); $this->where('supplier_id', '=', $supplier_id)->update($data); } else { $this->insert($data); } } public function SaveInfo($SupplierID = '', $data = '') { if ($SupplierID <= 0) { return false; } $this->where('supplier_id', '=', $SupplierID)->delete(); return $this->AddInfo($SupplierID, $data); } public function ContactInfo($SupplierID = '') { $collert = Request::only('supplier_id'); $collert = TrimX($collert, true, ['supplier_id']); empty($collert) && $collert['supplier_id'] = $SupplierID; if (empty($collert['supplier_id'])) { return false; } $info = $this->where('supplier_id', '=', $collert['supplier_id'])->get(); if (!$info) { return false; } $info = $info->toArray(); return $info; } //获取未完整的联系方式 public function getNotCompletedContacts($supplierId, $codeId) { $notCompleteContacts = SupplierContactModel::where('supplier_id', $supplierId) ->where('can_check_uids', $codeId) ->where(function ($q) { $q->where('supplier_consignee', '') ->orWhere('supplier_position', '') ->orWhere('supplier_email', '') ->orWhere('supplier_mobile', '') ->orWhere('supplier_telephone', ''); })->get(); return !empty($notCompleteContacts) ? $notCompleteContacts->toArray() : []; } }