初始化项目
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use think\Session;
|
||||
use app\common\model\Shop as ShopModel;
|
||||
use app\store\model\Order as OrderModel;
|
||||
use app\store\model\store\User;
|
||||
|
||||
/**
|
||||
* 商家用户模型
|
||||
* Class StoreUser
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Shop extends ShopModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
* @param $params
|
||||
* @param array $user
|
||||
* @return \think\Paginator
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getList($params, $user = [])
|
||||
{
|
||||
$filter = [];
|
||||
if(isset($params['status']) && (int)$params['status']>=0){
|
||||
$filter[] = ['status', '=', (int)$params['status']];
|
||||
}
|
||||
if(isset($params['shop_name'])){
|
||||
$filter[] = ['shop_name', 'like', "%{$params['shop_name']}%"];
|
||||
}
|
||||
if($user['is_super'] == 0) {
|
||||
$filter[] = ['store_user_id', 'in', User::getScope($user)];
|
||||
}
|
||||
return $this->where('is_delete', '=', '0')
|
||||
->with('admin')
|
||||
->where($filter)
|
||||
->order(['create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param $data
|
||||
* @return bool|false|int
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function add($data)
|
||||
{
|
||||
if (empty($data['shop_name'])) {
|
||||
$this->error = '请填写店铺名称';
|
||||
return false;
|
||||
}
|
||||
$this->startTrans();
|
||||
try {
|
||||
$data['store_id'] = self::$storeId;
|
||||
$this->save($data);
|
||||
$this->commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
$this->rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function edit($data)
|
||||
{
|
||||
if (empty($data['shop_name'])) {
|
||||
$this->error = '请填写店铺名称';
|
||||
return false;
|
||||
}
|
||||
$this->startTrans();
|
||||
try {
|
||||
// 更新管理员记录
|
||||
$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->save(['is_delete' => 1]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 判断是否已到当日收款上限
|
||||
* @param $order
|
||||
* @return false|int
|
||||
*/
|
||||
public function inspection($order)
|
||||
{
|
||||
$max_money = $this['max_money']; //每日收款上限
|
||||
$orderModel = new OrderModel;
|
||||
$startTime = strtotime(date("Y-m-d"));
|
||||
$totalMoney = $orderModel->getOrderTotalPriceCustom(['shop_id' => $order['shop_id'], 'order_status' => 20, 'create_time' => [
|
||||
['>=', $startTime],
|
||||
['<', $startTime + 86400],
|
||||
]]);
|
||||
$now = $totalMoney > 0 ? $this['payment'] + $order['pay_price'] : $order['pay_price'];
|
||||
$data = [
|
||||
'payment' => $now,
|
||||
];
|
||||
//如果超限 则直接下线停止接单,并且当天不可上线
|
||||
if ($now >= $max_money) {
|
||||
$data['status'] = 2;
|
||||
$data['stop_date'] = date("Y-m-d");
|
||||
}
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user