88 lines
2.4 KiB
PHP
88 lines
2.4 KiB
PHP
<?php
|
|
declare (strict_types=1);
|
|
|
|
namespace app\store\model;
|
|
|
|
use app\store\model\store\UserRole;
|
|
use think\Session;
|
|
use app\common\model\Checkout as CheckoutModel;
|
|
use app\store\model\Order as OrderModel;
|
|
use app\store\model\store\User as UserModel;
|
|
|
|
use app\store\model\merchant\BalanceLog as BalanceLogModel;
|
|
use app\store\service\store\User as StoreUserService;
|
|
use app\common\enum\merchant\balanceLog\Scene as SceneEnum;
|
|
use app\common\library\helper;
|
|
|
|
/**
|
|
* 结账模型
|
|
* Class Checkout
|
|
* @package app\store\model
|
|
*/
|
|
class Checkout extends CheckoutModel
|
|
{
|
|
/**
|
|
* 获取商户列表
|
|
* @param array $data
|
|
* @return \think\Paginator
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function getList($data = [])
|
|
{
|
|
return $this->with(['user'])
|
|
->order(['create_time' => 'desc'])
|
|
->where($data)
|
|
->paginate(15);
|
|
}
|
|
|
|
/**
|
|
* 结账
|
|
* @param $data
|
|
* @param $user
|
|
* @return bool|false|int
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function checkout($data, $user)
|
|
{
|
|
if (empty($data['end_time'])) {
|
|
$this->error = '请选择结账结束时间';
|
|
return false;
|
|
}
|
|
$this->startTrans();
|
|
try {
|
|
$lastData = self::getSingle();
|
|
$data['start_time'] = $lastData['end_time'] ?? '';
|
|
if(empty($data['start_time'])){
|
|
$firstOrder = OrderModel::getSingle(['pay_status' => 20]);
|
|
$data['start_time'] = $firstOrder['create_time'];
|
|
}
|
|
$OrderModel = new OrderModel;
|
|
$data['num'] = $OrderModel->getPayOrderTotal($data['start_time'], $data['end_time']);
|
|
$data['amount'] = $OrderModel->getOrderTotalPrice($data['start_time'], $data['end_time']);
|
|
$data['start_time'] = strtotime($data['start_time']);
|
|
$data['end_time'] = strtotime($data['end_time']);
|
|
$data['store_user_id'] = $user['store_user_id'];
|
|
$data['store_id'] = self::$storeId;
|
|
$this->save($data);
|
|
|
|
$this->commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
$this->error = $e->getMessage();
|
|
$this->rollback();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 软删除
|
|
* @return false|int
|
|
*/
|
|
public function setDelete()
|
|
{
|
|
return $this->delete();
|
|
}
|
|
|
|
|
|
}
|