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

127 lines
3.4 KiB

<?php
namespace app\api\model;
use app\api\service\User as UserService;
use app\common\enum\RecoveryStatusEnum;
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
*/
public function getUserList(array $where = [], int $listRows = 15): Paginator
{
// 当前用户ID
$userId = UserService::getCurrentLoginUserId();
if (!UserService::isStore()) {
$where = array_merge($where, ['user_id' => $userId]);
}
//分销商工程师
return $this->where($where)
->where($where)
->order(['create_time' => 'desc'])
->paginate($listRows);
}
/**
* @notes:订单详情
* @param int $orderId
* @return BaseRecoveryOrder|array|null
* @throws BaseException
* @author: wanghousheng
*/
public function getDetails(int $orderId)
{
$where['order_id'] = $orderId;
$where['user_id'] = UserService::getCurrentLoginUserId();
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
* @param int $orderId
* @param array $imageIds
* @return bool
* @author: wanghousheng
*/
public function edit(array $data, int $orderId, array $imageIds = []): bool
{
if ($this->where(['order_id' => $orderId])->save($data)) {
if ($imageIds) {
RecoveryImage::updates($orderId, $imageIds);
}
return true;
}
return false;
}
/**
* @notes:取消
* @param int $orderId
* @return bool
* @throws BaseException
* @author: wanghousheng
*/
public function cancel(int $orderId): bool
{
$where['order_id'] = $orderId;
// 当前用户ID
$userId = UserService::getCurrentLoginUserId();
if (!UserService::isStore()) {
$where['user_id'] = $userId;
}
$info = static::detail($where);
if (!$info->isEmpty() && $info['order_status'] == RecoveryStatusEnum::ACCEPTED) {
$this->where(['order_id' => $orderId])->save(['order_status' => RecoveryStatusEnum::CANCEL]);
return true;
}
return false;
}
}