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.
103 lines
2.7 KiB
103 lines
2.7 KiB
10 months ago
|
<?php
|
||
|
|
||
|
namespace app\api\model;
|
||
|
|
||
|
use app\api\service\User as UserService;
|
||
|
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 $recoveryId
|
||
|
* @return BaseRecoveryOrder|array|null
|
||
|
* @throws BaseException
|
||
|
* @author: wanghousheng
|
||
|
*/
|
||
|
public function getDetails(int $recoveryId)
|
||
|
{
|
||
|
$where['recovery_id'] = $recoveryId;
|
||
|
$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 $recoveryId
|
||
|
* @param array $imageIds
|
||
|
* @return bool
|
||
|
* @author: wanghousheng
|
||
|
*/
|
||
|
public function edit(array $data, int $recoveryId, array $imageIds = []): bool
|
||
|
{
|
||
|
if ($this->where(['recovery_id' => $recoveryId])->save($data)) {
|
||
|
if ($imageIds) {
|
||
|
RecoveryImage::updates($recoveryId, $imageIds);
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
}
|