You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/api/model/RecoveryOrder.php

149 lines
4.1 KiB

10 months ago
<?php
namespace app\api\model;
use app\api\service\User as UserService;
10 months ago
use app\common\enum\RecoveryStatusEnum;
10 months ago
use app\common\model\RecoveryOrder as BaseRecoveryOrder;
use app\common\service\Order as OrderService;
use cores\exception\BaseException;
use think\db\exception\DbException;
use think\Paginator;
class RecoveryOrder extends BaseRecoveryOrder
{
/**
* 隐藏字段
* @var array
*/
protected $hidden = [
'store_id',
'update_time',
];
/**
* @notes:用户回收订单列表
* @param array $where
* @param int $listRows
* @return Paginator
* @throws BaseException
* @throws DbException
* @author: wanghousheng
*/
10 months ago
public function getUserList(array $where = [], int $listRows = 15, array $with = []): Paginator
10 months ago
{
// 当前用户ID
$userId = UserService::getCurrentLoginUserId();
if (!UserService::isStore()) {
$where = array_merge($where, ['user_id' => $userId]);
}
//分销商工程师
10 months ago
return $this
10 months ago
->with($with)
10 months ago
->where($where)
->order(['create_time' => 'desc'])
->paginate($listRows);
}
/**
* @notes:订单详情
10 months ago
* @param int $orderId
10 months ago
* @return BaseRecoveryOrder|array|null
* @throws BaseException
* @author: wanghousheng
*/
10 months ago
public function getDetails(int $orderId)
10 months ago
{
10 months ago
$where['order_id'] = $orderId;
9 months ago
//不是店长带上 use_id
if(!UserService::isStore()) {
$where['user_id'] = UserService::getCurrentLoginUserId();
}
10 months ago
return static::detail($where, ['images.file']);
}
/**
* @notes:添加记录
* @param array $data
* @param array $imageIds
* @return bool
* @throws BaseException
* @author: wanghousheng
*/
public function add(array $data, array $imageIds = []): bool
{
$data['order_no'] = OrderService::createOrderNo();
$data['user_id'] = UserService::getCurrentLoginUserId();
$data['store_id'] = self::$storeId;
$data['create_time'] = time();
$data['update_time'] = $data['create_time'];
$insertId = $this->insertGetId($data);
if ($insertId) {
if ($imageIds) {
RecoveryImage::increased($insertId, $imageIds);
}
return true;
}
return false;
}
/**
* @notes:更新
* @param array $data
10 months ago
* @param int $orderId
10 months ago
* @param array $imageIds
* @return bool
* @author: wanghousheng
*/
10 months ago
public function edit(array $data, int $orderId, array $imageIds = []): bool
10 months ago
{
10 months ago
if ($this->where(['order_id' => $orderId])->save($data)) {
10 months ago
if ($imageIds) {
log_record(['name'=>'服务订单图片', 'image_ids' => $imageIds]);
10 months ago
RecoveryImage::updates($orderId, $imageIds);
10 months ago
}
return true;
}
return false;
}
10 months ago
/**
* @notes:取消
10 months ago
* @param int $orderId
10 months ago
* @return bool
* @throws BaseException
* @author: wanghousheng
*/
10 months ago
public function cancel(int $orderId): bool
10 months ago
{
10 months ago
$where['order_id'] = $orderId;
10 months ago
// 当前用户ID
$userId = UserService::getCurrentLoginUserId();
if (!UserService::isStore()) {
$where['user_id'] = $userId;
}
$info = static::detail($where);
if (!$info->isEmpty() && $info['order_status'] == RecoveryStatusEnum::ACCEPTED) {
10 months ago
$this->where(['order_id' => $orderId])->save(['order_status' => RecoveryStatusEnum::CANCEL]);
10 months ago
return true;
}
return false;
}
/**
* 获取回收单记录
* @return int
*/
9 months ago
public static function getCount($type): int {
// 当前用户ID
$userId = UserService::getCurrentLoginUserId();
// 查询数据
$query = self::where('order_status', '=', $type);
// 非店长不带入user_id查询
if (!UserService::isStore()) {
9 months ago
$query = $query->where('user_id', '=', $userId);
}
return $query->count();
}
9 months ago
10 months ago
}