<?php
|
|
namespace app\api\model\plus\ticket;
|
|
use app\common\exception\BaseException;
|
use app\common\model\plus\ticket\Ticket as TicketModel;
|
|
/**
|
* 模型
|
*/
|
class Ticket extends TicketModel
|
{
|
/**
|
* 隐藏字段
|
* @var array
|
*/
|
protected $hidden = [
|
'is_delete',
|
'app_id',
|
'update_time'
|
];
|
|
/**
|
* 详情
|
*/
|
public static function detail($upload_id)
|
{
|
if (!$model = parent::detail($upload_id)) {
|
throw new BaseException(['msg' => '信息不存在']);
|
}
|
return $model;
|
}
|
|
/**
|
* 获取列表
|
*/
|
public function getList($params,$user)
|
{
|
$model = $this;
|
return $model ->with(['image.file'])
|
->where('user_id', '=', $user["user_id"])
|
->where('is_delete', '=', 0)
|
->order(['create_time' => 'desc'])
|
->paginate($params);
|
}
|
/**
|
* 添加小票上传
|
*/
|
public function addTicket($user,$params)
|
{
|
$formData=json_decode($params["formData"], true);
|
$data = [
|
'user_id' => $user["user_id"],
|
'content' => $formData['content'],
|
'app_id' => self::$app_id
|
];
|
if (empty($formData["content"]) && empty($formData["image_list"])) {
|
$this->error = '图片与备注不能留空';
|
return false;
|
}
|
return $this->transaction(function () use ( $formData, $data) {
|
// 记录备注内容
|
$this->save($data);
|
// 记录小票图片
|
$this->saveAllImages($this['upload_id'],$formData);
|
return true;
|
});
|
}
|
/**
|
* 记录小票图片
|
*/
|
private function saveAllImages($upload_id,$formData)
|
{
|
// 生成图片数据
|
if(!empty($formData['image_list'])){
|
$imageData = [];
|
foreach ($formData['image_list'] as $imageId) {
|
$imageData[] = [
|
'upload_id' => $upload_id,
|
'image_id' => $imageId['file_id'],
|
'app_id' => self::$app_id
|
];
|
}
|
$model = new TicketUploadImage;
|
return !empty($imageData) && $model->saveAll($imageData);
|
}
|
return true;
|
|
}
|
|
}
|