初始化项目
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Account as AccountModel;
|
||||
|
||||
/**
|
||||
* 公司用户池模型
|
||||
* Class Account
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Account extends AccountModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取当前用户总数
|
||||
* @param array $param 查询参数
|
||||
* @return int|string
|
||||
*/
|
||||
public function getUserTotal(array $param = [])
|
||||
{
|
||||
// 检索查询条件
|
||||
$filter = $this->getUserTotalFilter($param);
|
||||
// 查询结果
|
||||
return $this->where($filter)
|
||||
->where('is_delete', '=', '0')
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户总数的查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getUserTotalFilter(array $param = [])
|
||||
{
|
||||
// 默认查询参数
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'search' => null, // 模糊搜索
|
||||
'last_called_at' => null, // 最后使用时间
|
||||
'company_id' => null, // 公司ID
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
if (!is_null($params['last_called_at'])) {
|
||||
$startTime = strtotime($params['last_called_at']);
|
||||
$filter[] = ['last_called_at', '>=', $startTime];
|
||||
$filter[] = ['last_called_at', '<', $startTime + 86400];
|
||||
}
|
||||
if ($params['company_id']) {
|
||||
$filter[] = ['company_id', '=', $params['company_id']];
|
||||
}
|
||||
!empty($params['search']) && $filter[] = ['userNo|userName|mobile', 'like', "%{$params['search']}%"];
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 检索查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取用户列表
|
||||
return $this->with(['company'])
|
||||
->where($filter)
|
||||
->where('is_delete', '=', '0')
|
||||
->order(['create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param = [])
|
||||
{
|
||||
// 默认查询条件
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'search' => '', // 用户名称|手机号
|
||||
'company_id' => '', // 公司ID
|
||||
'last_called_at' => null, // 最后时间时间
|
||||
'store_user_id' => null, // 所属员工
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 微信昵称
|
||||
!empty($params['search']) && $filter[] = ['userNo|userName|mobile', 'like', "%{$params['search']}%"];
|
||||
// 所属公司
|
||||
$params['company_id'] && $filter[] = ['company_id', '=', (int)$params['company_id']];
|
||||
// 起止时间
|
||||
if (!empty($params['last_called_at'])) {
|
||||
$times = between_time($params['last_called_at']);
|
||||
$filter[] = ['last_called_at', '>=', $times['start_time']];
|
||||
$filter[] = ['last_called_at', '<', $times['end_time'] + 86400];
|
||||
}
|
||||
// 所属员工
|
||||
$params['store_user_id'] && $filter[] = ['store_user_id', 'in', (array)$params['store_user_id']];
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function setDelete()
|
||||
{
|
||||
return $this->transaction(function () {
|
||||
// 标记为已删除
|
||||
return $this->save(['is_delete' => 1]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param $data
|
||||
* @param array $user
|
||||
* @return bool|false|int
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function add($data, $user = [])
|
||||
{
|
||||
$this->startTrans();
|
||||
try {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function edit($data)
|
||||
{
|
||||
if (empty($data['userNo'])) {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Article as ArticleModel;
|
||||
|
||||
/**
|
||||
* 文章模型
|
||||
* Class Article
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Article extends ArticleModel
|
||||
{
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 查询参数
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'title' => '', // 文章标题
|
||||
'categoryId' => 0, // 文章分类id
|
||||
'status' => -1, // 文章状态
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 文章标题
|
||||
!empty($params['title']) && $filter[] = ['title', 'like', "%{$params['title']}%"];
|
||||
// 文章分类id
|
||||
$params['categoryId'] > 0 && $filter[] = ['category_id', '=', $params['categoryId']];
|
||||
// 文章状态
|
||||
$params['status'] > -1 && $filter[] = ['status', '=', $params['status']];
|
||||
// 查询列表数据
|
||||
return $this->with(['image', 'category'])
|
||||
->withoutField(['content'])
|
||||
->where($filter)
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['sort' => 'asc', 'create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param array $data
|
||||
* @return false|int
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
if (empty($data['image_id'])) {
|
||||
$this->error = '请上传封面图';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['content'])) {
|
||||
$this->error = '请输入文章内容';
|
||||
return false;
|
||||
}
|
||||
$data['store_id'] = self::$storeId;
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool|int
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
if (empty($data['image_id'])) {
|
||||
$this->error = '请上传封面图';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['content'])) {
|
||||
$this->error = '请输入文章内容';
|
||||
return false;
|
||||
}
|
||||
return $this->save($data) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 软删除
|
||||
* @return false|int
|
||||
*/
|
||||
public function setDelete()
|
||||
{
|
||||
return $this->save(['is_delete' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文章总数量
|
||||
* @param array $where
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getArticleTotal(array $where = [])
|
||||
{
|
||||
return (new static)->where($where)->where('is_delete', '=', 0)->count();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Bank as BankModel;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 银行账户模型
|
||||
* Class Goods
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Bank extends BankModel
|
||||
{
|
||||
/**
|
||||
* 添加银行账户
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
/*if (!isset($data['images']) || empty($data['images'])) {
|
||||
$this->error = '请上传商品图片';
|
||||
return false;
|
||||
}*/
|
||||
$data['wxapp_id'] = $data['sku']['wxapp_id'] = self::$wxapp_id;
|
||||
// 开启事务
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 添加商品
|
||||
$this->allowField(true)->save($data);
|
||||
// 商品图片
|
||||
//$this->addSupplierImages($data['images']);
|
||||
Db::commit();
|
||||
return $this->bank_id;
|
||||
} catch (\Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
Db::rollback();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加供货商图片
|
||||
* @param $images
|
||||
* @return int
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
private function addSupplierImages($images)
|
||||
{
|
||||
$this->image()->delete();
|
||||
$data = array_map(function ($image_id) {
|
||||
return [
|
||||
'image_id' => $image_id,
|
||||
'wxapp_id' => self::$wxapp_id
|
||||
];
|
||||
}, $images);
|
||||
return $this->image()->saveAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑银行账户
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
public function edit($data)
|
||||
{
|
||||
/*if (!isset($data['images']) || empty($data['images'])) {
|
||||
$this->error = '请上传商品图片';
|
||||
return false;
|
||||
}*/
|
||||
$data['wxapp_id'] = $data['sku']['wxapp_id'] = self::$wxapp_id;
|
||||
|
||||
// 开启事务
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 保存商品
|
||||
$this->allowField(true)->save($data);
|
||||
// 商品图片
|
||||
//$this->addSupplierImages($data['images']);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 修改银行账户状态
|
||||
* @param $status
|
||||
* @return false|int
|
||||
*/
|
||||
public function setStatus($status)
|
||||
{
|
||||
return $this->save(['status' => $status]) !== false;
|
||||
}
|
||||
/**
|
||||
* 修改银行其他账户状态为非默认,只能有一个默认
|
||||
* @param $bank_id
|
||||
* @param $store_user_id
|
||||
* @return false|int
|
||||
*/
|
||||
public function setOtherStatus($bank_id,$store_user_id)
|
||||
{
|
||||
$where = array(
|
||||
'bank_id' => array('neq', $bank_id),
|
||||
'store_user_id' => array('eq', $store_user_id),
|
||||
);
|
||||
return $this->save(['status' => 2],$where) !== false;
|
||||
}
|
||||
/**
|
||||
* 删除
|
||||
* @param $bank_id
|
||||
* @return false|int
|
||||
*/
|
||||
public function setDelete($bank_id)
|
||||
{
|
||||
return $this->where(['bank_id' => $bank_id])->delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Card as CardModel;
|
||||
|
||||
/**
|
||||
* 充值卡模型
|
||||
* Class Card
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Card extends CardModel
|
||||
{
|
||||
/**
|
||||
* 获取充值卡列表
|
||||
* @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(18);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param $data
|
||||
* @param array $user
|
||||
* @return bool|false|int
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function add($data, $user = [])
|
||||
{
|
||||
$this->startTrans();
|
||||
try {
|
||||
if(isset($data['card_number'])){
|
||||
$data['store_user_id'] = $user['store_user_id'];
|
||||
$data['store_id'] = self::$storeId;
|
||||
$this->save($data);
|
||||
}else {
|
||||
foreach ($data as &$item){
|
||||
$item['store_user_id'] = $user['store_user_id'];
|
||||
$item['store_id'] = self::$storeId;
|
||||
}
|
||||
$this->saveAll($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]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Category as CategoryModel;
|
||||
|
||||
/**
|
||||
* 商品分类模型
|
||||
* Class Category
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Category extends CategoryModel
|
||||
{
|
||||
/**
|
||||
* 添加新记录
|
||||
* @param $data
|
||||
* @return false|int
|
||||
*/
|
||||
public function add($data)
|
||||
{
|
||||
$data['store_id'] = self::$storeId;
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑记录
|
||||
* @param $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function edit($data)
|
||||
{
|
||||
// 判断上级分类是否为当前子级
|
||||
if ($data['parent_id'] > 0) {
|
||||
// 获取所有上级id集
|
||||
$parentIds = $this->getTopCategoryIds($data['parent_id']);
|
||||
if (in_array($this['category_id'], $parentIds)) {
|
||||
$this->error = '上级分类不允许设置为当前子分类';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 是否删除图片
|
||||
!isset($data['image_id']) && $data['image_id'] = 0;
|
||||
return $this->save($data) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有上级id集
|
||||
* @param int $categoryId
|
||||
* @param null|array $list
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function getTopCategoryIds(int $categoryId, $list = null)
|
||||
{
|
||||
static $parentIds = [];
|
||||
is_null($list) && $list = $this->getAll();
|
||||
foreach ($list as $item) {
|
||||
if ($item['category_id'] == $categoryId && $item['parent_id'] > 0) {
|
||||
$parentIds[] = $item['parent_id'];
|
||||
$this->getTopCategoryIds($item['parent_id'], $list);
|
||||
}
|
||||
}
|
||||
return $parentIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* @return bool
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
// 判断是否存在下级分类
|
||||
if (static::detail(['parent_id' => $this['category_id']])) {
|
||||
$this->error = '当前分类下存在子分类,不允许删除';
|
||||
return false;
|
||||
}
|
||||
// 判断该分类是否被商品引用
|
||||
$goodsCount = GoodsCategoryRel::getCountByCategoryId($this['category_id']);
|
||||
if ($goodsCount > 0) {
|
||||
$this->error = "该分类被{$goodsCount}个商品引用,不允许删除";
|
||||
return false;
|
||||
}
|
||||
// 删除分类记录
|
||||
return $this->delete();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use think\Session;
|
||||
use app\common\model\Code as CodeModel;
|
||||
use app\common\model\Shop as ShopModel;
|
||||
use app\store\model\Order as OrderModel;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 商家用户模型
|
||||
* Class StoreUser
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Code extends CodeModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取支付码列表
|
||||
* @return \think\Paginator
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getList($where)
|
||||
{
|
||||
return $this->where($where)
|
||||
->field('*,FROM_UNIXTIME(create_time+expiration_time) as expiration_time')
|
||||
->order(['create_time' => 'desc'])
|
||||
->with(['shop','user'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param $data
|
||||
* @return bool|false|int
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function add($data)
|
||||
{
|
||||
if (empty($data['shop_id'])) {
|
||||
$this->error = '请选择店铺';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['code_account'])) {
|
||||
$this->error = '请填写产码账号';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['order_no'])) {
|
||||
$this->error = '请填写订单号';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['passageway'])) {
|
||||
$this->error = '请选择通道编号';
|
||||
return false;
|
||||
}
|
||||
if (in_array($data['passageway'],['ZFBH5','SNZFBH5']) && empty($data['alipay'])) {
|
||||
$this->error = '请填写支付宝链接';
|
||||
return false;
|
||||
}
|
||||
if ($data['passageway'] == 'WX' && empty($data['link'])) {
|
||||
$this->error = '请填写微信链接';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['money'])) {
|
||||
$this->error = '请填写金额';
|
||||
return false;
|
||||
}
|
||||
//判断微信产码数量是否超限
|
||||
/*if($data['passageway'] == 'WX'){
|
||||
$custNo = substr($data['link'],strripos($data['link'],"custNo=")+7,10);
|
||||
$num = $this->where(
|
||||
[
|
||||
'passageway'=>'WX',
|
||||
'link'=>['like','%'.$custNo.'%'],
|
||||
])
|
||||
->count();
|
||||
if($num >= 8){
|
||||
$this->error = '账号【'.$custNo.'】已达到产码上限8个';
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
if($data['passageway'] == 'ZFBH5'){
|
||||
$data['link'] = $data['alipay'];
|
||||
$searchUrl = $data['link'];
|
||||
}else {
|
||||
$otherPay = "https://order.suning.com/pay/otherPay.do?{{parameter}}&payChannel=PC";
|
||||
$parameter = strstr($data['link'], 'orderId');
|
||||
$searchUrl = str_replace("{{parameter}}", $parameter, $otherPay);
|
||||
}
|
||||
$data['search_url'] = $searchUrl;
|
||||
$this->startTrans();
|
||||
try {
|
||||
//$shop = ShopModel::detail($data['shop_id']);
|
||||
//$data['store_user_id'] = $shop['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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function edit($data)
|
||||
{
|
||||
if (empty($data['shop_id'])) {
|
||||
$this->error = '请选择店铺';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['code_account'])) {
|
||||
$this->error = '请填写产码账号';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['order_no'])) {
|
||||
$this->error = '请填写订单号';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['passageway'])) {
|
||||
$this->error = '请选择通道编号';
|
||||
return false;
|
||||
}
|
||||
if (in_array($data['passageway'],['ZFBH5','SNZFBH5']) && empty($data['alipay'])) {
|
||||
$this->error = '请填写支付宝链接';
|
||||
return false;
|
||||
}
|
||||
if ($data['passageway'] == 'WX' && empty($data['link'])) {
|
||||
$this->error = '请填写微信链接';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['money'])) {
|
||||
$this->error = '请填写金额';
|
||||
return false;
|
||||
}
|
||||
if($data['passageway'] == 'ZFBH5'){
|
||||
$data['link'] = $data['alipay'];
|
||||
$searchUrl = $data['link'];
|
||||
}else {
|
||||
if($data['passageway'] == 'SNZFBH5')$data['link'] = $data['alipay'];
|
||||
$otherPay = "https://order.suning.com/pay/otherPay.do?{{parameter}}&payChannel=PC";
|
||||
$parameter = strstr($data['link'], 'orderId');
|
||||
$searchUrl = str_replace("{{parameter}}", $parameter, $otherPay);
|
||||
}
|
||||
$data['search_url'] = $searchUrl;
|
||||
$this->startTrans();
|
||||
try {
|
||||
//$shop = ShopModel::detail($data['shop_id']);
|
||||
//$data['store_user_id'] = $shop['store_user_id'];
|
||||
// 更新管理员记录
|
||||
$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();
|
||||
}
|
||||
/**
|
||||
* 修改码的状态
|
||||
* @param int $order_id
|
||||
* @return false|int
|
||||
*/
|
||||
public function modifyUsed($order_id)
|
||||
{
|
||||
return $this->save([
|
||||
'status' => 2,
|
||||
'pay_status' => 1,
|
||||
'order_id' => $order_id,
|
||||
'allot_time' => time(),
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* 切换状态
|
||||
* @param $status
|
||||
* @return false|int
|
||||
*/
|
||||
public function changeStatus($status)
|
||||
{
|
||||
if($this['pay_status'] == 2){
|
||||
return '当前已是已核销状态';
|
||||
}
|
||||
if($bool = $this->save(['pay_status' => $status])){
|
||||
$bool = true;
|
||||
}
|
||||
return $bool;
|
||||
}
|
||||
/**
|
||||
* 切换启停状态
|
||||
* @param $state
|
||||
* @return false|int
|
||||
*/
|
||||
public function stateSwitch($state)
|
||||
{
|
||||
if(!in_array($state,[1,2])){
|
||||
return '未知状态';
|
||||
}
|
||||
if($bool = $this->save(['state' => $state])){
|
||||
$bool = true;
|
||||
}
|
||||
return $bool;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\library\helper;
|
||||
use app\common\model\Comment as CommentModel;
|
||||
use app\store\model\CommentImage as CommentImageModel;
|
||||
|
||||
/**
|
||||
* 商品评价模型
|
||||
* Class Comment
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Comment extends CommentModel
|
||||
{
|
||||
/**
|
||||
* 获取评价列表
|
||||
* @param array $param
|
||||
* @return mixed
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 检索查询条件
|
||||
$query = $this->setQueryFilter($param);
|
||||
// 查询列表数据
|
||||
return $query->with(['user.avatar', 'orderGoods' => ['image']])
|
||||
->alias($this->name)
|
||||
->field(["$this->name.*"])
|
||||
->join('goods', "goods.goods_id = {$this->name}.goods_id")
|
||||
->join('order', "order.order_id = {$this->name}.order_id")
|
||||
->join('user', "user.user_id = {$this->name}.user_id")
|
||||
->where("{$this->name}.is_delete", '=', 0)
|
||||
->order(["{$this->name}.sort" => 'asc', "{$this->name}.create_time" => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检索查询条件
|
||||
* @param array $param
|
||||
* @return \think\db\BaseQuery
|
||||
*/
|
||||
private function setQueryFilter(array $param)
|
||||
{
|
||||
// 实例化查询对象
|
||||
$query = $this->getNewQuery();
|
||||
// 查询参数
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'score' => 0, // 评分 (10好评 20中评 30差评)
|
||||
'goodsName' => '', // 商品名称/编码
|
||||
'orderNo' => '', // 订单号
|
||||
'userId' => 0, // 用户id
|
||||
'status' => -1 // 评价状态 -1全部
|
||||
]);
|
||||
// 评分
|
||||
$params['score'] > 0 && $query->where("{$this->name}.score", '=', $params['score']);
|
||||
// 商品名称/编码
|
||||
!empty($params['goodsName']) && $query->where('goods.goods_name|goods.goods_no', 'like', "%{$params['goodsName']}%");
|
||||
// 订单号
|
||||
!empty($params['orderNo']) && $query->where('order.order_no', 'like', "%{$params['orderNo']}%");
|
||||
// 用户id
|
||||
$params['userId'] > 0 && $query->where("{$this->name}.user_id", '=', $params['userId']);
|
||||
// 评价状态
|
||||
$params['status'] > -1 && $query->where("{$this->name}.status", '=', $params['status']);
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评价详情
|
||||
* @param int $commentId
|
||||
* @return Comment|array|null
|
||||
*/
|
||||
public function getDetail(int $commentId)
|
||||
{
|
||||
// 评价详情
|
||||
$detail = static::detail($commentId, ['images.file']);
|
||||
// 图片ID集
|
||||
$detail['imageIds'] = helper::getArrayColumn($detail['images'], 'image_id');
|
||||
// 图片列表
|
||||
$detail['imageList'] = helper::getArrayColumn($detail['images'], 'file');
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
return $this->transaction(function () use ($data) {
|
||||
// 更新商品图片记录
|
||||
CommentImageModel::updates((int)$this['comment_id'], $data['imageIds']);
|
||||
// 是否为图片评价
|
||||
$data['is_picture'] = !empty($data['images']);
|
||||
// 更新评论记录
|
||||
return $this->save($data);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 软删除
|
||||
* @return false|int
|
||||
*/
|
||||
public function setDelete()
|
||||
{
|
||||
return $this->save(['is_delete' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评价总数量
|
||||
* @return int|string
|
||||
*/
|
||||
public function getCommentTotal()
|
||||
{
|
||||
return $this->where(['is_delete' => 0])->count();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\CommentImage as CommentImageModel;
|
||||
|
||||
/**
|
||||
* 商品评价图片模型
|
||||
* Class GoodsImage
|
||||
* @package app\store\model
|
||||
*/
|
||||
class CommentImage extends CommentImageModel
|
||||
{
|
||||
/**
|
||||
* 批量写入记录
|
||||
* @param int $commentId
|
||||
* @param array $imageIds
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increased(int $commentId, array $imageIds)
|
||||
{
|
||||
$dataset = [];
|
||||
foreach ($imageIds as $imageId) {
|
||||
$dataset[] = [
|
||||
'image_id' => $imageId,
|
||||
'comment_id' => $commentId,
|
||||
'store_id' => self::$storeId
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新记录
|
||||
* @param $commentId
|
||||
* @param array $imageIds 新的图片集
|
||||
* @return array|false
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function updates(int $commentId, array $imageIds)
|
||||
{
|
||||
// 删除所有的sku记录
|
||||
static::deleteAll(['comment_id' => $commentId]);
|
||||
// 批量写入商品图片记录
|
||||
return static::increased($commentId, $imageIds);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\store\model\store\UserRole;
|
||||
use think\Session;
|
||||
use app\common\model\Company as CompanyModel;
|
||||
use app\store\model\Order as OrderModel;
|
||||
use app\store\model\store\User as UserModel;
|
||||
|
||||
use app\store\model\company\BalanceLog as BalanceLogModel;
|
||||
use app\store\service\store\User as StoreUserService;
|
||||
use app\common\enum\company\balanceLog\Scene as SceneEnum;
|
||||
use app\common\library\helper;
|
||||
|
||||
/**
|
||||
* 公司模型
|
||||
* Class Company
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Company extends CompanyModel
|
||||
{
|
||||
// 充值类型枚举: 余额
|
||||
const RECHARGE_TYPE_BALANCE = 'balance';
|
||||
/**
|
||||
* 获取商户列表
|
||||
* @param array $data
|
||||
* @return \think\Paginator
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getList($data = [])
|
||||
{
|
||||
return $this->order(['create_time' => 'desc'])
|
||||
->where($data)
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param $data
|
||||
* @param array $user
|
||||
* @return bool|false|int
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function add($data, $user = [])
|
||||
{
|
||||
if (empty($data['name'])) {
|
||||
$this->error = '请填写公司名称';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['address'])) {
|
||||
$this->error = '请填写公司地址';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['orgNo'])) {
|
||||
$this->error = '请填写公司编号';
|
||||
return false;
|
||||
}
|
||||
$this->startTrans();
|
||||
try {
|
||||
$data['privateKey'] = str_replace(["\r\n", "\n"], '', $data['privateKey']);
|
||||
$data['publicKey'] = str_replace(["\r\n", "\n"], '', $data['publicKey']);
|
||||
$data['platformPublicKey'] = str_replace(["\r\n", "\n"], '', $data['platformPublicKey']);
|
||||
$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;
|
||||
}
|
||||
}
|
||||
/*返回随机数*/
|
||||
public function suiji($digit=12){
|
||||
$a = "abcdefghijklmnopqrstuvwxyz";
|
||||
$x = strlen($a)-1;
|
||||
$html = "";
|
||||
for($i=1;$i<=$digit;$i++) {
|
||||
$rand = rand(1,$x);
|
||||
$html .= substr($a,$rand,1);
|
||||
if($i == 1){//某些语言变量首字母不能是数字
|
||||
$a .= "0123456789";
|
||||
$x = strlen($a)-1;
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function edit($data)
|
||||
{
|
||||
if (empty($data['name'])) {
|
||||
$this->error = '请填写公司名称';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['address'])) {
|
||||
$this->error = '请填写公司地址';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['orgNo'])) {
|
||||
$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->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 公司数据统计
|
||||
* @param $user
|
||||
* @param $get
|
||||
* @return \think\Paginator
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getCompanyStatistics($user,$get = [])
|
||||
{
|
||||
$filter = [];
|
||||
if($user['is_super'] == 0){
|
||||
$company_idArr = $user['company_id']?json_decode($user['company_id'],true):[];
|
||||
$filter[] = ['a.company_id', 'in', $company_idArr];
|
||||
}
|
||||
if(isset($get['name'])){
|
||||
$filter[] = ['a.name', 'like', '%'.$get['name'].'%'];
|
||||
}
|
||||
$times = [];
|
||||
if(isset($get['betweenTime'])) {
|
||||
$times = between_time($get['betweenTime']);
|
||||
}
|
||||
$and = "";
|
||||
if(isset($times['start_time'])){
|
||||
$and .= " and create_time >= '".$times['start_time']."' ";
|
||||
}
|
||||
if(isset($times['end_time'])){
|
||||
$and .= " and create_time < '".($times['end_time'] + 86400)."' ";
|
||||
}
|
||||
$and2 = " and create_time >= '".strtotime(date('Y-m-d'))."' and create_time < '".strtotime(date('Y-m-d').' 23:59:59')."' ";
|
||||
return $this->alias('a')
|
||||
->field('a.*, (select IFNULL(sum(amount),0) from yoshop_order where company_id = a.company_id and order_status = 20 '.$and.') as amount, (select IFNULL(sum(amount),0) from yoshop_order where company_id = a.company_id and order_status = 20 '.$and2.') as today')
|
||||
->order(['a.create_time' => 'desc'])
|
||||
->where($filter)
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商户充值
|
||||
* @param string $target 充值类型
|
||||
* @param array $data 表单数据
|
||||
* @return bool
|
||||
*/
|
||||
public function recharge(string $target, array $data)
|
||||
{
|
||||
// 当前操作人用户名
|
||||
$storeUserName = StoreUserService::getLoginInfo()['user']['user_name'];
|
||||
if ($target === self::RECHARGE_TYPE_BALANCE) {
|
||||
return $this->rechargeToBalance($storeUserName, $data['balance']);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商户充值:余额
|
||||
* @param string $storeUserName
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
private function rechargeToBalance(string $storeUserName, array $data)
|
||||
{
|
||||
if (!isset($data['money']) || $data['money'] === '' || $data['money'] < 0) {
|
||||
$this->error = '请输入正确的金额';
|
||||
return false;
|
||||
}
|
||||
// 判断充值方式,计算最终金额
|
||||
if ($data['mode'] === 'inc') {
|
||||
$diffMoney = $data['money'];
|
||||
} elseif ($data['mode'] === 'dec') {
|
||||
$diffMoney = -$data['money'];
|
||||
} else {
|
||||
$diffMoney = helper::bcsub($data['money'], $this['balance']);
|
||||
}
|
||||
// 更新记录
|
||||
$this->transaction(function () use ($storeUserName, $data, $diffMoney) {
|
||||
// 更新账户余额
|
||||
static::setIncBalance((int)$this['company_id'], (float)$diffMoney);
|
||||
// 新增余额变动记录
|
||||
BalanceLogModel::add(SceneEnum::ADMIN, [
|
||||
'company_id' => $this['company_id'],
|
||||
'money' => (float)$diffMoney,
|
||||
'remark' => $data['remark'],
|
||||
], [$storeUserName]);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Coupon as CouponModel;
|
||||
use app\common\enum\coupon\CouponType as CouponTypeEnum;
|
||||
use app\common\enum\coupon\ExpireType as ExpireTypeEnum;
|
||||
use app\common\enum\coupon\ApplyRange as ApplyRangeEnum;
|
||||
|
||||
/**
|
||||
* 优惠券模型
|
||||
* Class Coupon
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Coupon extends CouponModel
|
||||
{
|
||||
/**
|
||||
* 获取列表记录
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList(array $param = []): \think\Paginator
|
||||
{
|
||||
// 检索查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 查询列表数据
|
||||
return $this->where($filter)
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['sort', 'create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部记录
|
||||
* @param array $param
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAll(array $param = [])
|
||||
{
|
||||
return $this->where($this->getFilter($param))
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['sort', $this->getPk()])
|
||||
->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检索查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param = []): array
|
||||
{
|
||||
// 默认查询条件
|
||||
$param = $this->setQueryDefaultValue($param, ['search' => '']);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
!empty($param['search']) && $filter[] = ['name', 'like', "%{$param['search']}%"];
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加新记录
|
||||
* @param array $data
|
||||
* @return bool|false
|
||||
*/
|
||||
public function add(array $data): bool
|
||||
{
|
||||
$data['store_id'] = self::$storeId;
|
||||
return $this->save($this->createData($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function edit(array $data): bool
|
||||
{
|
||||
return $this->save($this->createData($data)) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数据
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
private function createData(array $data): array
|
||||
{
|
||||
// 折扣券记录有效期
|
||||
// 领取后生效
|
||||
if ($data['expire_type'] == ExpireTypeEnum::RECEIVE) {
|
||||
$data['start_time'] = $data['end_time'] = 0;
|
||||
} // 固定时间
|
||||
elseif ($data['expire_type'] == ExpireTypeEnum::FIXED_TIME) {
|
||||
$times = between_time($data['betweenTime']);
|
||||
$data['start_time'] = $times['start_time'];
|
||||
$data['end_time'] = $times['end_time'] + (86400 - 1);
|
||||
$data['expire_day'] = 1;
|
||||
}
|
||||
// 适用范围
|
||||
if ($data['apply_range'] == ApplyRangeEnum::ALL) {
|
||||
$data['apply_range_config'] = [];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录 (软删除)
|
||||
* @return bool
|
||||
*/
|
||||
public function setDelete(): bool
|
||||
{
|
||||
return $this->save(['is_delete' => 1]) !== false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Deduct as DeductModel;
|
||||
|
||||
class Deduct extends DeductModel
|
||||
{
|
||||
/**
|
||||
* 添加新记录
|
||||
* @param $data
|
||||
* @return false|int
|
||||
*/
|
||||
public function add($data)
|
||||
{
|
||||
$data['wxapp_id'] = self::$wxapp_id;
|
||||
return $this->allowField(true)->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑记录
|
||||
* @param $data
|
||||
* @return bool|int
|
||||
*/
|
||||
public function edit($data)
|
||||
{
|
||||
return $this->allowField(true)->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* @return bool|int
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
// 判断当前物流公司是否已被订单使用
|
||||
/*$Order = new Order;
|
||||
if ($orderCount = $Order->where(['express_id' => $this['express_id']])->count()) {
|
||||
$this->error = '当前物流公司已被' . $orderCount . '个订单使用,不允许删除';
|
||||
return false;
|
||||
}*/
|
||||
return $this->delete();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\store\model\Goods as GoodsModel;
|
||||
use app\common\model\Delivery as DeliveryModel;
|
||||
use app\store\model\DeliveryRule as DeliveryRuleModel;
|
||||
|
||||
/**
|
||||
* 配送模板模型
|
||||
* Class Delivery
|
||||
* @package app\common\model
|
||||
*/
|
||||
class Delivery extends DeliveryModel
|
||||
{
|
||||
/**
|
||||
* 获取全部
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function getAll()
|
||||
{
|
||||
$model = new static;
|
||||
return $model->order(['sort', $model->getPk()])->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList($param = [])
|
||||
{
|
||||
// 默认查询条件
|
||||
$params = $this->setQueryDefaultValue($param, ['search' => '']);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
!empty($params['search']) && $filter[] = ['name', 'like', "%{$params['search']}%"];
|
||||
// 查询列表数据
|
||||
return $this->with(['rule'])
|
||||
->where($filter)
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['sort', $this->getPk()])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加新记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
// 表单验证
|
||||
if (!$this->onValidate($data)) {
|
||||
return false;
|
||||
}
|
||||
$data['store_id'] = self::$storeId;
|
||||
// 事务处理
|
||||
$this->transaction(function () use ($data) {
|
||||
// 保存数据
|
||||
$this->save($data);
|
||||
// 添加模板区域及运费
|
||||
DeliveryRuleModel::increased((int)$this['delivery_id'], $data['rules']);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
// 表单验证
|
||||
if (!$this->onValidate($data)) {
|
||||
return false;
|
||||
}
|
||||
// 事务处理
|
||||
$this->transaction(function () use ($data) {
|
||||
// 保存数据
|
||||
$this->save($data);
|
||||
// 更新模板区域及运费
|
||||
DeliveryRuleModel::updates((int)$this['delivery_id'], $data['rules']);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单验证
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
private function onValidate(array $data)
|
||||
{
|
||||
if (!isset($data['rules']) || empty($data['rules'])) {
|
||||
$this->error = '请选择可配送区域';
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* @return bool
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
// 验证运费模板是否被商品使用
|
||||
if (!$this->checkIsUseGoods($this['delivery_id'])) {
|
||||
return false;
|
||||
}
|
||||
// 删除运费模板
|
||||
return $this->save(['is_delete' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证运费模板是否被商品使用
|
||||
* @param int $deliveryId
|
||||
* @return bool
|
||||
*/
|
||||
private function checkIsUseGoods(int $deliveryId)
|
||||
{
|
||||
// 判断是否存在商品
|
||||
$goodsCount = (new GoodsModel)->getGoodsTotal(['delivery_id' => $deliveryId]);
|
||||
if ($goodsCount > 0) {
|
||||
$this->error = "该模板被{$goodsCount}个商品使用,不允许删除";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\DeliveryRule as DeliveryRuleModel;
|
||||
|
||||
/**
|
||||
* 配送模板区域及运费模型
|
||||
* Class DeliveryRule
|
||||
* @package app\store\model
|
||||
*/
|
||||
class DeliveryRule extends DeliveryRuleModel
|
||||
{
|
||||
/**
|
||||
* 批量写入记录
|
||||
* @param int $deliveryId
|
||||
* @param array $rules
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increased(int $deliveryId, array $rules)
|
||||
{
|
||||
$dataset = [];
|
||||
foreach ($rules as $ruleItem) {
|
||||
$dataset[] = [
|
||||
'delivery_id' => $deliveryId,
|
||||
'region' => $ruleItem['region'],
|
||||
'region_text' => $ruleItem['region_text'],
|
||||
'first' => $ruleItem['first'],
|
||||
'first_fee' => $ruleItem['first_fee'],
|
||||
'additional' => $ruleItem['additional'],
|
||||
'additional_fee' => $ruleItem['additional_fee'],
|
||||
'store_id' => self::$storeId
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新关系记录
|
||||
* @param $deliveryId
|
||||
* @param array $rules 新的图片集
|
||||
* @return array|false
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function updates(int $deliveryId, array $rules)
|
||||
{
|
||||
// 删除所有的记录
|
||||
static::deleteAll(['delivery_id' => $deliveryId]);
|
||||
// 批量写入记录
|
||||
return static::increased($deliveryId, $rules);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Express as ExpressModel;
|
||||
|
||||
class Express extends ExpressModel
|
||||
{
|
||||
/**
|
||||
* 添加新记录
|
||||
* @param $data
|
||||
* @return false|int
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
$data['store_id'] = self::$storeId;
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑记录
|
||||
* @param $data
|
||||
* @return bool|int
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
// 判断当前物流公司是否已被订单使用
|
||||
$Order = new Order;
|
||||
if ($orderCount = $Order->where(['express_id' => $this['express_id']])->count()) {
|
||||
$this->error = '当前物流公司已被' . $orderCount . '个订单使用,不允许删除';
|
||||
return false;
|
||||
}
|
||||
return $this->delete();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\library\helper;
|
||||
use app\store\model\Spec as SpecModel;
|
||||
use app\common\model\Goods as GoodsModel;
|
||||
use app\store\model\GoodsCoupon as GoodsCouponModel;
|
||||
use app\store\model\GoodsSku as GoodsSkuModel;
|
||||
use app\store\model\GoodsImage as GoodsImageModel;
|
||||
use app\store\model\GoodsSpecRel as GoodsSpecRelModel;
|
||||
use app\store\model\goods\ServiceRel as GoodsServiceRelModel;
|
||||
use app\store\model\GoodsCategoryRel as GoodsCategoryRelModel;
|
||||
use app\store\service\Goods as GoodsService;
|
||||
use app\common\enum\goods\SpecType as SpecTypeEnum;
|
||||
use app\common\enum\goods\Status as GoodsStatusEnum;
|
||||
use cores\exception\BaseException;
|
||||
|
||||
/**
|
||||
* 商品模型
|
||||
* Class Goods
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Goods extends GoodsModel
|
||||
{
|
||||
/**
|
||||
* 获取商品详情
|
||||
* @param int $goodsId
|
||||
* @return mixed
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getDetail(int $goodsId)
|
||||
{
|
||||
// 获取商品基础信息
|
||||
$goodsInfo = $this->getBasic($goodsId);
|
||||
// 分类ID集
|
||||
$goodsInfo['categoryIds'] = GoodsCategoryRelModel::getCategoryIds($goodsInfo['goods_id']);
|
||||
// 商品多规格属性列表
|
||||
if ($goodsInfo['spec_type'] == SpecTypeEnum::MULTI) {
|
||||
$goodsInfo['specList'] = GoodsSpecRelModel::getSpecList($goodsInfo['goods_id']);
|
||||
}
|
||||
// 服务与承诺
|
||||
$goodsInfo['serviceIds'] = GoodsServiceRelModel::getServiceIds($goodsInfo['goods_id']);
|
||||
// 商品规格是否锁定(锁定状态下不允许编辑规格)
|
||||
$goodsInfo['isSpecLocked'] = GoodsService::checkSpecLocked($goodsId);
|
||||
// 优惠券列表
|
||||
$goodsInfo['couponList'] = GoodsCouponModel::getCouponList($goodsInfo['goods_id']);
|
||||
// 返回商品详细信息
|
||||
return $goodsInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品基础信息
|
||||
* @param int $goodsId
|
||||
* @return mixed
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function getBasic(int $goodsId)
|
||||
{
|
||||
// 关联查询
|
||||
$with = ['images.file', 'skuList.image', 'video', 'videoCover'];
|
||||
// 获取商品记录
|
||||
$goodsInfo = static::detail($goodsId, $with);
|
||||
empty($goodsInfo) && throwError('很抱歉,商品信息不存在');
|
||||
// 整理商品数据并返回
|
||||
return parent::setGoodsData($goodsInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加商品
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \cores\exception\BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function add(array $data): bool
|
||||
{
|
||||
// 创建商品数据
|
||||
$data = $this->createData($data);
|
||||
// 事务处理
|
||||
$this->transaction(function () use ($data) {
|
||||
// 添加商品
|
||||
$this->save($data);
|
||||
// 新增商品与分类关联
|
||||
GoodsCategoryRelModel::increased((int)$this['goods_id'], $data['categoryIds']);
|
||||
// 新增商品与图片关联
|
||||
GoodsImageModel::increased((int)$this['goods_id'], $data['imagesIds']);
|
||||
// 新增商品与规格关联
|
||||
GoodsSpecRelModel::increased((int)$this['goods_id'], $data['newSpecList']);
|
||||
// 新增商品sku信息
|
||||
GoodsSkuModel::add((int)$this['goods_id'], $data['spec_type'], $data['newSkuList']);
|
||||
// 新增服务与承诺关联
|
||||
GoodsServiceRelModel::increased((int)$this['goods_id'], $data['serviceIds']);
|
||||
// 新增优惠券关系记录
|
||||
GoodsCouponModel::increased((int)$this['goods_id'], $data['couponList']);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑商品
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \cores\exception\BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function edit(array $data): bool
|
||||
{
|
||||
// 创建商品数据
|
||||
$data = $this->createData($data);
|
||||
// 事务处理
|
||||
$this->transaction(function () use ($data) {
|
||||
// 更新商品
|
||||
$this->save($data);
|
||||
// 更新商品与分类关联
|
||||
GoodsCategoryRelModel::updates((int)$this['goods_id'], $data['categoryIds']);
|
||||
// 更新商品与图片关联
|
||||
GoodsImageModel::updates((int)$this['goods_id'], $data['imagesIds']);
|
||||
// 更新商品与规格关联
|
||||
GoodsSpecRelModel::updates((int)$this['goods_id'], $data['newSpecList']);
|
||||
// 更新商品sku信息
|
||||
GoodsSkuModel::edit((int)$this['goods_id'], $data['spec_type'], $data['newSkuList']);
|
||||
// 更新服务与承诺关联
|
||||
GoodsServiceRelModel::updates((int)$this['goods_id'], $data['serviceIds']);
|
||||
// 更新优惠券关系记录
|
||||
GoodsCouponModel::updates((int)$this['goods_id'], $data['couponList']);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改商品状态
|
||||
* @param array $goodsIds 商品id集
|
||||
* @param bool $state 为true表示上架
|
||||
* @return bool|false
|
||||
*/
|
||||
public function setStatus(array $goodsIds, bool $state): bool
|
||||
{
|
||||
// 批量更新记录
|
||||
return static::updateBase(['status' => $state ? 10 : 20], [['goods_id', 'in', $goodsIds]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 软删除
|
||||
* @param array $goodsIds
|
||||
* @return bool
|
||||
*/
|
||||
public function setDelete(array $goodsIds): bool
|
||||
{
|
||||
foreach ($goodsIds as $goodsId) {
|
||||
if (!GoodsService::checkIsAllowDelete($goodsId)) {
|
||||
$this->error = '当前商品正在参与其他活动,不允许删除';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 批量更新记录
|
||||
return static::updateBase(['is_delete' => 1], [['goods_id', 'in', $goodsIds]]);
|
||||
}
|
||||
|
||||
// 获取已售罄的商品
|
||||
public function getSoldoutGoodsTotal(): int
|
||||
{
|
||||
$filter = [
|
||||
['stock_total', '=', 0],
|
||||
['status', '=', GoodsStatusEnum::ON_SALE]
|
||||
];
|
||||
return $this->getGoodsTotal($filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前商品总数
|
||||
* @param array $where
|
||||
* @return int
|
||||
*/
|
||||
public function getGoodsTotal(array $where = []): int
|
||||
{
|
||||
return $this->where($where)->where('is_delete', '=', 0)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建商品数据
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
private function createData(array $data): array
|
||||
{
|
||||
// 默认数据
|
||||
$data = array_merge($data, [
|
||||
'line_price' => $data['line_price'] ?? 0,
|
||||
'content' => $data['content'] ?? '',
|
||||
'newSpecList' => [],
|
||||
'newSkuList' => [],
|
||||
'store_id' => self::$storeId,
|
||||
]);
|
||||
// 库存总量 stock_total
|
||||
// 商品价格 最低最高
|
||||
if ($data['spec_type'] == SpecTypeEnum::MULTI) {
|
||||
$data['stock_total'] = GoodsSkuModel::getStockTotal($data['specData']['skuList']);
|
||||
[$data['goods_price_min'], $data['goods_price_max']] = GoodsSkuModel::getGoodsPrices($data['specData']['skuList']);
|
||||
[$data['line_price_min'], $data['line_price_max']] = GoodsSkuModel::getLinePrices($data['specData']['skuList']);
|
||||
} elseif ($data['spec_type'] == SpecTypeEnum::SINGLE) {
|
||||
$data['goods_price_min'] = $data['goods_price_max'] = $data['goods_price'];
|
||||
$data['line_price_min'] = $data['line_price_max'] = $data['line_price'];
|
||||
$data['stock_total'] = $data['stock_num'];
|
||||
}
|
||||
// 规格和sku数据处理
|
||||
if ($data['spec_type'] == SpecTypeEnum::MULTI) {
|
||||
// 验证规格值是否合法
|
||||
SpecModel::checkSpecData($data['specData']['specList']);
|
||||
// 生成多规格数据 (携带id)
|
||||
$data['newSpecList'] = SpecModel::getNewSpecList($data['specData']['specList']);
|
||||
// 生成skuList (携带goods_sku_id)
|
||||
$data['newSkuList'] = GoodsSkuModel::getNewSkuList($data['newSpecList'], $data['specData']['skuList']);
|
||||
} elseif ($data['spec_type'] == SpecTypeEnum::SINGLE) {
|
||||
// 生成skuItem
|
||||
$data['newSkuList'] = helper::pick($data, ['goods_price', 'line_price', 'stock_num', 'goods_weight']);
|
||||
}
|
||||
// 检查优惠券数据
|
||||
GoodsCouponModel::checkCouponData($data['couponList']);
|
||||
// 单独设置折扣的配置
|
||||
$data['is_enable_grade'] == 0 && $data['is_alone_grade'] = 0;
|
||||
$aloneGradeEquity = [];
|
||||
if ($data['is_alone_grade'] == 1) {
|
||||
foreach ($data['alone_grade_equity'] as $key => $value) {
|
||||
$gradeId = str_replace('grade_id:', '', $key);
|
||||
$aloneGradeEquity[$gradeId] = $value;
|
||||
}
|
||||
}
|
||||
$data['alone_grade_equity'] = $aloneGradeEquity;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\GoodsCategoryRel as GoodsCategoryRelModel;
|
||||
|
||||
/**
|
||||
* 商品与分类关系模型
|
||||
* Class GoodsCategoryRel
|
||||
* @package app\store\model
|
||||
*/
|
||||
class GoodsCategoryRel extends GoodsCategoryRelModel
|
||||
{
|
||||
/**
|
||||
* 根据分类ID获取记录总数量
|
||||
* @param int $categoryId
|
||||
* @return int
|
||||
*/
|
||||
public static function getCountByCategoryId(int $categoryId)
|
||||
{
|
||||
return (new static)->alias('m')
|
||||
->join('goods', 'goods.goods_id = m.goods_id')
|
||||
->where('m.category_id', '=', $categoryId)
|
||||
->where('goods.is_delete', '=', 0)
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品分类ID集
|
||||
* @param int $goodsId
|
||||
* @return array
|
||||
*/
|
||||
public static function getCategoryIds(int $goodsId)
|
||||
{
|
||||
return (new static)->where('goods_id', '=', $goodsId)->column('category_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量写入商品分类记录
|
||||
* @param int $goodsId
|
||||
* @param array $categoryIds
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increased(int $goodsId, array $categoryIds)
|
||||
{
|
||||
$dataset = [];
|
||||
foreach ($categoryIds as $categoryId) {
|
||||
$dataset[] = [
|
||||
'category_id' => $categoryId,
|
||||
'goods_id' => $goodsId,
|
||||
'store_id' => self::$storeId
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新关系记录
|
||||
* @param $goodsId
|
||||
* @param array $categoryIds 新的分类集
|
||||
* @return array|false
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function updates(int $goodsId, $categoryIds)
|
||||
{
|
||||
// 已分配的分类集
|
||||
$assignCategoryIds = self::getCategoryIdsByGoodsId($goodsId);
|
||||
// 找出删除的分类
|
||||
$deleteCategoryIds = array_diff($assignCategoryIds, $categoryIds);
|
||||
if (!empty($deleteCategoryIds)) {
|
||||
static::deleteAll([
|
||||
['goods_id', '=', $goodsId],
|
||||
['category_id', 'in', $deleteCategoryIds]
|
||||
]);
|
||||
}
|
||||
// 找出添加的分类
|
||||
$newCategoryIds = array_diff($categoryIds, $assignCategoryIds);
|
||||
$dataset = [];
|
||||
foreach ($newCategoryIds as $categoryId) {
|
||||
$dataset[] = [
|
||||
'goods_id' => $goodsId,
|
||||
'category_id' => $categoryId,
|
||||
'store_id' => self::$storeId,
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定商品的所有分类id
|
||||
* @param int $goodsId
|
||||
* @return array
|
||||
*/
|
||||
public static function getCategoryIdsByGoodsId(int $goodsId)
|
||||
{
|
||||
return (new static)->where('goods_id', '=', $goodsId)->column('category_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\library\helper;
|
||||
use app\common\model\GoodsCoupon as GoodsCouponModel;
|
||||
use cores\exception\BaseException;
|
||||
|
||||
/**
|
||||
* 商品优惠券关系模型
|
||||
* Class GoodsCoupon
|
||||
* @package app\store\model
|
||||
*/
|
||||
class GoodsCoupon extends GoodsCouponModel
|
||||
{
|
||||
/**
|
||||
* 验证优惠券是否合法
|
||||
* @param array $couponList
|
||||
* @throws BaseException
|
||||
*/
|
||||
public static function checkCouponData(array $couponList)
|
||||
{
|
||||
$values = helper::getArrayColumn($couponList, 'coupon_id');
|
||||
if (count($couponList) != count(array_unique($values))) {
|
||||
throwError('很抱歉,不能存在重复的优惠券 请检查您的选择');
|
||||
}
|
||||
foreach ($couponList as $item) {
|
||||
if(empty($item['send_num'])){
|
||||
throwError('很抱歉,优惠券数量不能为空 请检查您的输入');
|
||||
}elseif($item['send_num'] < 0 || $item['send_num'] > 100){
|
||||
throwError('很抱歉,优惠券数量只能在1和100之间 请检查您的输入');
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 批量写入商品与优惠券关系记录
|
||||
* @param int $goodsId
|
||||
* @param array $couponList
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increased(int $goodsId, array $couponList)
|
||||
{
|
||||
$dataset = [];
|
||||
foreach ($couponList as $item) {
|
||||
$dataset[] = [
|
||||
'goods_id' => $goodsId,
|
||||
'coupon_id' => $item['coupon_id'],
|
||||
'send_num' => $item['send_num'],
|
||||
'store_id' => self::$storeId
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新商品与优惠券关系记录
|
||||
* @param int $goodsId
|
||||
* @param array $couponList
|
||||
* @return array|false
|
||||
*/
|
||||
public static function updates(int $goodsId, array $couponList)
|
||||
{
|
||||
// 删除所有的记录
|
||||
static::deleteAll(['goods_id' => $goodsId]);
|
||||
// 批量新增记录
|
||||
return static::increased($goodsId, $couponList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\GoodsImage as GoodsImageModel;
|
||||
|
||||
/**
|
||||
* 商品图片模型
|
||||
* Class GoodsImage
|
||||
* @package app\store\model
|
||||
*/
|
||||
class GoodsImage extends GoodsImageModel
|
||||
{
|
||||
/**
|
||||
* 批量写入商品图片记录
|
||||
* @param int $goodsId
|
||||
* @param array $imageIds
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increased(int $goodsId, array $imageIds)
|
||||
{
|
||||
$dataset = [];
|
||||
foreach ($imageIds as $imageId) {
|
||||
$dataset[] = [
|
||||
'image_id' => $imageId,
|
||||
'goods_id' => $goodsId,
|
||||
'store_id' => self::$storeId
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新关系记录
|
||||
* @param int $goodsId
|
||||
* @param array $imageIds 新的图片集
|
||||
* @return array|false
|
||||
*/
|
||||
public static function updates(int $goodsId, array $imageIds)
|
||||
{
|
||||
// 删除所有的sku记录
|
||||
static::deleteAll(['goods_id' => $goodsId]);
|
||||
// 批量写入商品图片记录
|
||||
return static::increased($goodsId, $imageIds);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\library\helper;
|
||||
use app\common\model\GoodsSku as GoodsSkuModel;
|
||||
use app\common\enum\goods\SpecType as SpecTypeEnum;
|
||||
|
||||
/**
|
||||
* 商品规格模型
|
||||
* Class GoodsSku
|
||||
* @package app\store\model
|
||||
*/
|
||||
class GoodsSku extends GoodsSkuModel
|
||||
{
|
||||
/**
|
||||
* 获取库存总数量 (根据sku列表数据)
|
||||
* @param array $skuList
|
||||
* @return float|int
|
||||
*/
|
||||
public static function getStockTotal(array $skuList)
|
||||
{
|
||||
return (int)helper::getArrayColumnSum($skuList, 'stock_num');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品价格高低区间 (根据sku列表数据)
|
||||
* @param array $skuList
|
||||
* @return array
|
||||
*/
|
||||
public static function getGoodsPrices(array $skuList): array
|
||||
{
|
||||
$goodsPriceArr = helper::getArrayColumn($skuList, 'goods_price');
|
||||
return empty($goodsPriceArr) ? [0, 0] : [min($goodsPriceArr), max($goodsPriceArr)];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取划线价格高低区间 (根据sku列表数据)
|
||||
* @param array $skuList
|
||||
* @return array
|
||||
*/
|
||||
public static function getLinePrices(array $skuList): array
|
||||
{
|
||||
$linePriceArr = helper::getArrayColumn($skuList, 'line_price');
|
||||
return empty($linePriceArr) ? [0, 0] : [min($linePriceArr), max($linePriceArr)];
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成skuList数据(写入goods_sku_id)
|
||||
* @param array $newSpecList
|
||||
* @param array $skuList
|
||||
* @return array
|
||||
*/
|
||||
public static function getNewSkuList(array $newSpecList, array $skuList): array
|
||||
{
|
||||
foreach ($skuList as &$skuItem) {
|
||||
$skuItem['specValueIds'] = static::getSpecValueIds($newSpecList, $skuItem['skuKeys']);
|
||||
$skuItem['goodsProps'] = static::getGoodsProps($newSpecList, $skuItem['skuKeys']);
|
||||
$skuItem['goods_sku_id'] = implode('_', $skuItem['specValueIds']);
|
||||
}
|
||||
return $skuList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据$skuKeys生成规格值id集
|
||||
* @param array $newSpecList
|
||||
* @param array $skuKeys
|
||||
* @return array
|
||||
*/
|
||||
private static function getSpecValueIds(array $newSpecList, array $skuKeys): array
|
||||
{
|
||||
$goodsSkuIdArr = [];
|
||||
foreach ($skuKeys as $skuKey) {
|
||||
$groupItem = helper::arraySearch($newSpecList, 'key', $skuKey['groupKey']);
|
||||
$specValueItem = helper::arraySearch($groupItem['valueList'], 'key', $skuKey['valueKey']);
|
||||
$goodsSkuIdArr[] = $specValueItem['spec_value_id'];
|
||||
}
|
||||
return $goodsSkuIdArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据$skuKeys生成规格属性记录
|
||||
* @param array $newSpecList
|
||||
* @param array $skuKeys
|
||||
* @return array
|
||||
*/
|
||||
private static function getGoodsProps(array $newSpecList, array $skuKeys): array
|
||||
{
|
||||
$goodsPropsArr = [];
|
||||
foreach ($skuKeys as $skuKey) {
|
||||
$groupItem = helper::arraySearch($newSpecList, 'key', $skuKey['groupKey']);
|
||||
$specValueItem = helper::arraySearch($groupItem['valueList'], 'key', $skuKey['valueKey']);
|
||||
$goodsPropsArr[] = [
|
||||
'group' => ['name' => $groupItem['spec_name'], 'id' => $groupItem['spec_id']],
|
||||
'value' => ['name' => $specValueItem['spec_value'], 'id' => $specValueItem['spec_value_id']]
|
||||
];
|
||||
}
|
||||
return $goodsPropsArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增商品sku记录
|
||||
* @param int $goodsId
|
||||
* @param array $newSkuList
|
||||
* @param int $specType
|
||||
* @return array|bool|false
|
||||
*/
|
||||
public static function add(int $goodsId, int $specType = SpecTypeEnum::SINGLE, array $newSkuList = [])
|
||||
{
|
||||
// 单规格模式
|
||||
if ($specType === SpecTypeEnum::SINGLE) {
|
||||
return (new static)->save(array_merge($newSkuList, [
|
||||
'goods_id' => $goodsId,
|
||||
'goods_sku_id' => 0,
|
||||
'store_id' => self::$storeId
|
||||
]));
|
||||
} // 多规格模式
|
||||
elseif ($specType === SpecTypeEnum::MULTI) {
|
||||
// 批量写入商品sku记录
|
||||
return static::increasedFroMulti($goodsId, $newSkuList);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品sku记录
|
||||
* @param int $goodsId
|
||||
* @param int $specType
|
||||
* @param array $skuList
|
||||
* @return array|bool|false
|
||||
*/
|
||||
public static function edit(int $goodsId, int $specType = SpecTypeEnum::SINGLE, array $skuList = [])
|
||||
{
|
||||
// 删除所有的sku记录
|
||||
static::deleteAll(['goods_id' => $goodsId]);
|
||||
// 新增商品sku记录
|
||||
return static::add($goodsId, $specType, $skuList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量写入商品sku记录
|
||||
* @param int $goodsId
|
||||
* @param array $skuList
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increasedFroMulti(int $goodsId, array $skuList)
|
||||
{
|
||||
$dataset = [];
|
||||
foreach ($skuList as $skuItem) {
|
||||
$dataset[] = array_merge($skuItem, [
|
||||
'goods_sku_id' => $skuItem['goods_sku_id'],
|
||||
'line_price' => $skuItem['line_price'] ?: 0.00,
|
||||
'goods_sku_no' => $skuItem['goods_sku_no'] ?: '',
|
||||
'stock_num' => $skuItem['stock_num'] ?: 0,
|
||||
'goods_weight' => $skuItem['goods_weight'] ?: 0,
|
||||
'goods_props' => $skuItem['goodsProps'],
|
||||
'spec_value_ids' => $skuItem['specValueIds'],
|
||||
'goods_id' => $goodsId,
|
||||
'store_id' => self::$storeId
|
||||
]);
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\GoodsSpecRel as GoodsSpecRelModel;
|
||||
|
||||
/**
|
||||
* 商品规格关系模型
|
||||
* Class GoodsSpecRel
|
||||
* @package app\store\model
|
||||
*/
|
||||
class GoodsSpecRel extends GoodsSpecRelModel
|
||||
{
|
||||
/**
|
||||
* 批量写入商品与规格值关系记录
|
||||
* @param int $goodsId
|
||||
* @param array $specList
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increased(int $goodsId, array $specList)
|
||||
{
|
||||
$dataset = [];
|
||||
foreach ($specList as $item) {
|
||||
foreach ($item['valueList'] as $specValueItem) {
|
||||
$dataset[] = [
|
||||
'goods_id' => $goodsId,
|
||||
'spec_id' => $item['spec_id'],
|
||||
'spec_value_id' => $specValueItem['spec_value_id'],
|
||||
'store_id' => self::$storeId
|
||||
];
|
||||
}
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新商品与规格值关系记录
|
||||
* @param int $goodsId
|
||||
* @param array $specList
|
||||
* @return array|false
|
||||
*/
|
||||
public static function updates(int $goodsId, array $specList)
|
||||
{
|
||||
// 删除所有的记录
|
||||
static::deleteAll(['goods_id' => $goodsId]);
|
||||
// 批量新增记录
|
||||
return static::increased($goodsId, $specList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Help as HelpModel;
|
||||
|
||||
/**
|
||||
* 模型类:帮助中心
|
||||
* Class Help
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Help extends HelpModel
|
||||
{
|
||||
/**
|
||||
* 新增记录
|
||||
* @param array $data
|
||||
* @return false|int
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
$data['store_id'] = self::$storeId;
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool|int
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
return $this->save($data) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* @return bool
|
||||
*/
|
||||
public function setDelete()
|
||||
{
|
||||
return $this->save(['is_delete' => 1]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\UserCoupon as UserCouponModel;
|
||||
use app\common\service\Order as OrderService;
|
||||
use app\store\model\GoodsCoupon as GoodsCouponModel;
|
||||
use app\store\model\store\UserRole;
|
||||
use think\Session;
|
||||
use app\common\model\Merchant as MerchantModel;
|
||||
use app\store\model\Goods as GoodsModel;
|
||||
use app\store\model\GoodsSku as GoodsSkuModel;
|
||||
use app\store\model\User as FrontUserModel;
|
||||
|
||||
use app\store\model\store\User as UserModel;
|
||||
|
||||
use app\store\model\merchant\BalanceLog as BalanceLogModel;
|
||||
use app\common\model\merchant\MerchantOrder as MerchantOrderModel;
|
||||
use app\store\service\store\User as StoreUserService;
|
||||
use app\common\enum\merchant\balanceLog\Scene as SceneEnum;
|
||||
use app\common\library\helper;
|
||||
// 生成订单
|
||||
use app\store\model\Coupon as CouponModel;
|
||||
|
||||
/**
|
||||
* 商户模型
|
||||
* Class StoreUser
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Merchant extends MerchantModel
|
||||
{
|
||||
// 充值类型枚举: 余额
|
||||
const RECHARGE_TYPE_BALANCE = 'balance';
|
||||
/**
|
||||
* 获取商户列表
|
||||
* @param array $data
|
||||
* @return \think\Paginator
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getList($data = [])
|
||||
{
|
||||
return $this->with(['referrer'])
|
||||
->order(['create_time' => 'desc'])
|
||||
->where($data)
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param $data
|
||||
* @param array $user
|
||||
* @return bool|false|int
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function add($data, $user = [])
|
||||
{
|
||||
if (empty($data['name'])) {
|
||||
$this->error = '请填写商户名称';
|
||||
return false;
|
||||
}
|
||||
if (floatval($user['level']) >= 3) {
|
||||
$this->error = '你没有创建代理商的权限';
|
||||
return false;
|
||||
}
|
||||
$this->startTrans();
|
||||
try {
|
||||
$data['orgNo'] = $this->createNo();
|
||||
$data['appKey'] = $this->suiji(30);
|
||||
$data['store_user_id'] = $user['store_user_id'];
|
||||
$data['parent_merchant_id'] = $user['merchant_id'];
|
||||
$data['level'] = floatval($user['level']) + 1;
|
||||
$data['store_id'] = self::$storeId;
|
||||
$data = array_merge($data, $this->secretKey());
|
||||
$this->save($data);
|
||||
|
||||
//创建商户登录账号
|
||||
$userModel = new UserModel();
|
||||
$newData['user_name'] = $data['name'];
|
||||
$newData['password'] = encryption_hash('123456');
|
||||
$newData['real_name'] = $data['name'];
|
||||
$newData['status'] = 1;
|
||||
$newData['is_super'] = 0;
|
||||
$newData['store_id'] = self::$storeId;
|
||||
//账号层级
|
||||
$newData['level'] = $data['level'];
|
||||
$newData['merchant_id'] = $this->merchant_id;
|
||||
$userModel->save($newData);
|
||||
// 新增角色关系记录
|
||||
UserRole::increased((int)$userModel['store_user_id'], [10014]);
|
||||
$this->commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
$this->rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/*返回随机数*/
|
||||
public function suiji($digit=12){
|
||||
$a = "abcdefghijklmnopqrstuvwxyz";
|
||||
$x = strlen($a)-1;
|
||||
$html = "";
|
||||
for($i=1;$i<=$digit;$i++) {
|
||||
$rand = rand(1,$x);
|
||||
$html .= substr($a,$rand,1);
|
||||
if($i == 1){//某些语言变量首字母不能是数字
|
||||
$a .= "0123456789";
|
||||
$x = strlen($a)-1;
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/*返回随机数*/
|
||||
public function secretKey(){
|
||||
// 生成 RSA 密钥对
|
||||
$config = array(
|
||||
'private_key_bits' => 2048,
|
||||
'private_key_type' => OPENSSL_KEYTYPE_RSA,
|
||||
);
|
||||
$keyPair = openssl_pkey_new($config);
|
||||
// 提取私钥
|
||||
openssl_pkey_export($keyPair, $privateKey);
|
||||
// 提取公钥
|
||||
$keyDetails = openssl_pkey_get_details($keyPair);
|
||||
$publicKey = $keyDetails['key'];
|
||||
|
||||
return ['privateKey'=>base64_encode($privateKey), 'publicKey'=>base64_encode($publicKey)];
|
||||
}
|
||||
|
||||
/** 生成编号
|
||||
* @param $prefix
|
||||
* @return string
|
||||
*/
|
||||
public static function createNo($prefix = 'S'): string
|
||||
{
|
||||
return $prefix . substr(implode('', array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function edit($data)
|
||||
{
|
||||
if (empty($data['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->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户数据统计
|
||||
* @param $user
|
||||
* @param $get
|
||||
* @return \think\Paginator
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getMerchantStatistics($user,$get = [])
|
||||
{
|
||||
$filter = [];
|
||||
if($user['is_super'] == 0){
|
||||
$merchant_idArr = $user['merchant_id']?json_decode($user['merchant_id'],true):[];
|
||||
$filter[] = ['a.merchant_id', 'in', $merchant_idArr];
|
||||
}
|
||||
if(isset($get['name'])){
|
||||
$filter[] = ['a.name', 'like', '%'.$get['name'].'%'];
|
||||
}
|
||||
$times = [];
|
||||
if(isset($get['betweenTime'])) {
|
||||
$times = between_time($get['betweenTime']);
|
||||
}
|
||||
$and = "";
|
||||
if(isset($times['start_time'])){
|
||||
$and .= " and create_time >= '".$times['start_time']."' ";
|
||||
}
|
||||
if(isset($times['end_time'])){
|
||||
$and .= " and create_time < '".($times['end_time'] + 86400)."' ";
|
||||
}
|
||||
$and2 = " and create_time >= '".strtotime(date('Y-m-d'))."' and create_time < '".strtotime(date('Y-m-d').' 23:59:59')."' ";
|
||||
return $this->alias('a')
|
||||
->field('a.*, (select IFNULL(sum(amount),0) from yoshop_order where merchant_id = a.merchant_id and order_status = 20 '.$and.') as amount, (select IFNULL(sum(amount),0) from yoshop_order where merchant_id = a.merchant_id and order_status = 20 '.$and2.') as today')
|
||||
->order(['a.create_time' => 'desc'])
|
||||
->where($filter)
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商户充值
|
||||
* @param string $target 充值类型
|
||||
* @param array $data 表单数据
|
||||
* @return bool
|
||||
*/
|
||||
public function recharge(string $target, array $data)
|
||||
{
|
||||
// 当前操作人用户名
|
||||
$storeUserName = StoreUserService::getLoginInfo()['user']['user_name'];
|
||||
if ($target === self::RECHARGE_TYPE_BALANCE) {
|
||||
return $this->rechargeToBalance($storeUserName, $data['balance']);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商户充值:余额
|
||||
* @param string $storeUserName
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
private function rechargeToBalance(string $storeUserName, array $data)
|
||||
{
|
||||
if (!isset($data['money']) || $data['money'] === '' || $data['money'] < 0) {
|
||||
$this->error = '请输入正确的金额';
|
||||
return false;
|
||||
}
|
||||
// 判断充值方式,计算最终金额
|
||||
if ($data['mode'] === 'inc') {
|
||||
$diffMoney = $data['money'];
|
||||
} elseif ($data['mode'] === 'dec') {
|
||||
$diffMoney = -$data['money'];
|
||||
} else {
|
||||
$diffMoney = helper::bcsub($data['money'], $this['balance']);
|
||||
}
|
||||
// 更新记录
|
||||
$this->transaction(function () use ($storeUserName, $data, $diffMoney) {
|
||||
// 更新账户余额
|
||||
static::setIncBalance((int)$this['merchant_id'], (float)$diffMoney);
|
||||
// 新增余额变动记录
|
||||
BalanceLogModel::add(SceneEnum::ADMIN, [
|
||||
'merchant_id' => $this['merchant_id'],
|
||||
'money' => (float)$diffMoney,
|
||||
'remark' => $data['remark'],
|
||||
], [$storeUserName]);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 代理商发券
|
||||
* @param array $data 表单数据
|
||||
* @return bool
|
||||
*/
|
||||
public function sendCoupon(array $data)
|
||||
{
|
||||
return $this->sendCouponAction($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 代理商发券 执行
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
private function sendCouponAction(array $data)
|
||||
{
|
||||
if (!isset($data['goods_id']) || $data['goods_id'] === '' || $data['goods_id'] < 0) {
|
||||
$this->error = '请选择发券商品';
|
||||
return false;
|
||||
}
|
||||
$goods = GoodsModel::detail($data['goods_id']);
|
||||
if(empty($goods['goods_id'] ?? '')){
|
||||
$this->error = '对应发券商品不存在';
|
||||
return false;
|
||||
}
|
||||
if($goods['oilCardType'] != 'coupon'){
|
||||
$this->error = '此商品不是优惠券商品';
|
||||
return false;
|
||||
}
|
||||
if (!isset($data['phone']) || $data['phone'] === '' || $data['phone'] < 0) {
|
||||
$this->error = '请输入用户手机号';
|
||||
return false;
|
||||
}
|
||||
$user = FrontUserModel::detail(['mobile' => $data['phone']]);
|
||||
if(empty($user['user_id'] ?? '')){
|
||||
$this->error = '未找到此手机号对应的用户';
|
||||
return false;
|
||||
}
|
||||
// 更新记录
|
||||
$this->transaction(function () use ($data, $goods, $user) {
|
||||
// 生成发券记录
|
||||
MerchantOrderModel::add([
|
||||
'order_no' => $this->orderNo(),
|
||||
'order_type' => 'coupon',
|
||||
'order_status' => 30,
|
||||
'total_price' => $goods['goods_price_max'],
|
||||
'order_price' => $goods['goods_price_max'],
|
||||
'goods_id' => $goods['goods_id'],
|
||||
'user_id' => $user['user_id'],
|
||||
'merchant_id' => $this['merchant_id'],
|
||||
'admin_remark' => $data['remark'] ?? '',
|
||||
]);
|
||||
// 发放优惠券
|
||||
$coupons = GoodsCouponModel::getCouponList($goods['goods_id'])->toArray();
|
||||
if($coupons && is_array($coupons)) {
|
||||
foreach ($coupons as $item) {
|
||||
$coupon = CouponModel::detail($item['coupon_id']);
|
||||
for ($i=0;$i<$item['send_num'];$i++){
|
||||
$userCouponModel = new UserCouponModel();
|
||||
$userCouponModel->add($user['user_id'], $coupon);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成订单号
|
||||
* @return string
|
||||
*/
|
||||
public function orderNo(): string
|
||||
{
|
||||
return OrderService::createOrderNo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use think\Request;
|
||||
use app\common\model\Notify as NotifyModel;
|
||||
|
||||
/**
|
||||
* 通知管理
|
||||
* Class Order
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Notify extends NotifyModel
|
||||
{
|
||||
/**
|
||||
* 通知列表
|
||||
* @return \think\Paginator
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
// 获取数据列表
|
||||
return $this->where('status', '=', 0)
|
||||
->order(['create_time' => 'asc'])
|
||||
->paginate(200);
|
||||
}
|
||||
/**
|
||||
* 新增通知记录
|
||||
* @param $order
|
||||
* @return false|int
|
||||
*/
|
||||
public function add($order)
|
||||
{
|
||||
return $this->save([
|
||||
'order_id' => $order['order_id'],
|
||||
'notify_url' => $order['notify_url'],
|
||||
'store_id' => 10001,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改通知状态
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
public function sureNotify($data)
|
||||
{
|
||||
return $this->save([
|
||||
'status' => $data['status'],
|
||||
'last_time' => time(),
|
||||
]) !== false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,835 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\enum\order\PayType as OrderPayTypeEnum;
|
||||
use app\common\service\goods\source\Factory as StockFactory;
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\store\User;
|
||||
use think\facade\Db;
|
||||
use think\facade\Request;
|
||||
use app\common\model\Goods as GoodsModel;
|
||||
use app\common\model\Order as OrderModel;
|
||||
use app\common\service\Order as OrderService;
|
||||
use app\common\service\Message as MessageService;
|
||||
use app\common\service\order\Refund as RefundService;
|
||||
use app\common\enum\order\OrderStatus as OrderStatusEnum;
|
||||
use app\common\enum\order\PayStatus as PayStatusEnum;
|
||||
use app\common\enum\order\DeliveryType as DeliveryTypeEnum;
|
||||
use app\common\enum\order\ReceiptStatus as ReceiptStatusEnum;
|
||||
use app\common\enum\order\DeliveryStatus as DeliveryStatusEnum;
|
||||
use app\common\library\helper;
|
||||
|
||||
/**
|
||||
* 订单管理
|
||||
* Class Order
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Order extends OrderModel
|
||||
{
|
||||
// 全部订单
|
||||
const LIST_TYPE_ALL = 'all';
|
||||
|
||||
// 待发货订单
|
||||
const LIST_TYPE_DELIVERY = 'delivery';
|
||||
|
||||
// 待收货订单
|
||||
const LIST_TYPE_RECEIPT = 'receipt';
|
||||
|
||||
// 待付款订单
|
||||
const LIST_TYPE_PAY = 'pay';
|
||||
|
||||
// 已完成订单
|
||||
const LIST_TYPE_COMPLETE = 'complete';
|
||||
|
||||
// 已取消
|
||||
const LIST_TYPE_CANCEL = 'cancel';
|
||||
|
||||
// 油券
|
||||
const LIST_TYPE_OIL = 'oil';
|
||||
|
||||
// 优惠券
|
||||
const LIST_TYPE_COUPON = 'coupon';
|
||||
|
||||
/**
|
||||
* 订单详情页数据
|
||||
* @param int $orderId
|
||||
* @return Order|array|false|null
|
||||
*/
|
||||
public function getDetail(int $orderId)
|
||||
{
|
||||
return static::detail($orderId, [
|
||||
'user',
|
||||
'address',
|
||||
'goods' => ['image'],
|
||||
'express',
|
||||
]) ?: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单列表
|
||||
* @param string $dataType 订单类型
|
||||
* @param array $param
|
||||
* @param array $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function getList(string $dataType = self::LIST_TYPE_ALL, array $param = [], $user = [])
|
||||
{
|
||||
if(!isset($param['merchantId']) && isset($user['is_super']) && $user['is_super'] == 0){
|
||||
$param['merchantId'] = $user['merchant_id'];
|
||||
}
|
||||
// 检索查询条件
|
||||
$filter = $this->getQueryFilter($param);
|
||||
// 设置订单类型条件
|
||||
$dataTypeFilter = $this->getFilterDataType($dataType);
|
||||
$keyword = $param['goods_no'] ?? '';
|
||||
// 先查询总金额
|
||||
$totalPayPrice = $this->alias('order')
|
||||
->leftJoin('user', 'user.user_id = order.user_id')
|
||||
->leftJoin('order_address address', 'address.order_id = order.order_id')
|
||||
->leftJoin('order_goods og', 'og.order_id = order.order_id')
|
||||
->where($dataTypeFilter)
|
||||
->where($filter)
|
||||
->where('order.is_delete', '=', 0)
|
||||
->when(!empty($keyword), function ($query) use ($keyword) {
|
||||
$query->whereLike('og.goods_no', "%{$keyword}%");
|
||||
})
|
||||
->sum('order.pay_price');
|
||||
|
||||
// 再查分页列表
|
||||
$list = $this->with(['goods.image', 'user.avatar', 'spreadOne', 'spreadTwo'])
|
||||
->alias('order')
|
||||
->field('order.*')
|
||||
->leftJoin('user', 'user.user_id = order.user_id')
|
||||
->leftJoin('order_address address', 'address.order_id = order.order_id')
|
||||
->leftJoin('order_goods og', 'og.order_id = order.order_id')
|
||||
->where($dataTypeFilter)
|
||||
->where($filter)
|
||||
->where('order.is_delete', '=', 0)
|
||||
->when(!empty($keyword), function ($query) use ($keyword) {
|
||||
$query->whereLike('og.goods_no', "%{$keyword}%");
|
||||
})
|
||||
->order(['order.create_time' => 'desc'])
|
||||
->paginate(10);
|
||||
// 获取数据列表
|
||||
return [
|
||||
'list' => $list,
|
||||
'total_money' => $totalPayPrice,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 订单列表(全部)
|
||||
* @param string $dataType 订单类型
|
||||
* @param array $query
|
||||
* @return mixed
|
||||
*/
|
||||
public function getListAll(string $dataType = self::LIST_TYPE_ALL, array $query = [])
|
||||
{
|
||||
// 检索查询条件
|
||||
$queryFilter = $this->getQueryFilter($query);
|
||||
// 设置订单类型条件
|
||||
$dataTypeFilter = $this->getFilterDataType($dataType);
|
||||
// 获取数据列表
|
||||
return $this->with(['goods.image', 'address', 'user.avatar', 'express'])
|
||||
->alias('order')
|
||||
->field('order.*')
|
||||
->join('user', 'user.user_id = order.user_id')
|
||||
->where($dataTypeFilter)
|
||||
->where($queryFilter)
|
||||
->where('order.is_delete', '=', 0)
|
||||
->order(['order.create_time' => 'desc'])
|
||||
->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置检索查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getQueryFilter(array $param): array
|
||||
{
|
||||
// 默认参数
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'searchType' => '', // 关键词类型 (10订单号 20会员昵称 30会员ID 40收货人姓名 50收货人电话)
|
||||
'searchValue' => '', // 关键词内容
|
||||
'goods_no' => '', // 商品编码
|
||||
'oilCardNo' => '', // 油卡编号
|
||||
'shareNo' => '', // 分油记录编号
|
||||
'orderSource' => -1, // 订单来源
|
||||
'payType' => -1, // 支付方式
|
||||
'spread_uid' => -1, // 一级代理商
|
||||
'pay_status' => -1, // 支付状态
|
||||
'oil_status' => -1, // 分油状态
|
||||
'use_status' => -1, // 使用状态
|
||||
'deliveryType' => -1, // 配送方式
|
||||
'betweenTime' => [], // 起止时间
|
||||
'userId' => 0, // 会员ID
|
||||
'merchantId' => 0, // 代理商
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 关键词
|
||||
if (!empty($params['searchValue'])) {
|
||||
$searchWhere = [
|
||||
10 => ['order.order_no', 'like', "%{$params['searchValue']}%"],
|
||||
20 => ['user.nick_name', 'like', "%{$params['searchValue']}%"],
|
||||
30 => ['order.user_id', '=', (int)$params['searchValue']],
|
||||
40 => ['address.name', 'like', "%{$params['searchValue']}%"],
|
||||
50 => ['address.phone', 'like', "%{$params['searchValue']}%"],
|
||||
];
|
||||
array_key_exists($params['searchType'], $searchWhere) && $filter[] = $searchWhere[$params['searchType']];
|
||||
}
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['order.create_time', '>=', strtotime(date('Y-m-d',$times['start_time']))];
|
||||
$filter[] = ['order.create_time', '<', strtotime(date('Y-m-d',$times['end_time'])) + 86400];
|
||||
}
|
||||
// 订单来源
|
||||
$params['orderSource'] > -1 && $filter[] = ['order_source', '=', (int)$params['orderSource']];
|
||||
// 支付方式
|
||||
$params['payType'] > -1 && $filter[] = ['pay_type', '=', (int)$params['payType']];
|
||||
// 一级代理商
|
||||
$params['spread_uid'] > -1 && $filter[] = ['spread_uid', '=', (int)$params['spread_uid']];
|
||||
// 支付状态
|
||||
$params['pay_status'] > -1 && $filter[] = ['pay_status', '=', (int)$params['pay_status']];
|
||||
// 分油状态
|
||||
if($params['oil_status'] > -1){
|
||||
$subQuery = Db::name('order_goods')
|
||||
->where('oil_status', (int)$params['oil_status'])
|
||||
->column('order_id'); // 获取所有符合条件的 order_id 数组
|
||||
$filter[] = ['order.order_id', 'in', $subQuery];
|
||||
}
|
||||
// 使用状态
|
||||
if($params['use_status'] > -1){
|
||||
$subQuery = Db::name('order_goods')
|
||||
->where('use_status', (int)$params['use_status'])
|
||||
->column('order_id'); // 获取所有符合条件的 order_id 数组
|
||||
$filter[] = ['order.order_id', 'in', $subQuery];
|
||||
}
|
||||
// 油卡编号
|
||||
if($params['oilCardNo']){
|
||||
$subQuery = Db::name('order_goods')
|
||||
->where('oilCardNo', 'like', "%{$params['oilCardNo']}%")
|
||||
->column('order_id'); // 获取所有符合条件的 order_id 数组
|
||||
$filter[] = ['order.order_id', 'in', $subQuery];
|
||||
}
|
||||
// 分油记录编号
|
||||
if($params['shareNo']){
|
||||
$subQuery = Db::name('order_goods')
|
||||
->where('shareNo', 'like', "%{$params['shareNo']}%")
|
||||
->column('order_id'); // 获取所有符合条件的 order_id 数组
|
||||
$filter[] = ['order.order_id', 'in', $subQuery];
|
||||
}
|
||||
// 配送方式
|
||||
$params['deliveryType'] > -1 && $filter[] = ['delivery_type', '=', (int)$params['deliveryType']];
|
||||
// 用户id
|
||||
$params['userId'] > 0 && $filter[] = ['order.user_id', '=', (int)$params['userId']];
|
||||
// 推广人ID
|
||||
if($params['merchantId'] > 0) {
|
||||
$filter[] = function ($query) use ($params) {
|
||||
$query->where('order.spread_uid', '=', $params['merchantId'])
|
||||
->whereOr('order.spread_two_uid', '=', $params['merchantId']);
|
||||
};
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置检索查询条件
|
||||
* @param $query
|
||||
*/
|
||||
private function setWhere($query): array
|
||||
{
|
||||
$filter = [];
|
||||
// $query['start_time'] = isset($query['start_time'])?$query['start_time']:strtotime(date("Y-m-d"));
|
||||
// $query['end_time'] = isset($query['end_time'])?$query['end_time']:strtotime(date("Y-m-d"));
|
||||
if (isset($query['start_time'])) {
|
||||
!empty($query['start_time']) && $filter[] = ['create_time', '>=', $query['start_time']];
|
||||
}
|
||||
if (isset($query['end_time'])) {
|
||||
!empty($query['end_time']) && $filter[] = ['create_time', '<', $query['end_time']+86400];
|
||||
}
|
||||
if (isset($query['order_status'])) {
|
||||
!empty($query['order_status']) && $query['order_status'] != -1 && $filter[] = ['order_status', '=', $query['order_status']];
|
||||
}
|
||||
if (isset($query['merchant_id']) && !empty($query['merchant_id']) && $query['merchant_id'] != -1) {
|
||||
$merchantId = $query['merchant_id'];
|
||||
$filter[] = function ($query) use ($merchantId) {
|
||||
$query->where('spread_uid', '=', $merchantId)
|
||||
->whereOr('spread_two_uid', '=', $merchantId);
|
||||
};
|
||||
}
|
||||
if (isset($query['oilCardType'])) {
|
||||
!empty($query['oilCardType']) && $query['oilCardType'] != -1 && $filter[] = ['oilCardType', '=', $query['oilCardType']];
|
||||
}
|
||||
if (isset($query['saleOrderNo'])) {
|
||||
!empty($query['saleOrderNo']) && $filter[] = ['saleOrderNo', 'like', '%' . trim($query['saleOrderNo']) . '%'];
|
||||
}
|
||||
if (isset($query['goodsNo'])) {
|
||||
!empty($query['goodsNo']) && $filter[] = ['goodsNo', 'like', '%' . trim($query['goodsNo']) . '%'];
|
||||
}
|
||||
if (isset($query['userNo'])) {
|
||||
!empty($query['userNo']) && $filter[] = ['userNo', 'like', '%' . trim($query['userNo']) . '%'];
|
||||
}
|
||||
if (isset($query['mobile'])) {
|
||||
!empty($query['mobile']) && $filter[] = ['mobile', 'like', '%' . trim($query['mobile']) . '%'];
|
||||
}
|
||||
if (isset($query['oilCardNo'])) {
|
||||
!empty($query['oilCardNo']) && $filter[] = ['oilCardNo', 'like', '%' . trim($query['oilCardNo']) . '%'];
|
||||
}
|
||||
if (isset($query['shareNo'])) {
|
||||
!empty($query['shareNo']) && $filter[] = ['shareNo', 'like', '%' . trim($query['shareNo']) . '%'];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置订单类型条件
|
||||
* @param string $dataType
|
||||
* @return array
|
||||
*/
|
||||
private function getFilterDataType(string $dataType = self::LIST_TYPE_ALL): array
|
||||
{
|
||||
// 数据类型
|
||||
$filter = [];
|
||||
switch ($dataType) {
|
||||
case self::LIST_TYPE_ALL:
|
||||
$filter = [];
|
||||
break;
|
||||
case self::LIST_TYPE_DELIVERY:
|
||||
$filter = [
|
||||
['pay_status', '=', PayStatusEnum::SUCCESS],
|
||||
['delivery_status', '=', DeliveryStatusEnum::NOT_DELIVERED],
|
||||
['order_status', 'in', [OrderStatusEnum::NORMAL]]
|
||||
];
|
||||
break;
|
||||
case self::LIST_TYPE_RECEIPT:
|
||||
$filter = [
|
||||
['pay_status', '=', PayStatusEnum::SUCCESS],
|
||||
['delivery_status', '=', DeliveryStatusEnum::DELIVERED],
|
||||
['receipt_status', '=', ReceiptStatusEnum::NOT_RECEIVED]
|
||||
];
|
||||
break;
|
||||
case self::LIST_TYPE_PAY:
|
||||
$filter[] = ['pay_status', '=', PayStatusEnum::PENDING];
|
||||
$filter[] = ['order_status', '=', OrderStatusEnum::NORMAL];
|
||||
break;
|
||||
case self::LIST_TYPE_COMPLETE:
|
||||
$filter[] = ['order_status', '=', OrderStatusEnum::COMPLETED];
|
||||
break;
|
||||
case self::LIST_TYPE_CANCEL:
|
||||
$filter[] = ['order_status', '=', OrderStatusEnum::CANCELLED];
|
||||
break;
|
||||
case self::LIST_TYPE_OIL:
|
||||
$filter[] = ['order_type', '=', 'zsy_ticket'];
|
||||
break;
|
||||
case self::LIST_TYPE_COUPON:
|
||||
$filter[] = ['order_type', '=', 'coupon'];
|
||||
break;
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认发货(单独订单)
|
||||
* @param $data
|
||||
* @return bool|false
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delivery($data): bool
|
||||
{
|
||||
// 转义为订单列表
|
||||
$orderList = [$this];
|
||||
// 验证订单是否满足发货条件
|
||||
if (!$this->verifyDelivery($orderList)) {
|
||||
return false;
|
||||
}
|
||||
// 整理更新的数据
|
||||
$updateList = [[
|
||||
'order_id' => $this['order_id'],
|
||||
'express_id' => $data['express_id'],
|
||||
'express_no' => $data['express_no']
|
||||
]];
|
||||
// 更新订单发货状态
|
||||
$this->updateToDelivery($updateList);
|
||||
// 获取已发货的订单
|
||||
$completed = self::detail($this['order_id'], ['user', 'address', 'goods', 'express']);
|
||||
// 发送消息通知
|
||||
$this->sendDeliveryMessage([$completed]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认发货后发送消息通知
|
||||
* @param $orderList
|
||||
* @return bool
|
||||
*/
|
||||
private function sendDeliveryMessage($orderList): bool
|
||||
{
|
||||
// 发送消息通知
|
||||
foreach ($orderList as $item) {
|
||||
MessageService::send('order.delivery', ['order' => $item], self::$storeId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单发货状态(批量)
|
||||
* @param $orderList
|
||||
* @return bool
|
||||
*/
|
||||
private function updateToDelivery($orderList): bool
|
||||
{
|
||||
// 整理更新的数据
|
||||
$data = [];
|
||||
foreach ($orderList as $item) {
|
||||
$data[] = [
|
||||
'data' => [
|
||||
'express_no' => $item['express_no'],
|
||||
'express_id' => $item['express_id'],
|
||||
'delivery_status' => 20,
|
||||
'delivery_time' => time(),
|
||||
],
|
||||
'where' => ['order_id' => $item['order_id']]
|
||||
];
|
||||
}
|
||||
// 批量更新
|
||||
$this->updateAll($data);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证订单是否满足发货条件
|
||||
* @param $orderList
|
||||
* @return bool
|
||||
*/
|
||||
private function verifyDelivery($orderList): bool
|
||||
{
|
||||
foreach ($orderList as $order) {
|
||||
if (
|
||||
$order['pay_status'] != PayStatusEnum::SUCCESS
|
||||
|| $order['delivery_type'] != DeliveryTypeEnum::EXPRESS
|
||||
|| $order['delivery_status'] != DeliveryStatusEnum::NOT_DELIVERED
|
||||
) {
|
||||
$this->error = "订单号[{$order['order_no']}] 不满足发货条件!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改订单价格
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function updatePrice(array $data): bool
|
||||
{
|
||||
if ($this['pay_status'] != PayStatusEnum::PENDING) {
|
||||
$this->error = '该订单不合法';
|
||||
return false;
|
||||
}
|
||||
// 实际付款金额
|
||||
$payPrice = helper::bcadd($data['order_price'], $data['express_price']);
|
||||
if ($payPrice <= 0) {
|
||||
$this->error = '订单实付款价格不能为0.00元';
|
||||
return false;
|
||||
}
|
||||
// 改价的金额差价
|
||||
$updatePrice = helper::bcsub($data['order_price'], $this['order_price']);
|
||||
// 更新订单记录
|
||||
return $this->save([
|
||||
'order_no' => $this->orderNo(), // 修改订单号, 否则微信支付提示重复
|
||||
'pay_price' => $payPrice,
|
||||
'update_price' => $updatePrice,
|
||||
'express_price' => $data['express_price']
|
||||
]) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤销分油,回收
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function cancelShare(array $data): bool
|
||||
{
|
||||
// 更新订单记录
|
||||
return $this->save([
|
||||
'order_status' => OrderStatusEnum::RECOVER
|
||||
]) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核:用户取消订单
|
||||
* @param array $data
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function confirmCancel(array $data)
|
||||
{
|
||||
// 判断订单是否有效
|
||||
if (
|
||||
$this['pay_status'] != PayStatusEnum::SUCCESS
|
||||
) {
|
||||
$this->error = '该订单不合法';
|
||||
return false;
|
||||
}
|
||||
// 订单取消事件
|
||||
return $this->transaction(function () use ($data) {
|
||||
if ($data['status']) {
|
||||
// 执行退款操作
|
||||
(new RefundService)->execute($this);
|
||||
// 订单取消事件
|
||||
OrderService::cancelEvent($this);
|
||||
}
|
||||
// 更新订单状态
|
||||
return $this->save(['order_status' => $data['status'] ? OrderStatusEnum::CANCELLED : OrderStatusEnum::NORMAL]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 将订单记录设置为已删除
|
||||
* @return bool
|
||||
*/
|
||||
public function setDelete(): bool
|
||||
{
|
||||
return $this->save(['is_delete' => 1]) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已付款订单总数 (可指定某天)
|
||||
* @param null $startDate
|
||||
* @param null $endDate
|
||||
* @param array $user
|
||||
* @return int
|
||||
*/
|
||||
public function getPayOrderTotal($startDate = null, $endDate = null, $user = []): int
|
||||
{
|
||||
$filter = [];
|
||||
$filter[] = ['pay_status', '=', 20];
|
||||
if (!is_null($startDate) && !is_null($endDate)) {
|
||||
$filter[] = ['create_time', '>=', strtotime($startDate)];
|
||||
$filter[] = ['create_time', '<', strtotime($endDate) + 86400];
|
||||
}
|
||||
if(!empty($user)) {
|
||||
if(isset($user['is_super']) && $user['is_super'] == 0){
|
||||
$filter[] = function ($query) use ($user) {
|
||||
$query->where('spread_uid', '=', $user['merchant_id'])
|
||||
->whereOr('spread_two_uid', '=', $user['merchant_id']);
|
||||
};
|
||||
}
|
||||
}
|
||||
return $this->getOrderTotal($filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取未发货订单数量
|
||||
* @return int
|
||||
*/
|
||||
public function getNotDeliveredOrderTotal(): int
|
||||
{
|
||||
$filter = [
|
||||
['pay_status', '=', PayStatusEnum::SUCCESS],
|
||||
['delivery_status', '=', DeliveryStatusEnum::NOT_DELIVERED],
|
||||
['order_status', 'in', [OrderStatusEnum::NORMAL]]
|
||||
];
|
||||
return $this->getOrderTotal($filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取未付款订单数量
|
||||
* @return int
|
||||
*/
|
||||
public function getNotPayOrderTotal(): int
|
||||
{
|
||||
$filter = [
|
||||
['pay_status', '=', PayStatusEnum::PENDING],
|
||||
['order_status', '=', OrderStatusEnum::NORMAL]
|
||||
];
|
||||
return $this->getOrderTotal($filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单总数
|
||||
* @param array $filter
|
||||
* @return int
|
||||
*/
|
||||
public function getOrderTotal(array $filter = [], $query = []): int
|
||||
{
|
||||
// 获取订单总数量
|
||||
// 检索查询
|
||||
$search = $this->setWhere($query);
|
||||
return $this->where(array_merge($filter,$search))
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取总金额
|
||||
* @param array $filter
|
||||
* @param array $query
|
||||
* @return float|int
|
||||
*/
|
||||
public function getOrderTotalMoney($filter=[], $query = [])
|
||||
{
|
||||
// 检索查询
|
||||
$search = $this->setWhere($query);
|
||||
return $this->where(array_merge($filter,$search))
|
||||
->sum('pay_price');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取某天的总销售额
|
||||
* @param null $startDate
|
||||
* @param null $endDate
|
||||
* @param array $user
|
||||
* @return float
|
||||
*/
|
||||
public function getOrderTotalPrice($startDate = null, $endDate = null,$user=[]): float
|
||||
{
|
||||
// 查询对象
|
||||
$query = $this->getNewQuery();
|
||||
$filter = [];
|
||||
// 设置查询条件
|
||||
if (!is_null($startDate) && !is_null($endDate)) {
|
||||
$filter[] = ['create_time', '>=', strtotime($startDate)];
|
||||
$filter[] = ['create_time', '<', strtotime($endDate) + 86400];
|
||||
}
|
||||
if(!empty($user)) {
|
||||
if(isset($user['is_super']) && $user['is_super'] == 0){
|
||||
$filter[] = function ($query) use ($user) {
|
||||
$query->where('spread_uid', '=', $user['merchant_id'])
|
||||
->whereOr('spread_two_uid', '=', $user['merchant_id']);
|
||||
};
|
||||
}
|
||||
}
|
||||
// 总销售额
|
||||
return $query->where('pay_status', '=', 20)
|
||||
->where($filter)
|
||||
->sum('pay_price');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某天的下单用户数
|
||||
* @param string $day
|
||||
* @return float|int
|
||||
*/
|
||||
public function getPayOrderUserTotal(string $day)
|
||||
{
|
||||
$startTime = strtotime($day);
|
||||
return $this->field('user_id')
|
||||
->where('pay_time', '>=', $startTime)
|
||||
->where('pay_time', '<', $startTime + 86400)
|
||||
->where('pay_status', '=', PayStatusEnum::SUCCESS)
|
||||
->where('is_delete', '=', '0')
|
||||
->group('user_id')
|
||||
->count();
|
||||
}
|
||||
/**
|
||||
* 修改订单状态
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
public function updateStatus($data)
|
||||
{
|
||||
if ($this['order_status'] == $data['status']) {
|
||||
$this->error = '状态未做改变';
|
||||
return false;
|
||||
}
|
||||
$field = [
|
||||
'order_status' => $data['status'],
|
||||
'buyer_remark' => $data['buyer_remark']
|
||||
];
|
||||
if($data['status'] == 20){
|
||||
$field['pay_status'] = 20;
|
||||
$field['pay_time'] = time();
|
||||
}
|
||||
return $this->save($field) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单超时修改
|
||||
* @param $where
|
||||
* @return bool
|
||||
* @throws \app\common\exception\BaseException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function overtimeUpdate($where)
|
||||
{
|
||||
if (empty($where) || !is_array($where)) {
|
||||
$this->error = '条件不合法';
|
||||
return false;
|
||||
}
|
||||
return $this->where($where)->update(['order_status' => 30]) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新订单
|
||||
* @param array $order 订单信息
|
||||
* @return bool
|
||||
*/
|
||||
public function addOil(array $order): bool
|
||||
{
|
||||
// 创建新的订单
|
||||
$status = $this->transaction(function () use ($order) {
|
||||
// 创建订单事件
|
||||
return $this->createOrderEvent($order);
|
||||
});
|
||||
return $status;
|
||||
}
|
||||
/**
|
||||
* 创建订单事件
|
||||
* @param $order
|
||||
* @return bool
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function createOrderEvent($order): bool
|
||||
{
|
||||
// 新增订单记录
|
||||
$status = $this->add($order);
|
||||
// 保存订单商品信息
|
||||
$this->saveOrderGoods($order);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品库存 (针对下单减库存的商品)
|
||||
* @param $orderSource
|
||||
* @param $goodsList
|
||||
* @return void
|
||||
*/
|
||||
private function updateGoodsStockNum($orderSource, $goodsList): void
|
||||
{
|
||||
StockFactory::getFactory($orderSource)->updateGoodsStock($goodsList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增订单记录
|
||||
* @param $order
|
||||
* @return bool|false
|
||||
*/
|
||||
private function add($order): bool
|
||||
{
|
||||
// 订单数据
|
||||
$data = [
|
||||
'user_id' => $order['user_id'],
|
||||
'order_no' => $order['saleOrderNo'],
|
||||
'total_price' => $order['amount'],
|
||||
'order_price' => $order['amount'],
|
||||
'coupon_id' => '',
|
||||
'coupon_money' => '',
|
||||
'points_money' => 0.00,
|
||||
'points_num' => 0,
|
||||
'pay_price' => $order['amount'],
|
||||
'delivery_type' => 10,
|
||||
'pay_type' => $order['payType'],
|
||||
'buyer_remark' => $order['buyer_remark'],
|
||||
'order_source' => 10,
|
||||
'order_source_id' => '',
|
||||
'points_bonus' => '',
|
||||
'order_status' => OrderStatusEnum::NORMAL,
|
||||
'platform' => '后台',
|
||||
'store_id' => $order['store_id'],
|
||||
'pay_status' => PayStatusEnum::SUCCESS,
|
||||
'pay_time' => time()
|
||||
];
|
||||
// 保存订单记录
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存订单商品信息
|
||||
* @param $order
|
||||
* @return void
|
||||
*/
|
||||
private function saveOrderGoods($order): void
|
||||
{
|
||||
// 查找一个未被调用的用户
|
||||
$goods = Db::name('goods')
|
||||
->alias('goods')
|
||||
->field('goods.*,yoshop_goods_image.image_id')
|
||||
->where('goods.goods_id', '=', $order['goods_id'])
|
||||
->join('yoshop_goods_image', 'goods.goods_id = yoshop_goods_image.goods_id')
|
||||
->limit(1)
|
||||
->find();
|
||||
// 订单商品列表
|
||||
$list[] = [
|
||||
'province' => $order['province'],
|
||||
'user_id' => $order['user_id'],
|
||||
'account_id' => $order['account_id'],
|
||||
'userNo' => $order['userNo'],
|
||||
'mobile' => $order['mobile'],
|
||||
'store_id' => $order['store_id'],
|
||||
'goods_id' => $goods['goods_id'],
|
||||
'goods_name' => $goods['goods_name'],
|
||||
'oilCardType' => $order['oilCardType'],
|
||||
'company_id' => $order['company_id'],
|
||||
'oilCardNo' => $order['oilCardNo'],
|
||||
'shareNo' => $order['shareNo'],
|
||||
'goods_no' => $order['goodsNo'],
|
||||
'image_id' => $goods['image_id'],
|
||||
'deduct_stock_type' => 10,
|
||||
'spec_type' => 10,
|
||||
'goods_sku_id' => '',
|
||||
'goods_props' => '',
|
||||
'content' => '',
|
||||
'goods_sku_no' => '',
|
||||
'goods_price' => $order['amount'],
|
||||
'line_price' => 0,
|
||||
'goods_weight' => 0,
|
||||
'is_user_grade' => 0,
|
||||
'grade_ratio' => 0,
|
||||
'grade_goods_price' => 0,
|
||||
'grade_total_money' => 0,
|
||||
'coupon_money' => 0,
|
||||
'points_money' => 0.00,
|
||||
'points_num' => 0,
|
||||
'points_bonus' => 0,
|
||||
'total_num' => 1,
|
||||
'total_price' => $order['amount'],
|
||||
'total_pay_price' => $order['amount']
|
||||
];
|
||||
$this->goods()->saveAll($list) !== false;
|
||||
// 更新商品库存 (针对下单减库存的商品)
|
||||
$this->updateGoodsStockNum(10, $list);
|
||||
}
|
||||
/**
|
||||
* 修改订单状态
|
||||
* @param $where
|
||||
* @param $field
|
||||
* @return false|int
|
||||
*/
|
||||
public static function orderUpdate($where, $field)
|
||||
{
|
||||
return (new static())->where($where)->update($field) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一条记录
|
||||
* @param array $filter
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getSingle(array $filter): ?array
|
||||
{
|
||||
$model = new static;
|
||||
$data = $model->where($filter)->order(['order_id' => 'asc'])->find();
|
||||
return $data ? $data->toArray() : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\OrderAddress as OrderAddressModel;
|
||||
|
||||
/**
|
||||
* 订单收货地址模型
|
||||
* Class OrderAddress
|
||||
* @package app\store\model
|
||||
*/
|
||||
class OrderAddress extends OrderAddressModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\enum\order\OrderStatus as OrderStatusEnum;
|
||||
use app\common\model\OrderGoods as OrderGoodsModel;
|
||||
|
||||
/**
|
||||
* 订单商品模型
|
||||
* Class OrderGoods
|
||||
* @package app\store\model
|
||||
*/
|
||||
class OrderGoods extends OrderGoodsModel
|
||||
{
|
||||
/**
|
||||
* 修改订单状态
|
||||
* @param $where
|
||||
* @param $field
|
||||
* @return false|int
|
||||
*/
|
||||
public static function orderUpdate($where, $field)
|
||||
{
|
||||
return (new static())->where($where)->update($field) !== false;
|
||||
}
|
||||
/**
|
||||
* 撤销分油,回收
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function cancelShare(array $data): bool
|
||||
{
|
||||
// 更新订单记录
|
||||
return $this->save([
|
||||
'order_status' => 20
|
||||
]) !== false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\store\model\User as UserModel;
|
||||
use app\common\model\OrderRefund as OrderRefundModel;
|
||||
use app\common\enum\order\refund\RefundType as RefundTypeEnum;
|
||||
use app\common\enum\order\refund\AuditStatus as AuditStatusEnum;
|
||||
use app\common\enum\order\refund\RefundStatus as RefundStatusEnum;
|
||||
use app\common\service\Message as MessageService;
|
||||
use app\common\service\order\Refund as RefundService;
|
||||
|
||||
/**
|
||||
* 售后单模型
|
||||
* Class OrderRefund
|
||||
* @package app\api\model
|
||||
*/
|
||||
class OrderRefund extends OrderRefundModel
|
||||
{
|
||||
/**
|
||||
* 获取售后单列表
|
||||
* @param array $param
|
||||
* @return mixed
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 检索查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取列表数据
|
||||
return $this->alias('refund')
|
||||
->field('refund.*, order.order_no')
|
||||
->with(['orderGoods.image', 'orderData', 'user.avatar'])
|
||||
->join('order', 'order.order_id = refund.order_id')
|
||||
->join('user', 'user.user_id = order.user_id')
|
||||
->where($filter)
|
||||
->order(['refund.create_time' => 'desc', 'refund.' . $this->getPk()])
|
||||
->paginate(10);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取售后单详情
|
||||
* @param int $orderRefundId
|
||||
* @return OrderRefund|false|null
|
||||
*/
|
||||
public function getDetail(int $orderRefundId)
|
||||
{
|
||||
return static::detail($orderRefundId, [
|
||||
'orderData', 'images.file', 'orderGoods.image', 'express', 'address', 'user'
|
||||
]) ?: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检索查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param = []): array
|
||||
{
|
||||
// 默认查询条件
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'searchType' => '', // 关键词类型 (10订单号 20会员昵称 30会员ID)
|
||||
'searchValue' => '', // 关键词内容
|
||||
'refundType' => -1, // 售后类型
|
||||
'refundStatus' => -1, // 售后单状态
|
||||
'betweenTime' => [], // 申请时间
|
||||
]);
|
||||
// 检查查询条件
|
||||
$filter = [];
|
||||
// 关键词
|
||||
if (!empty($params['searchValue'])) {
|
||||
$searchWhere = [
|
||||
10 => ['order.order_no', 'like', "%{$params['searchValue']}%"],
|
||||
20 => ['user.nick_name', 'like', "%{$params['searchValue']}%"],
|
||||
30 => ['order.user_id', '=', (int)$params['searchValue']]
|
||||
];
|
||||
array_key_exists($params['searchType'], $searchWhere) && $filter[] = $searchWhere[$params['searchType']];
|
||||
}
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['refund.create_time', '>=', $times['start_time']];
|
||||
$filter[] = ['refund.create_time', '<', $times['end_time'] + 86400];
|
||||
}
|
||||
// 售后类型
|
||||
$params['refundType'] > -1 && $filter[] = ['refund.type', '=', (int)$params['refundType']];
|
||||
// 处理状态
|
||||
$params['refundStatus'] > -1 && $filter[] = ['refund.status', '=', (int)$params['refundStatus']];
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商家审核
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function audit(array $data): bool
|
||||
{
|
||||
if ($data['audit_status'] == AuditStatusEnum::REJECTED && empty($data['refuse_desc'])) {
|
||||
$this->error = '请输入拒绝原因';
|
||||
return false;
|
||||
}
|
||||
if ($data['audit_status'] == AuditStatusEnum::REVIEWED && empty($data['address_id'])) {
|
||||
$this->error = '请选择退货地址';
|
||||
return false;
|
||||
}
|
||||
$this->transaction(function () use ($data) {
|
||||
// 拒绝申请, 标记售后单状态为已拒绝
|
||||
$data['audit_status'] == AuditStatusEnum::REJECTED && $data['status'] = RefundStatusEnum::REJECTED;
|
||||
// 同意换货申请, 标记售后单状态为已完成
|
||||
$data['audit_status'] == AuditStatusEnum::REVIEWED && $this['type'] == RefundTypeEnum::EXCHANGE && $data['status'] = RefundStatusEnum::COMPLETED;
|
||||
// 更新退款单状态
|
||||
$this->save($data);
|
||||
// 同意售后申请, 记录退货地址
|
||||
if ($data['audit_status'] == AuditStatusEnum::REVIEWED) {
|
||||
(new OrderRefundAddress)->add((int)$this['order_refund_id'], (int)$data['address_id']);
|
||||
}
|
||||
// 订单详情
|
||||
$order = Order::detail($this['order_id']);
|
||||
// 发送消息通知
|
||||
MessageService::send('order.refund', [
|
||||
'refund' => $this, // 退款单信息
|
||||
'order_no' => $order['order_no'] // 订单信息
|
||||
], $this['store_id']);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认收货并退款
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function receipt(array $data): bool
|
||||
{
|
||||
// 订单详情
|
||||
$order = Order::detail($this['order_id']);
|
||||
if ($data['refund_money'] > min($order['pay_price'], $this['orderGoods']['total_pay_price'])) {
|
||||
$this->error = '退款金额不能大于商品实付款金额';
|
||||
return false;
|
||||
}
|
||||
// 事务处理
|
||||
$this->transaction(function () use ($order, $data) {
|
||||
// 更新售后单状态
|
||||
$this->save([
|
||||
'refund_money' => $data['refund_money'],
|
||||
'is_receipt' => 1,
|
||||
'status' => RefundStatusEnum::COMPLETED
|
||||
]);
|
||||
// 消减用户的实际消费金额
|
||||
// 条件:判断订单是否已结算
|
||||
if ($order['is_settled'] == true) {
|
||||
(new UserModel)->setDecUserExpend($order['user_id'], $data['refund_money']);
|
||||
}
|
||||
// 执行原路退款
|
||||
(new RefundService)->execute($order, (string)$data['refund_money']);
|
||||
// 发送消息通知
|
||||
MessageService::send('order.refund', [
|
||||
'refund' => $this, // 退款单信息
|
||||
'order_no' => $order['order_no'], // 订单信息
|
||||
], $this['store_id']);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取待处理售后单数量
|
||||
* @return int
|
||||
*/
|
||||
public function getRefundTotal()
|
||||
{
|
||||
return $this->where('status', '=', RefundStatusEnum::NORMAL)->count();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\store\model\store\Address as AddressModel;
|
||||
use app\common\model\OrderRefundAddress as OrderRefundAddressModel;
|
||||
|
||||
/**
|
||||
* 售后单退货地址模型
|
||||
* Class OrderRefundAddress
|
||||
* @package app\store\model
|
||||
*/
|
||||
class OrderRefundAddress extends OrderRefundAddressModel
|
||||
{
|
||||
/**
|
||||
* 新增售后单退货地址记录
|
||||
* @param int $orderRefundId
|
||||
* @param int $storeAddressId
|
||||
* @return bool
|
||||
*/
|
||||
public function add(int $orderRefundId, int $storeAddressId)
|
||||
{
|
||||
// 获取地址详情
|
||||
$address = AddressModel::detail($storeAddressId);
|
||||
// 新增退货地址记录
|
||||
return $this->save([
|
||||
'order_refund_id' => $orderRefundId,
|
||||
'name' => $address['name'],
|
||||
'phone' => $address['phone'],
|
||||
'province_id' => $address['province_id'],
|
||||
'city_id' => $address['city_id'],
|
||||
'region_id' => $address['region_id'],
|
||||
'detail' => $address['detail'],
|
||||
'store_id' => self::$storeId
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\OrderRefundImage as OrderRefundImageModel;
|
||||
|
||||
class OrderRefundImage extends OrderRefundImageModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Page as PageModel;
|
||||
use app\common\enum\page\PageType as PageTypeEnum;
|
||||
|
||||
/**
|
||||
* 店铺页面模型
|
||||
* Class Page
|
||||
* @package app\common\model
|
||||
*/
|
||||
class Page extends PageModel
|
||||
{
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 检索查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取列表信息
|
||||
return $this->withoutField('page_data')
|
||||
->where($filter)
|
||||
->where(['is_delete' => 0])
|
||||
->order(['create_time' => 'desc', $this->getPk()])
|
||||
->paginate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检索查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param = [])
|
||||
{
|
||||
$filter = [];
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'name' => '', // 页面名称
|
||||
]);
|
||||
!empty($params['name']) && $filter[] = ['page_name', 'like', "%{$params['name']}%"];
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增页面
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
return $this->save([
|
||||
'page_type' => 20,
|
||||
'page_name' => $data['page']['params']['name'],
|
||||
'page_data' => $data,
|
||||
'store_id' => self::$storeId
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新页面
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
$pageData = $this->getFilterPageData($data);
|
||||
return $this->save([
|
||||
'page_name' => $pageData['page']['params']['name'],
|
||||
'page_data' => $pageData
|
||||
]) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤页面数据
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
private function getFilterPageData(array $data)
|
||||
{
|
||||
foreach ($data['items'] as &$item) {
|
||||
if ($item['type'] === 'richText') {
|
||||
$item['params']['content'] = htmlspecialchars_decode($item['params']['content']);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* @return int
|
||||
*/
|
||||
public function setDelete()
|
||||
{
|
||||
if ($this['page_type'] == PageTypeEnum::HOME) {
|
||||
$this->error = '默认首页不可以删除';
|
||||
return false;
|
||||
}
|
||||
// 删除记录
|
||||
return $this->save(['is_delete' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设为默认首页
|
||||
* @return int
|
||||
*/
|
||||
public function setHome()
|
||||
{
|
||||
// 取消原默认首页
|
||||
$this->where(['page_type' => PageTypeEnum::HOME])->update(['page_type' => PageTypeEnum::CUSTOM]);
|
||||
return $this->save(['page_type' => PageTypeEnum::HOME]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\store\model\store\UserRole;
|
||||
use think\Session;
|
||||
use app\common\model\Partners as PartnersModel;
|
||||
use app\store\model\Order as OrderModel;
|
||||
use app\store\model\store\User as UserModel;
|
||||
use app\store\model\PartnersGoods as PartnersGoodsModel;
|
||||
|
||||
use app\store\model\partners\BalanceLog as BalanceLogModel;
|
||||
use app\store\model\partners\StockLog as StockLogModel;
|
||||
use app\store\service\store\User as StoreUserService;
|
||||
use app\common\enum\partners\balanceLog\Scene as SceneEnum;
|
||||
use app\common\library\helper;
|
||||
|
||||
/**
|
||||
* 商户模型
|
||||
* Class StoreUser
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Partners extends PartnersModel
|
||||
{
|
||||
// 充值类型枚举: 余额
|
||||
const RECHARGE_TYPE_BALANCE = 'balance';
|
||||
/**
|
||||
* 获取商户列表
|
||||
* @param array $data
|
||||
* @return \think\Paginator
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getList($data = [])
|
||||
{
|
||||
return $this->order(['create_time' => 'desc'])
|
||||
->where($data)
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param $data
|
||||
* @param array $user
|
||||
* @return bool|false|int
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function add($data, $user = [])
|
||||
{
|
||||
if (empty($data['name'])) {
|
||||
$this->error = '请填写商户名称';
|
||||
return false;
|
||||
}
|
||||
// 检查商品数据
|
||||
$goodsList = PartnersGoodsModel::checkGoodsData($data['goodsList']);
|
||||
$this->startTrans();
|
||||
try {
|
||||
$data['orgNo'] = $this->createNo();
|
||||
$data['appKey'] = $this->suiji(30);
|
||||
$data['store_user_id'] = $user['store_user_id'];
|
||||
$data['store_id'] = self::$storeId;
|
||||
$data = array_merge($data, $this->secretKey());
|
||||
$this->save($data);
|
||||
//创建商户登录账号
|
||||
$userModel = new UserModel();
|
||||
$newData['user_name'] = $data['name'];
|
||||
$newData['password'] = encryption_hash('123456');
|
||||
$newData['real_name'] = $data['name'];
|
||||
$newData['status'] = 1;
|
||||
$newData['is_super'] = 0;
|
||||
$newData['store_id'] = self::$storeId;
|
||||
//账号层级
|
||||
$newData['level'] = 1;
|
||||
$newData['partners_id'] = json_encode([$this->partners_id],320);
|
||||
$userModel->save($newData);
|
||||
// 新增角色关系记录
|
||||
UserRole::increased((int)$userModel['store_user_id'], [10014]);
|
||||
// 新增商品关系记录
|
||||
PartnersGoodsModel::increased((int)$this['partners_id'], $goodsList);
|
||||
// 新增合作商商品库存变动记录
|
||||
StockLogModel::increased((int)$this['partners_id'], $goodsList);
|
||||
$this->commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
$this->rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/*返回随机数*/
|
||||
public function suiji($digit=12){
|
||||
$a = "abcdefghijklmnopqrstuvwxyz";
|
||||
$x = strlen($a)-1;
|
||||
$html = "";
|
||||
for($i=1;$i<=$digit;$i++) {
|
||||
$rand = rand(1,$x);
|
||||
$html .= substr($a,$rand,1);
|
||||
if($i == 1){//某些语言变量首字母不能是数字
|
||||
$a .= "0123456789";
|
||||
$x = strlen($a)-1;
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function secretKey(){
|
||||
// 生成 RSA 密钥对
|
||||
$config = [
|
||||
'private_key_bits' => 2048,
|
||||
'private_key_type' => OPENSSL_KEYTYPE_RSA,
|
||||
];
|
||||
$keyPair = openssl_pkey_new($config);
|
||||
|
||||
// 提取私钥(PEM格式)
|
||||
openssl_pkey_export($keyPair, $privateKey);
|
||||
|
||||
// 提取公钥(PEM格式)
|
||||
$keyDetails = openssl_pkey_get_details($keyPair);
|
||||
$publicKey = $keyDetails['key'];
|
||||
|
||||
// 直接返回原始 PEM 字符串,不进行 base64 编码
|
||||
return [
|
||||
'privateKey' => $privateKey,
|
||||
'publicKey' => $publicKey,
|
||||
];
|
||||
}
|
||||
|
||||
/** 生成编号
|
||||
* @param $prefix
|
||||
* @return string
|
||||
*/
|
||||
public static function createNo($prefix = 'S'): string
|
||||
{
|
||||
return $prefix . substr(implode('', array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function edit($data)
|
||||
{
|
||||
if (empty($data['name'])) {
|
||||
$this->error = '请填写商户名称';
|
||||
return false;
|
||||
}
|
||||
// 检查商品数据
|
||||
$goodsList = PartnersGoodsModel::checkGoodsData($data['goodsList']);
|
||||
$this->startTrans();
|
||||
try {
|
||||
// 更新管理员记录
|
||||
$this->save($data);
|
||||
// 更新商品关系记录
|
||||
PartnersGoodsModel::updates((int)$this['partners_id'], $goodsList);
|
||||
// 新增合作商商品库存变动记录
|
||||
StockLogModel::increased((int)$this['partners_id'], $goodsList);
|
||||
$this->commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
$this->rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 软删除
|
||||
* @return false|int
|
||||
*/
|
||||
public function setDelete()
|
||||
{
|
||||
return $this->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户数据统计
|
||||
* @param $user
|
||||
* @param $get
|
||||
* @return \think\Paginator
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getPartnersStatistics($user,$get = [])
|
||||
{
|
||||
$filter = [];
|
||||
if($user['is_super'] == 0){
|
||||
$partners_idArr = $user['partners_id']?json_decode($user['partners_id'],true):[];
|
||||
$filter[] = ['a.partners_id', 'in', $partners_idArr];
|
||||
}
|
||||
if(isset($get['name'])){
|
||||
$filter[] = ['a.name', 'like', '%'.$get['name'].'%'];
|
||||
}
|
||||
$times = [];
|
||||
if(isset($get['betweenTime'])) {
|
||||
$times = between_time($get['betweenTime']);
|
||||
}
|
||||
$and = "";
|
||||
if(isset($times['start_time'])){
|
||||
$and .= " and create_time >= '".$times['start_time']."' ";
|
||||
}
|
||||
if(isset($times['end_time'])){
|
||||
$and .= " and create_time < '".($times['end_time'] + 86400)."' ";
|
||||
}
|
||||
$and2 = " and create_time >= '".strtotime(date('Y-m-d'))."' and create_time < '".strtotime(date('Y-m-d').' 23:59:59')."' ";
|
||||
return $this->alias('a')
|
||||
->field('a.*, (select IFNULL(sum(amount),0) from yoshop_order where partners_id = a.partners_id and order_status = 20 '.$and.') as amount, (select IFNULL(sum(amount),0) from yoshop_order where partners_id = a.partners_id and order_status = 20 '.$and2.') as today')
|
||||
->order(['a.create_time' => 'desc'])
|
||||
->where($filter)
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商户充值
|
||||
* @param string $target 充值类型
|
||||
* @param array $data 表单数据
|
||||
* @return bool
|
||||
*/
|
||||
public function recharge(string $target, array $data)
|
||||
{
|
||||
// 当前操作人用户名
|
||||
$storeUserName = StoreUserService::getLoginInfo()['user']['user_name'];
|
||||
if ($target === self::RECHARGE_TYPE_BALANCE) {
|
||||
return $this->rechargeToBalance($storeUserName, $data['balance']);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商户充值:余额
|
||||
* @param string $storeUserName
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
private function rechargeToBalance(string $storeUserName, array $data)
|
||||
{
|
||||
if (!isset($data['money']) || $data['money'] === '' || $data['money'] < 0) {
|
||||
$this->error = '请输入正确的金额';
|
||||
return false;
|
||||
}
|
||||
// 判断充值方式,计算最终金额
|
||||
if ($data['mode'] === 'inc') {
|
||||
$diffMoney = $data['money'];
|
||||
} elseif ($data['mode'] === 'dec') {
|
||||
$diffMoney = -$data['money'];
|
||||
} else {
|
||||
$diffMoney = helper::bcsub($data['money'], $this['balance']);
|
||||
}
|
||||
// 更新记录
|
||||
$this->transaction(function () use ($storeUserName, $data, $diffMoney) {
|
||||
// 更新账户余额
|
||||
static::setIncBalance((int)$this['partners_id'], (float)$diffMoney);
|
||||
// 新增余额变动记录
|
||||
BalanceLogModel::add(SceneEnum::ADMIN, [
|
||||
'partners_id' => $this['partners_id'],
|
||||
'money' => (float)$diffMoney,
|
||||
'remark' => $data['remark'],
|
||||
], [$storeUserName]);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\library\helper;
|
||||
use app\common\model\PartnersGoods as PartnersGoodsModel;
|
||||
use cores\exception\BaseException;
|
||||
|
||||
/**
|
||||
* 合作商商品关系模型
|
||||
* Class PartnersGoods
|
||||
* @package app\store\model
|
||||
*/
|
||||
class PartnersGoods extends PartnersGoodsModel
|
||||
{
|
||||
/**
|
||||
* 验证商品是否合法
|
||||
* @param array $goodsList
|
||||
* @throws BaseException
|
||||
*/
|
||||
public static function checkGoodsData(array $goodsList)
|
||||
{
|
||||
$values = helper::getArrayColumn($goodsList, 'goods_id');
|
||||
if (count($goodsList) != count(array_unique($values))) {
|
||||
throwError('很抱歉,不能存在重复的商品 请检查您的选择');
|
||||
}
|
||||
foreach ($goodsList as &$item) {
|
||||
if($item['allot_num'] < 0 && abs($item['allot_num']) > $item['stock_num']){
|
||||
throwError('很抱歉,分配数量减少不能低于库存数量 请检查您的输入');
|
||||
}elseif($item['allot_num'] > 100){
|
||||
throwError('很抱歉,分配数量不能大于100 请检查您的输入');
|
||||
}
|
||||
$item['before_num'] = $item['stock_num'];
|
||||
$item['stock_num'] += $item['allot_num'];
|
||||
$item['after_num'] = $item['stock_num'];
|
||||
$item['change_type'] = $item['allot_num'] < 0 ? 2 : 1;
|
||||
}
|
||||
unset($item);
|
||||
return $goodsList;
|
||||
}
|
||||
/**
|
||||
* 批量写入合作商与商品关系记录
|
||||
* @param int $partnersId
|
||||
* @param array $goodsList
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increased(int $partnersId, array $goodsList)
|
||||
{
|
||||
$dataset = [];
|
||||
foreach ($goodsList as $item) {
|
||||
$dataset[] = [
|
||||
'partners_id' => $partnersId,
|
||||
'goods_id' => $item['goods_id'],
|
||||
'stock_num' => $item['stock_num'],
|
||||
'store_id' => self::$storeId
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新合作商和商品关系记录
|
||||
* @param int $partnersId
|
||||
* @param array $goodsList
|
||||
* @return array|false
|
||||
*/
|
||||
public static function updates(int $partnersId, array $goodsList)
|
||||
{
|
||||
// 删除所有的记录
|
||||
static::deleteAll(['partners_id' => $partnersId]);
|
||||
// 批量新增记录
|
||||
return static::increased($partnersId, $goodsList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Region as RegionModel;
|
||||
|
||||
/**
|
||||
* 地区模型
|
||||
* Class Region
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Region extends RegionModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use think\facade\Cache;
|
||||
use app\common\model\store\Setting as SettingModel;
|
||||
use app\common\enum\Setting as SettingEnum;
|
||||
|
||||
/**
|
||||
* 系统设置模型
|
||||
* Class Setting
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Setting extends SettingModel
|
||||
{
|
||||
/**
|
||||
* 更新系统设置
|
||||
* @param string $key
|
||||
* @param array $values
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function edit(string $key, array $values)
|
||||
{
|
||||
// 设置项详情记录
|
||||
$model = self::detail($key) ?: $this;
|
||||
// 数据验证
|
||||
if (!$this->validValues($key, $values)) {
|
||||
return false;
|
||||
}
|
||||
// 删除系统设置缓存
|
||||
Cache::delete('setting_' . self::$storeId);
|
||||
// 更新记录
|
||||
return $model->save([
|
||||
'key' => $key,
|
||||
'describe' => SettingEnum::data()[$key]['describe'],
|
||||
'values' => $values,
|
||||
'update_time' => time(),
|
||||
'store_id' => self::$storeId,
|
||||
]) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据验证
|
||||
* @param string $key
|
||||
* @param array $values
|
||||
* @return bool
|
||||
*/
|
||||
private function validValues(string $key, array $values)
|
||||
{
|
||||
$callback = [
|
||||
'store' => function ($values) {
|
||||
return $this->validStore($values);
|
||||
}
|
||||
];
|
||||
// 验证商城设置
|
||||
return isset($callback[$key]) ? $callback[$key]($values) : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证商城设置
|
||||
* @param array $values
|
||||
* @return bool
|
||||
*/
|
||||
private function validStore(array $values)
|
||||
{
|
||||
if (!isset($values['delivery_type']) || empty($values['delivery_type'])) {
|
||||
$this->error = '配送方式至少选择一个';
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\library\helper;
|
||||
use app\common\model\Spec as SpecModel;
|
||||
use app\store\model\SpecValue as SpecValueModel;
|
||||
use cores\exception\BaseException;
|
||||
|
||||
/**
|
||||
* 规格组模型
|
||||
* Class Spec
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Spec extends SpecModel
|
||||
{
|
||||
/**
|
||||
* 验证规格值是否合法
|
||||
* @param array $specList
|
||||
* @throws BaseException
|
||||
*/
|
||||
public static function checkSpecData(array $specList)
|
||||
{
|
||||
foreach ($specList as $item) {
|
||||
$values = helper::getArrayColumn($item['valueList'], 'spec_value');
|
||||
if (count($item['valueList']) != count(array_unique($values))) {
|
||||
throwError('很抱歉,不能存在重复的规格值 请检查您的输入');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 规格组写入数据库并生成id
|
||||
* 此时的$specList是用户端传来的
|
||||
* @param array $specList
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function getNewSpecList(array $specList): array
|
||||
{
|
||||
// 规格组名称合集
|
||||
$names = helper::getArrayColumn($specList, 'spec_name');
|
||||
// 获取到已存在的规格组
|
||||
$alreadyData = static::getListByNames($names);
|
||||
// 遍历整理新的规格集
|
||||
foreach ($specList as $key => &$item) {
|
||||
$alreadyItem = helper::getArrayItemByColumn($alreadyData, 'spec_name', $item['spec_name']);
|
||||
if (!empty($alreadyItem)) {
|
||||
// 规格名已存在的记录spec_id
|
||||
$item['spec_id'] = $alreadyItem['spec_id'];
|
||||
} else {
|
||||
// 规格名不存在的新增记录
|
||||
$result = static::add($item);
|
||||
$item['spec_id'] = $result['spec_id'];
|
||||
}
|
||||
// 规格值写入数据库并生成id
|
||||
$item['valueList'] = SpecValueModel::getNewValueList((int)$item['spec_id'], $item['valueList']);
|
||||
}
|
||||
return $specList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增规格组记录
|
||||
* @param array $item
|
||||
* @return static|\think\Model
|
||||
*/
|
||||
private static function add(array $item)
|
||||
{
|
||||
// 拿到所有的规格组名称集
|
||||
// 获取到已存在的
|
||||
return self::create([
|
||||
'spec_name' => $item['spec_name'],
|
||||
'store_id' => self::$storeId
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据规格组名称集获取列表
|
||||
* @param array $names
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private static function getListByNames(array $names): \think\Collection
|
||||
{
|
||||
return (new static)->where('spec_name', 'in', $names)->select();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\library\helper;
|
||||
use app\common\model\SpecValue as SpecValueModel;
|
||||
|
||||
/**
|
||||
* 规格/属性(值)模型
|
||||
* Class SpecValue
|
||||
* @package app\store\model
|
||||
*/
|
||||
class SpecValue extends SpecValueModel
|
||||
{
|
||||
/**
|
||||
* 规格值写入数据库并生成id
|
||||
* @param int $specId
|
||||
* @param array $valueList
|
||||
* @return array
|
||||
*/
|
||||
public static function getNewValueList(int $specId, array $valueList)
|
||||
{
|
||||
// 规格组名称合集
|
||||
$values = helper::getArrayColumn($valueList, 'spec_value');
|
||||
// 获取到已存在的规格值
|
||||
$alreadyData = static::getListByValues($specId, $values);
|
||||
// 遍历整理新的规格集
|
||||
foreach ($valueList as $key => &$item) {
|
||||
$alreadyItem = helper::getArrayItemByColumn($alreadyData, 'spec_value', $item['spec_value']);
|
||||
if (!empty($alreadyItem)) {
|
||||
// 规格值已存在的记录spec_value_id
|
||||
$item['spec_value_id'] = $alreadyItem['spec_value_id'];
|
||||
} else {
|
||||
// 规格值不存在的新增记录
|
||||
$result = static::add($specId, $item);
|
||||
$item['spec_value_id'] = $result['spec_value_id'];
|
||||
}
|
||||
}
|
||||
return $valueList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增规格组记录
|
||||
* @param int $specId
|
||||
* @param array $item
|
||||
* @return Spec|\think\Model
|
||||
*/
|
||||
private static function add(int $specId, array $item)
|
||||
{
|
||||
return self::create([
|
||||
'spec_value' => $item['spec_value'],
|
||||
'spec_id' => $specId,
|
||||
'store_id' => self::$storeId
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据规格组名称集获取列表
|
||||
* @param int $specId
|
||||
* @param array $values
|
||||
* @return \think\Collection
|
||||
*/
|
||||
private static function getListByValues(int $specId, array $values)
|
||||
{
|
||||
return (new static)->where('spec_id', '=', $specId)
|
||||
->where('spec_value', 'in', $values)
|
||||
->select();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Store as StoreModel;
|
||||
|
||||
/**
|
||||
* 商家记录表模型
|
||||
* Class Store
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Store extends StoreModel
|
||||
{
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
// 是否删除图片
|
||||
!isset($data['logo_image_id']) && $data['logo_image_id'] = 0;
|
||||
return $this->save($data) !== false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\store\model\Setting as SettingModel;
|
||||
use app\common\model\UploadFile as UploadFileModel;
|
||||
use app\common\library\storage\Driver as StorageDriver;
|
||||
use app\common\enum\Setting as SettingEnum;
|
||||
use app\common\enum\file\Storage as StorageEnum;
|
||||
|
||||
/**
|
||||
* 文件库模型
|
||||
* Class UploadFile
|
||||
* @package app\store\model
|
||||
*/
|
||||
class UploadFile extends UploadFileModel
|
||||
{
|
||||
/**
|
||||
* 获取列表记录
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList(array $param = []): \think\Paginator
|
||||
{
|
||||
// 商品列表获取条件
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'fileType' => -1, // 文件类型(-1全部 10图片 20附件 30视频)
|
||||
'groupId' => -1, // 分组ID(-1全部 0未分组)
|
||||
'fileName' => '', // 文件名称
|
||||
'storage' => '', // 存储方式(StorageEnum)
|
||||
'channel' => -1, // 上传来源(-1全部 10商户后台 20用户端)
|
||||
'isRecycle' => false // 是否在回收站
|
||||
]);
|
||||
// 查询对象
|
||||
$query = $this->getNewQuery();
|
||||
// 文件分组
|
||||
$params['groupId'] > -1 && $query->where('group_id', '=', (int)$params['groupId']);
|
||||
// 文件类型
|
||||
$params['fileType'] > -1 && $query->where('file_type', '=', (int)$params['fileType']);
|
||||
// 存储方式
|
||||
!empty($params['storage']) && $query->where('storage', '=', $params['storage']);
|
||||
// 上传来源
|
||||
$params['channel'] > -1 && $query->where('channel', '=', (int)$params['channel']);
|
||||
// 文件名称
|
||||
!empty($params['fileName']) && $query->where('file_name', 'like', "%{$params['fileName']}%");
|
||||
// 是否在回收站
|
||||
$query->where('is_recycle', '=', (int)$params['isRecycle']);
|
||||
// 查询列表数据
|
||||
return $query->where('channel', '=', 10)
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['file_id' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移入|移出回收站
|
||||
* @param bool $isRecycle
|
||||
* @return bool|false
|
||||
*/
|
||||
public function setRecycle(bool $isRecycle = true): bool
|
||||
{
|
||||
return $this->save(['is_recycle' => (int)$isRecycle]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件(批量)
|
||||
* @param array $fileIds 文件ID集
|
||||
* @return bool
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function setDelete(array $fileIds): bool
|
||||
{
|
||||
// 验证文件数量
|
||||
if (count($fileIds) > 15) {
|
||||
$this->error = '一次性最多删除15个文件';
|
||||
return false;
|
||||
}
|
||||
// 存储配置信息
|
||||
$config = SettingModel::getItem(SettingEnum::STORAGE);
|
||||
foreach ($fileIds as $fileId) {
|
||||
// 获取文件详情
|
||||
$fileInfo = static::detail($fileId);
|
||||
// 实例化存储驱动
|
||||
$storage = new StorageDriver($config, $fileInfo['storage']);
|
||||
// 删除文件
|
||||
if (!$storage->delete($fileInfo['file_path'])) {
|
||||
$this->error = '文件删除失败:' . $storage->getError();
|
||||
return false;
|
||||
}
|
||||
// 标记为已删除
|
||||
$fileInfo->save(['is_delete' => 1]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量移动文件分组
|
||||
* @param int $groupId
|
||||
* @param array $fileIds
|
||||
* @return bool
|
||||
*/
|
||||
public function moveGroup(int $groupId, array $fileIds): bool
|
||||
{
|
||||
return static::updateBase(['group_id' => $groupId], [['file_id', 'in', $fileIds]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加文件库记录
|
||||
* @param array $data
|
||||
* @param int $fileType
|
||||
* @param int $groupId
|
||||
* @return bool|false
|
||||
*/
|
||||
public function add(array $data, int $fileType, int $groupId = 0): bool
|
||||
{
|
||||
return $this->save([
|
||||
'group_id' => $groupId > 0 ? (int)$groupId : 0,
|
||||
'channel' => 10,
|
||||
'storage' => $data['storage'],
|
||||
'domain' => $data['domain'],
|
||||
'file_name' => $data['file_name'],
|
||||
'file_path' => $data['file_path'],
|
||||
'file_size' => $data['file_size'],
|
||||
'file_ext' => $data['file_ext'],
|
||||
'file_type' => $fileType,
|
||||
'store_id' => self::$storeId
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function edit(array $data): bool
|
||||
{
|
||||
return $this->allowField(['file_name', 'group_id'])->save($data) !== false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\store\model\UploadFile as UploadFileModel;
|
||||
use app\common\model\UploadGroup as UploadGroupModel;
|
||||
|
||||
/**
|
||||
* 文件库分组模型
|
||||
* Class UploadGroup
|
||||
* @package app\store\model
|
||||
*/
|
||||
class UploadGroup extends UploadGroupModel
|
||||
{
|
||||
/**
|
||||
* 获取列表记录
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
$list = $this->getAll();
|
||||
return $this->getTreeData($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有分组
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function getAll()
|
||||
{
|
||||
return $this->order(['sort', 'create_time'])->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取树状列表
|
||||
* @param $list
|
||||
* @param int $parentId
|
||||
* @return array
|
||||
*/
|
||||
private function getTreeData(&$list, int $parentId = 0)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($list as $key => $item) {
|
||||
if ($item['parent_id'] == $parentId) {
|
||||
$children = $this->getTreeData($list, $item['group_id']);
|
||||
!empty($children) && $item['children'] = $children;
|
||||
$data[] = $item;
|
||||
unset($list[$key]);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加新记录
|
||||
* @param array $data
|
||||
* @return false|int
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
return $this->save(array_merge([
|
||||
'store_id' => self::$storeId,
|
||||
'sort' => 100
|
||||
], $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
// 判断上级分组是否为当前子级
|
||||
if ($data['parent_id'] > 0) {
|
||||
// 获取所有上级id集
|
||||
$parentIds = $this->getTopGroupIds($data['parent_id']);
|
||||
if (in_array($this['group_id'], $parentIds)) {
|
||||
$this->error = '上级分组不允许设置为当前子分组';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $this->save($data) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有上级id集
|
||||
* @param int $groupId
|
||||
* @param null|array $list
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function getTopGroupIds(int $groupId, $list = null)
|
||||
{
|
||||
static $parentIds = [];
|
||||
is_null($list) && $list = $this->getAll();
|
||||
foreach ($list as $item) {
|
||||
if ($item['group_id'] == $groupId && $item['parent_id'] > 0) {
|
||||
$parentIds[] = $item['parent_id'];
|
||||
$this->getTopGroupIds($item['parent_id'], $list);
|
||||
}
|
||||
}
|
||||
return $parentIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品分组
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
// 判断是否存在下级分组
|
||||
if (static::detail(['parent_id' => $this['group_id']])) {
|
||||
$this->error = '当前分组下存在子分组,不允许删除';
|
||||
return false;
|
||||
}
|
||||
// 更新该分组下的所有文件
|
||||
UploadFileModel::updateBase(['group_id' => 0], ['group_id' => $this['group_id']]);
|
||||
// 删除分组记录
|
||||
return $this->delete();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,369 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\User as UserModel;
|
||||
|
||||
use app\store\model\UserOauth as UserOauthModel;
|
||||
use app\store\model\user\GradeLog as GradeLogModel;
|
||||
use app\store\model\user\PointsLog as PointsLogModel;
|
||||
use app\store\model\user\BalanceLog as BalanceLogModel;
|
||||
use app\store\service\store\User as StoreUserService;
|
||||
use app\common\enum\user\balanceLog\Scene as SceneEnum;
|
||||
use app\common\enum\user\grade\log\ChangeType as ChangeTypeEnum;
|
||||
use app\common\library\helper;
|
||||
|
||||
/**
|
||||
* 用户模型
|
||||
* Class User
|
||||
* @package app\store\model
|
||||
*/
|
||||
class User extends UserModel
|
||||
{
|
||||
// 充值类型枚举: 余额
|
||||
const RECHARGE_TYPE_BALANCE = 'balance';
|
||||
|
||||
// 充值类型枚举: 积分
|
||||
const RECHARGE_TYPE_POINTS = 'points';
|
||||
|
||||
/**
|
||||
* 获取当前用户总数
|
||||
* @param array $param 查询参数
|
||||
* @return int|string
|
||||
*/
|
||||
public function getUserTotal(array $param = [])
|
||||
{
|
||||
// 检索查询条件
|
||||
$filter = $this->getUserTotalFilter($param);
|
||||
// 查询结果
|
||||
return $this->where($filter)
|
||||
->where('is_delete', '=', '0')
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户总数的查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getUserTotalFilter(array $param = [])
|
||||
{
|
||||
// 默认查询参数
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'date' => null, // 注册日期 如: 2020-08-01
|
||||
'isConsume' => null, // 是否已消费
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
if (!is_null($params['date'])) {
|
||||
$startTime = strtotime($params['date']);
|
||||
$filter[] = ['create_time', '>=', $startTime];
|
||||
$filter[] = ['create_time', '<', $startTime + 86400];
|
||||
}
|
||||
if (is_bool($params['isConsume'])) {
|
||||
$filter[] = ['pay_money', $params['isConsume'] ? '>' : '=', 0];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
* @param array $param
|
||||
* @param array $user
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList(array $param = [], array $user = [])
|
||||
{
|
||||
if(!isset($param['merchantId']) && isset($user['is_super']) && $user['is_super'] == 0){
|
||||
$param['merchantId'] = $user['merchant_id'];
|
||||
}
|
||||
// 检索查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取用户列表
|
||||
return $this->with(['avatar', 'grade'])
|
||||
->where($filter)
|
||||
->where('is_delete', '=', '0')
|
||||
->order(['create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param = [])
|
||||
{
|
||||
// 默认查询条件
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'search' => '', // 微信昵称
|
||||
'gender' => -1, // 用户性别
|
||||
'gradeId' => 0, // 用户等级
|
||||
'merchantId' => 0, // 代理商
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 微信昵称
|
||||
!empty($params['search']) && $filter[] = ['nick_name|mobile', 'like', "%{$params['search']}%"];
|
||||
// 用户性别
|
||||
$params['gender'] > -1 && $filter[] = ['gender', '=', (int)$params['gender']];
|
||||
// 用户等级
|
||||
$params['gradeId'] > 0 && $filter[] = ['grade_id', '=', (int)$params['gradeId']];
|
||||
$params['merchantId'] > 0 && $filter[] = ['referrer_id', '=', (int)$params['merchantId']]; // 推广代理商
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['create_time', '>=', $times['start_time']];
|
||||
$filter[] = ['create_time', '<', $times['end_time'] + 86400];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function setDelete()
|
||||
{
|
||||
return $this->transaction(function () {
|
||||
// 将第三方用户信息记录标记删除
|
||||
UserOauthModel::updateBase(['is_delete' => 1], [
|
||||
['user_id', '=', $this['user_id']]
|
||||
]);
|
||||
// 标记为已删除
|
||||
return $this->save(['is_delete' => 1]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户充值
|
||||
* @param string $target 充值类型
|
||||
* @param array $data 表单数据
|
||||
* @return bool
|
||||
*/
|
||||
public function recharge(string $target, array $data)
|
||||
{
|
||||
// 当前操作人用户名
|
||||
$storeUserName = StoreUserService::getLoginInfo()['user']['user_name'];
|
||||
if ($target === self::RECHARGE_TYPE_BALANCE) {
|
||||
return $this->rechargeToBalance($storeUserName, $data['balance']);
|
||||
} elseif ($target === self::RECHARGE_TYPE_POINTS) {
|
||||
return $this->rechargeToPoints($storeUserName, $data['points']);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户充值:余额
|
||||
* @param string $storeUserName
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
private function rechargeToBalance(string $storeUserName, array $data)
|
||||
{
|
||||
if (!isset($data['money']) || $data['money'] === '' || $data['money'] < 0) {
|
||||
$this->error = '请输入正确的金额';
|
||||
return false;
|
||||
}
|
||||
// 判断充值方式,计算最终金额
|
||||
if ($data['mode'] === 'inc') {
|
||||
$diffMoney = $data['money'];
|
||||
} elseif ($data['mode'] === 'dec') {
|
||||
$diffMoney = -$data['money'];
|
||||
} else {
|
||||
$diffMoney = helper::bcsub($data['money'], $this['balance']);
|
||||
}
|
||||
// 更新记录
|
||||
$this->transaction(function () use ($storeUserName, $data, $diffMoney) {
|
||||
// 更新账户余额
|
||||
static::setIncBalance((int)$this['user_id'], (float)$diffMoney);
|
||||
// 新增余额变动记录
|
||||
BalanceLogModel::add(SceneEnum::ADMIN, [
|
||||
'user_id' => $this['user_id'],
|
||||
'money' => (float)$diffMoney,
|
||||
'remark' => $data['remark'],
|
||||
], [$storeUserName]);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户充值:积分
|
||||
* @param string $storeUserName
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
private function rechargeToPoints(string $storeUserName, array $data)
|
||||
{
|
||||
if (!isset($data['value']) || $data['value'] === '' || $data['value'] < 0) {
|
||||
$this->error = '请输入正确的积分数量';
|
||||
return false;
|
||||
}
|
||||
// 判断充值方式,计算最终积分
|
||||
if ($data['mode'] === 'inc') {
|
||||
$diffMoney = $data['value'];
|
||||
} elseif ($data['mode'] === 'dec') {
|
||||
$diffMoney = -$data['value'];
|
||||
} else {
|
||||
$diffMoney = $data['value'] - $this['points'];
|
||||
}
|
||||
// 更新记录
|
||||
$this->transaction(function () use ($storeUserName, $data, $diffMoney) {
|
||||
// 更新账户积分
|
||||
$this->setInc($this['user_id'], 'points', $diffMoney);
|
||||
// 新增积分变动记录
|
||||
PointsLogModel::add([
|
||||
'user_id' => $this['user_id'],
|
||||
'value' => $diffMoney,
|
||||
'describe' => "后台管理员 [{$storeUserName}] 操作",
|
||||
'remark' => $data['remark'],
|
||||
]);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户等级
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateGrade(array $data)
|
||||
{
|
||||
// 变更前的等级id
|
||||
$oldGradeId = $this['grade_id'];
|
||||
return $this->transaction(function () use ($oldGradeId, $data) {
|
||||
// 更新用户的等级
|
||||
$status = $this->save(['grade_id' => $data['grade_id']]);
|
||||
// 新增用户等级修改记录
|
||||
if ($status) {
|
||||
(new GradeLogModel)->record([
|
||||
'user_id' => $this['user_id'],
|
||||
'old_grade_id' => $oldGradeId,
|
||||
'new_grade_id' => $data['grade_id'],
|
||||
'change_type' => ChangeTypeEnum::ADMIN_USER,
|
||||
'remark' => $data['remark']
|
||||
]);
|
||||
}
|
||||
return $status !== false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 消减用户的实际消费金额
|
||||
* @param int $userId
|
||||
* @param float $expendMoney
|
||||
* @return mixed
|
||||
*/
|
||||
public function setDecUserExpend(int $userId, float $expendMoney)
|
||||
{
|
||||
return $this->setDec(['user_id' => $userId], 'expend_money', $expendMoney);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param $data
|
||||
* @param array $user
|
||||
* @return bool|false|int
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function add($data, $user = [])
|
||||
{
|
||||
$this->startTrans();
|
||||
try {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function edit($data)
|
||||
{
|
||||
if (empty($data['userType'])) {
|
||||
$this->error = '请填写用户角色';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['userName'])) {
|
||||
$this->error = '请填写用户姓名';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['mobile'])) {
|
||||
$this->error = '请填写用户手机号';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['userIdCard'])) {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户充值:余额
|
||||
* @param string $storeUserName
|
||||
* @param array $data
|
||||
* @param int $storeId
|
||||
* @return bool
|
||||
*/
|
||||
public function exchangeToBalance(string $storeUserName, array $data, int $storeId)
|
||||
{
|
||||
if (!isset($data['money']) || $data['money'] === '' || $data['money'] < 0) {
|
||||
$this->error = '请输入正确的金额';
|
||||
return false;
|
||||
}
|
||||
// 判断充值方式,计算最终金额
|
||||
if ($data['mode'] === 'inc') {
|
||||
$diffMoney = $data['money'];
|
||||
} elseif ($data['mode'] === 'dec') {
|
||||
$diffMoney = -$data['money'];
|
||||
} else {
|
||||
$diffMoney = helper::bcsub($data['money'], $this['balance']);
|
||||
}
|
||||
// 更新记录
|
||||
$this->transaction(function () use ($storeUserName, $data, $diffMoney, $storeId) {
|
||||
// 更新账户余额
|
||||
static::setIncBalance((int)$this['user_id'], (float)$diffMoney);
|
||||
// 新增余额变动记录
|
||||
BalanceLogModel::addExchange(SceneEnum::EXCHANGE, [
|
||||
'user_id' => $this['user_id'],
|
||||
'money' => (float)$diffMoney,
|
||||
'remark' => $data['remark'],
|
||||
'store_id' => $storeId
|
||||
], [$storeUserName]);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\UserAddress as UserAddressModel;
|
||||
|
||||
/**
|
||||
* 用户收货地址模型
|
||||
* Class UserAddress
|
||||
* @package app\store\model
|
||||
*/
|
||||
class UserAddress extends UserAddressModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\UserCoupon as UserCouponModel;
|
||||
|
||||
/**
|
||||
* 用户优惠券模型
|
||||
* Class UserCoupon
|
||||
* @package app\store\model
|
||||
*/
|
||||
class UserCoupon extends UserCouponModel
|
||||
{
|
||||
/**
|
||||
* 获取列表记录
|
||||
* @param array $param
|
||||
* @return mixed
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 设置查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取列表数据
|
||||
return $this->with(['user.avatar'])
|
||||
->alias('m')
|
||||
->field('m.*')
|
||||
->join('user', 'user.user_id = m.user_id')
|
||||
->where($filter)
|
||||
->order(['m.create_time' => 'desc', $this->getPk()])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param): array
|
||||
{
|
||||
// 设置默认的检索数据
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'userId' => 0, // 会员ID
|
||||
'couponName' => '', // 优惠券名称
|
||||
'nickName' => '', // 会员昵称
|
||||
'betweenTime' => [], // 起止时间
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 用户ID
|
||||
$params['userId'] > 0 && $filter[] = ['m.user_id', '=', $params['userId']];
|
||||
// 会员昵称
|
||||
!empty($params['couponName']) && $filter[] = ['m.name', 'like', "%{$params['couponName']}%"];
|
||||
// 会员昵称
|
||||
!empty($params['nickName']) && $filter[] = ['user.nick_name', 'like', "%{$params['nickName']}%"];
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['m.create_time', '>=', $times['start_time']];
|
||||
$filter[] = ['m.create_time', '<', $times['end_time'] + 86400];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\UserOauth as UserOauthModel;
|
||||
|
||||
/**
|
||||
* 模型类:第三方用户信息
|
||||
* Class UserOauth
|
||||
* @package app\store\model
|
||||
*/
|
||||
class UserOauth extends UserOauthModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\article;
|
||||
|
||||
use app\store\model\Article as ArticleModel;
|
||||
use app\common\model\article\Category as CategoryModel;
|
||||
|
||||
/**
|
||||
* 文章分类模型
|
||||
* Class Category
|
||||
* @package app\store\model\article
|
||||
*/
|
||||
class Category extends CategoryModel
|
||||
{
|
||||
/**
|
||||
* 添加新记录
|
||||
* @param $data
|
||||
* @return false|int
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
// 保存记录
|
||||
$data['store_id'] = self::$storeId;
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑记录
|
||||
* @param $data
|
||||
* @return bool|int
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
// 保存记录
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品分类
|
||||
* @param int $categoryId
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function remove(int $categoryId)
|
||||
{
|
||||
// 判断是否存在文章
|
||||
$articleCount = ArticleModel::getArticleTotal(['category_id' => $categoryId]);
|
||||
if ($articleCount > 0) {
|
||||
$this->error = '该分类下存在' . $articleCount . '个文章,不允许删除';
|
||||
return false;
|
||||
}
|
||||
// 删除记录
|
||||
return $this->delete();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\card;
|
||||
|
||||
use app\common\model\card\CardLog as CardLogModel;
|
||||
|
||||
/**
|
||||
* 兑换明细模型
|
||||
* Class CardLog
|
||||
* @package app\store\model\card
|
||||
*/
|
||||
class CardLog extends CardLogModel
|
||||
{
|
||||
/**
|
||||
* 获取余额变动明细列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 设置查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取列表数据
|
||||
return $this->alias('log')
|
||||
->field('log.*')
|
||||
->where($filter)
|
||||
->join('user', 'user.user_id = log.user_id')
|
||||
->join('card', 'card.card_id = log.card_id')
|
||||
->order(['log.create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param): array
|
||||
{
|
||||
// 设置默认的检索数据
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'user_id' => 0, // 用户ID
|
||||
'search' => '', // 用户昵称
|
||||
'card_number' => '', // 卡号
|
||||
'betweenTime' => [] // 起止时间
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 用户ID
|
||||
$params['user_id'] > 0 && $filter[] = ['log.user_id', '=', $params['user_id']];
|
||||
// 用户昵称
|
||||
!empty($params['search']) && $filter[] = ['user.nick_name', 'like', "%{$params['search']}%"];
|
||||
// 用户昵称
|
||||
!empty($params['card_number']) && $filter[] = ['card.card_number', 'like', "%{$params['card_number']}%"];
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['log.create_time', '>=', $times['start_time']];
|
||||
$filter[] = ['log.create_time', '<', $times['end_time'] + 86400];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\card;
|
||||
|
||||
use app\common\model\card\CardPrint as CardPrintModel;
|
||||
|
||||
/**
|
||||
* 兑换卡打印记录模型
|
||||
* Class CardPrint
|
||||
* @package app\store\model\card
|
||||
*/
|
||||
class CardPrint extends CardPrintModel
|
||||
{
|
||||
/**
|
||||
* 获取兑换卡打印记录列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 设置查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取列表数据
|
||||
$list = $this->alias('print')
|
||||
->field('print.*')
|
||||
->where($filter)
|
||||
->order(['print.create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
// 生成下载url
|
||||
foreach ($list as &$item) {
|
||||
$item['download_url'] = base_url() . $item['file_path'];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param): array
|
||||
{
|
||||
// 设置默认的检索数据
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'batch' => '', // 批号
|
||||
'betweenTime' => [] // 起止时间
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['print.create_time', '>=', $times['start_time']];
|
||||
$filter[] = ['print.create_time', '<', $times['end_time'] + 86400];
|
||||
}
|
||||
!empty($params['batch']) && $filter[] = ['batch', 'like', '%' . trim($params['batch']) . '%'];
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换下载状态
|
||||
* @param $is_download
|
||||
* @return false|int
|
||||
*/
|
||||
public function changeStatus($is_download)
|
||||
{
|
||||
return $this->save(['is_download' => $is_download, 'download_time' => time()]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\company;
|
||||
|
||||
use app\common\model\company\BalanceLog as BalanceLogModel;
|
||||
|
||||
/**
|
||||
* 公司余额变动明细模型
|
||||
* Class BalanceLog
|
||||
* @package app\store\model\company
|
||||
*/
|
||||
class BalanceLog extends BalanceLogModel
|
||||
{
|
||||
/**
|
||||
* 获取余额变动明细列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 设置查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取列表数据
|
||||
return $this->alias('log')
|
||||
->field('log.*,company.name')
|
||||
->where($filter)
|
||||
->join('company', 'company.company_id = log.company_id')
|
||||
->order(['log.create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param): array
|
||||
{
|
||||
// 设置默认的检索数据
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'company_id' => 0, // 用户ID
|
||||
'search' => '', // 用户昵称
|
||||
'scene' => 0, // 余额变动场景
|
||||
'betweenTime' => [] // 起止时间
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 用户ID
|
||||
$params['company_id'] > 0 && $filter[] = ['log.company_id', '=', $params['company_id']];
|
||||
// 用户昵称
|
||||
!empty($params['search']) && $filter[] = ['company.name', 'like', "%{$params['search']}%"];
|
||||
// 余额变动场景
|
||||
$params['scene'] > 0 && $filter[] = ['log.scene', '=', (int)$params['scene']];
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['log.create_time', '>=', $times['start_time']];
|
||||
$filter[] = ['log.create_time', '<', $times['end_time'] + 86400];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\goods;
|
||||
|
||||
use app\common\model\goods\Service as ServiceModel;
|
||||
use app\store\model\goods\ServiceRel as ServiceRelModel;
|
||||
|
||||
/**
|
||||
* 商品服务与承诺模型
|
||||
* Class Service
|
||||
*/
|
||||
class Service extends ServiceModel
|
||||
{
|
||||
/**
|
||||
* 获取全部记录
|
||||
* @param array $param
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAll(array $param = [])
|
||||
{
|
||||
return $this->where($this->getFilter($param))
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['sort', $this->getPk()])
|
||||
->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表记录
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
return $this->where($this->getFilter($param))
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['sort', $this->getPk()])
|
||||
->paginate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param = [])
|
||||
{
|
||||
// 默认查询参数
|
||||
$params = $this->setQueryDefaultValue($param, ['search' => '']);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
!empty($params['search']) && $filter[] = ['name', 'like', "%{$params['search']}%"];
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param array $data
|
||||
* @return false|int
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
$data['store_id'] = self::$storeId;
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool|int
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
return $this->save($data) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录(软删除)
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
// 判断该服务是否被商品引用
|
||||
$goodsCount = ServiceRelModel::getCountByServiceId($this['service_id']);
|
||||
if ($goodsCount > 0) {
|
||||
$this->error = "该记录被{$goodsCount}个商品引用,不允许删除";
|
||||
return false;
|
||||
}
|
||||
return $this->save(['is_delete' => 1]) !== false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\goods;
|
||||
|
||||
use app\common\model\goods\ServiceRel as ServiceRelModel;
|
||||
|
||||
/**
|
||||
* 商品服务与承诺模型
|
||||
* Class ServiceRel
|
||||
*/
|
||||
class ServiceRel extends ServiceRelModel
|
||||
{
|
||||
/**
|
||||
* 根据服务ID获取记录总数量
|
||||
* @param int $serviceId
|
||||
* @return int
|
||||
*/
|
||||
public static function getCountByServiceId(int $serviceId)
|
||||
{
|
||||
return (new static)->where('service_id', '=', $serviceId)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量写入商品服务记录
|
||||
* @param int $goodsId
|
||||
* @param array $serviceIds
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increased(int $goodsId, array $serviceIds)
|
||||
{
|
||||
$dataset = [];
|
||||
foreach ($serviceIds as $serviceId) {
|
||||
$dataset[] = [
|
||||
'service_id' => $serviceId,
|
||||
'goods_id' => $goodsId,
|
||||
'store_id' => self::$storeId
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新关系记录
|
||||
* @param $goodsId
|
||||
* @param array $serviceIds 新的服务集
|
||||
* @return array|false
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function updates(int $goodsId, array $serviceIds)
|
||||
{
|
||||
// 已分配的服务集
|
||||
$assignServiceIds = self::getServiceIds($goodsId);
|
||||
// 找出删除的服务
|
||||
$deleteServiceIds = array_diff($assignServiceIds, $serviceIds);
|
||||
if (!empty($deleteServiceIds)) {
|
||||
static::deleteAll([
|
||||
['goods_id', '=', $goodsId],
|
||||
['service_id', 'in', $deleteServiceIds]
|
||||
]);
|
||||
}
|
||||
// 找出添加的服务
|
||||
$newServiceIds = array_diff($serviceIds, $assignServiceIds);
|
||||
$dataset = [];
|
||||
foreach ($newServiceIds as $serviceId) {
|
||||
$dataset[] = [
|
||||
'goods_id' => $goodsId,
|
||||
'service_id' => $serviceId,
|
||||
'store_id' => self::$storeId,
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\h5;
|
||||
|
||||
use think\facade\Cache;
|
||||
use app\common\model\h5\Setting as SettingModel;
|
||||
|
||||
/**
|
||||
* H5设置模型
|
||||
* Class Setting
|
||||
* @package app\store\model\wxapp
|
||||
*/
|
||||
class Setting extends SettingModel
|
||||
{
|
||||
/**
|
||||
* 设置项描述
|
||||
* @var array
|
||||
*/
|
||||
private $describe = [
|
||||
'basic' => '基础设置',
|
||||
];
|
||||
|
||||
/**
|
||||
* 更新系统设置
|
||||
* @param string $key
|
||||
* @param array $values
|
||||
* @return bool
|
||||
*/
|
||||
public function edit(string $key, array $values): bool
|
||||
{
|
||||
$model = self::detail($key) ?: $this;
|
||||
// 删除系统设置缓存
|
||||
Cache::delete('h5_setting_' . self::$storeId);
|
||||
return $model->save([
|
||||
'key' => $key,
|
||||
'describe' => $this->describe[$key],
|
||||
'values' => $values,
|
||||
'update_time' => time(),
|
||||
'store_id' => self::$storeId,
|
||||
]) !== false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\merchant;
|
||||
|
||||
use app\common\model\merchant\BalanceLog as BalanceLogModel;
|
||||
|
||||
/**
|
||||
* 用户余额变动明细模型
|
||||
* Class BalanceLog
|
||||
* @package app\store\model\merchant
|
||||
*/
|
||||
class BalanceLog extends BalanceLogModel
|
||||
{
|
||||
/**
|
||||
* 获取余额变动明细列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 设置查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取列表数据
|
||||
return $this->alias('log')
|
||||
->field('log.*,merchant.name')
|
||||
->where($filter)
|
||||
->join('merchant', 'merchant.merchant_id = log.merchant_id')
|
||||
->order(['log.create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param): array
|
||||
{
|
||||
// 设置默认的检索数据
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'merchant_id' => 0, // 用户ID
|
||||
'search' => '', // 用户昵称
|
||||
'scene' => 0, // 余额变动场景
|
||||
'betweenTime' => [] // 起止时间
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 用户ID
|
||||
$params['merchant_id'] > 0 && $filter[] = ['log.merchant_id', '=', $params['merchant_id']];
|
||||
// 用户昵称
|
||||
!empty($params['search']) && $filter[] = ['merchant.name', 'like', "%{$params['search']}%"];
|
||||
// 余额变动场景
|
||||
$params['scene'] > 0 && $filter[] = ['log.scene', '=', (int)$params['scene']];
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['log.create_time', '>=', $times['start_time']];
|
||||
$filter[] = ['log.create_time', '<', $times['end_time'] + 86400];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\merchant;
|
||||
|
||||
use app\common\model\merchant\MerchantOrder as MerchantOrderModel;
|
||||
|
||||
/**
|
||||
* 代理商订单
|
||||
* Class MerchantOrder
|
||||
* @package app\store\model\merchant
|
||||
*/
|
||||
class MerchantOrder extends MerchantOrderModel
|
||||
{
|
||||
/**
|
||||
* 获取余额变动明细列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 设置查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取列表数据
|
||||
return $this->with(['user.avatar', 'goods.images.file', 'merchant'])
|
||||
->alias('order')
|
||||
->field('order.*')
|
||||
->where($filter)
|
||||
->leftJoin('user', 'user.user_id = order.user_id')
|
||||
->order(['order.create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param): array
|
||||
{
|
||||
// 设置默认的检索数据
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'merchant_id' => 0, // 用户ID
|
||||
'search' => '', // 用户昵称
|
||||
'betweenTime' => [] // 起止时间
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 用户ID
|
||||
$params['merchant_id'] > 0 && $filter[] = ['order.merchant_id', '=', $params['merchant_id']];
|
||||
// 用户昵称
|
||||
!empty($params['search']) && $filter[] = ['user.mobile', 'like', "%{$params['search']}%"];
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['order.create_time', '>=', $times['start_time']];
|
||||
$filter[] = ['order.create_time', '<', $times['end_time'] + 86400];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某天的总销售额
|
||||
* @param null $startDate
|
||||
* @param null $endDate
|
||||
* @param array $merchant
|
||||
* @return float
|
||||
*/
|
||||
public function getOrderTotalPrice($startDate = null, $endDate = null,$merchant=[]): float
|
||||
{
|
||||
// 查询对象
|
||||
$query = $this->getNewQuery();
|
||||
$filter = [];
|
||||
// 设置查询条件
|
||||
if (!is_null($startDate) && !is_null($endDate)) {
|
||||
$filter[] = ['create_time', '>=', strtotime($startDate)];
|
||||
$filter[] = ['create_time', '<', strtotime($endDate) + 86400];
|
||||
}
|
||||
if(!empty($merchant)) {
|
||||
$filter[] = ['merchant_id', '=', $merchant['merchant_id']];
|
||||
}
|
||||
// 总销售额
|
||||
return $query->where('order_status', '=', 30)
|
||||
->where($filter)
|
||||
->sum('order_price');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\order;
|
||||
|
||||
use app\common\model\order\Export as ExportModel;
|
||||
use think\db\exception\DbException;
|
||||
|
||||
/**
|
||||
* 订单导出Excel记录模型
|
||||
* Class Export
|
||||
* @package app\store\model\order
|
||||
*/
|
||||
class Export extends ExportModel
|
||||
{
|
||||
/**
|
||||
* 获取导出记录
|
||||
* @return \think\Paginator
|
||||
* @throws DbException
|
||||
*/
|
||||
public function getList(): \think\Paginator
|
||||
{
|
||||
// 获取列表记录
|
||||
$list = $this->order(['create_time' => 'desc'])->paginate(10);
|
||||
// 生成下载url
|
||||
foreach ($list as &$item) {
|
||||
$item['download_url'] = base_url() . $item['file_path'];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
public function add($data): bool
|
||||
{
|
||||
return $this->save($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\order;
|
||||
|
||||
use app\common\model\order\QrCode as QrCodeModel;
|
||||
use think\db\exception\DbException;
|
||||
|
||||
/**
|
||||
* 支付码记录
|
||||
* Class Export
|
||||
* @package app\store\model\order
|
||||
*/
|
||||
class QrCode extends QrCodeModel
|
||||
{
|
||||
/**
|
||||
* 获取导出记录
|
||||
* @return \think\Paginator
|
||||
* @throws DbException
|
||||
*/
|
||||
public function getList(): \think\Paginator
|
||||
{
|
||||
// 获取列表记录
|
||||
return $this->order(['create_time' => 'desc'])->paginate(10);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
public function add($data): bool
|
||||
{
|
||||
return $this->save($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\order;
|
||||
|
||||
use app\common\model\order\Record as RecordModel;
|
||||
use think\db\exception\DbException;
|
||||
|
||||
/**
|
||||
* 分油通知记录模型
|
||||
* Class Record
|
||||
* @package app\store\model\order
|
||||
*/
|
||||
class Record extends RecordModel
|
||||
{
|
||||
/**
|
||||
* 获取导出记录
|
||||
* @return \think\Paginator
|
||||
* @throws DbException
|
||||
*/
|
||||
public function getList(): \think\Paginator
|
||||
{
|
||||
// 获取列表记录
|
||||
return $this->order(['create_time' => 'desc'])->paginate(10);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
public function add($data): bool
|
||||
{
|
||||
return $this->save($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\partners;
|
||||
|
||||
use app\common\model\partners\BalanceLog as BalanceLogModel;
|
||||
|
||||
/**
|
||||
* 用户余额变动明细模型
|
||||
* Class BalanceLog
|
||||
* @package app\store\model\partners
|
||||
*/
|
||||
class BalanceLog extends BalanceLogModel
|
||||
{
|
||||
/**
|
||||
* 获取余额变动明细列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 设置查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取列表数据
|
||||
return $this->alias('log')
|
||||
->field('log.*,partners.name')
|
||||
->where($filter)
|
||||
->join('partners', 'partners.partners_id = log.partners_id')
|
||||
->order(['log.create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param): array
|
||||
{
|
||||
// 设置默认的检索数据
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'partners_id' => 0, // 用户ID
|
||||
'search' => '', // 用户昵称
|
||||
'scene' => 0, // 余额变动场景
|
||||
'betweenTime' => [] // 起止时间
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 用户ID
|
||||
$params['partners_id'] > 0 && $filter[] = ['log.partners_id', '=', $params['partners_id']];
|
||||
// 用户昵称
|
||||
!empty($params['search']) && $filter[] = ['partners.name', 'like', "%{$params['search']}%"];
|
||||
// 余额变动场景
|
||||
$params['scene'] > 0 && $filter[] = ['log.scene', '=', (int)$params['scene']];
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['log.create_time', '>=', $times['start_time']];
|
||||
$filter[] = ['log.create_time', '<', $times['end_time'] + 86400];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\partners;
|
||||
|
||||
use app\common\model\partners\Order as OrderModel;
|
||||
|
||||
/**
|
||||
* 合作商订单
|
||||
* Class Order
|
||||
* @package app\store\model\partners
|
||||
*/
|
||||
class Order extends OrderModel
|
||||
{
|
||||
/**
|
||||
* 获取余额变动明细列表
|
||||
* @param array $param
|
||||
* @return mixed
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 设置查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 先查询总金额
|
||||
$totalPayPrice = $this->with(['goods.images.file', 'partners'])
|
||||
->alias('order')
|
||||
->field('order.*')
|
||||
->where($filter)
|
||||
->sum('order.total_pay_price');
|
||||
// 获取列表数据
|
||||
$list = $this->with(['goods.images.file', 'partners'])
|
||||
->alias('order')
|
||||
->field('order.*')
|
||||
->where($filter)
|
||||
->order(['order.create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
// 获取数据列表
|
||||
return [
|
||||
'list' => $list,
|
||||
'total_money' => $totalPayPrice,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param): array
|
||||
{
|
||||
// 设置默认的检索数据
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'partners_id' => 0, // 合作商ID
|
||||
'search' => '', // 用户昵称
|
||||
'goods_no' => '', // 商品编码
|
||||
'oil_status' => -1, // 分油状态
|
||||
'use_status' => -1, // 使用状态
|
||||
'betweenTime' => [] // 起止时间
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 合作商ID
|
||||
$params['partners_id'] > 0 && $filter[] = ['order.partners_id', '=', $params['partners_id']];
|
||||
// 用户昵称
|
||||
!empty($params['search']) && $filter[] = ['order.mobile', 'like', "%{$params['search']}%"];
|
||||
// 商品编码
|
||||
!empty($params['goods_no']) && $filter[] = ['order.goods_no', 'like', "%{$params['goods_no']}%"];
|
||||
// 分油状态
|
||||
$params['oil_status'] > -1 && $filter[] = ['oil_status', '=', (int)$params['oil_status']];
|
||||
// 使用状态
|
||||
$params['use_status'] > -1 && $filter[] = ['use_status', '=', (int)$params['use_status']];
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['order.create_time', '>=', strtotime(date('Y-m-d',$times['start_time']))];
|
||||
$filter[] = ['order.create_time', '<', strtotime(date('Y-m-d',$times['end_time'])) + 86400];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部记录
|
||||
* @param array $param
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAll(array $param = [])
|
||||
{
|
||||
return $this->where($param)
|
||||
->order(['order_id' => 'asc'])
|
||||
->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某天的总销售额
|
||||
* @param null $startDate
|
||||
* @param null $endDate
|
||||
* @param array $partners
|
||||
* @return float
|
||||
*/
|
||||
public function getOrderTotalPrice($startDate = null, $endDate = null,$partners=[]): float
|
||||
{
|
||||
// 查询对象
|
||||
$query = $this->getNewQuery();
|
||||
$filter = [];
|
||||
// 设置查询条件
|
||||
if (!is_null($startDate) && !is_null($endDate)) {
|
||||
$filter[] = ['create_time', '>=', strtotime($startDate)];
|
||||
$filter[] = ['create_time', '<', strtotime($endDate) + 86400];
|
||||
}
|
||||
if(!empty($partners)) {
|
||||
$filter[] = ['partners_id', '=', $partners['partners_id']];
|
||||
}
|
||||
// 总销售额
|
||||
return $query->where('oil_status_zsy', '=', 2)
|
||||
->where($filter)
|
||||
->sum('total_price');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\partners;
|
||||
|
||||
use app\common\model\partners\StockLog as StockLogModel;
|
||||
|
||||
/**
|
||||
* 合作商商品库存变动明细模型
|
||||
* Class StockLog
|
||||
* @package app\store\model\partners
|
||||
*/
|
||||
class StockLog extends StockLogModel
|
||||
{
|
||||
/**
|
||||
* 获取合作商商品库存变动明细列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 设置查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取列表数据
|
||||
return $this->alias('log')
|
||||
->field('log.*,partners.name')
|
||||
->where($filter)
|
||||
->join('partners', 'partners.partners_id = log.partners_id')
|
||||
->order(['log.create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param): array
|
||||
{
|
||||
// 设置默认的检索数据
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'partners_id' => 0, // 合作商ID
|
||||
'search' => '', // 用户昵称
|
||||
'betweenTime' => [] // 起止时间
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 用户ID
|
||||
$params['partners_id'] > 0 && $filter[] = ['log.partners_id', '=', $params['partners_id']];
|
||||
// 用户昵称
|
||||
!empty($params['search']) && $filter[] = ['partners.name', 'like', "%{$params['search']}%"];
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['log.create_time', '>=', $times['start_time']];
|
||||
$filter[] = ['log.create_time', '<', $times['end_time'] + 86400];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量写入合作商与商品库存变动记录
|
||||
* @param int $partnersId
|
||||
* @param array $goodsList
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increased(int $partnersId, array $goodsList)
|
||||
{
|
||||
$dataset = [];
|
||||
foreach ($goodsList as $item) {
|
||||
if(!empty($item['allot_num'])) {
|
||||
$dataset[] = [
|
||||
'partners_id' => $partnersId,
|
||||
'goods_id' => $item['goods_id'],
|
||||
'before_num' => $item['before_num'],
|
||||
'after_num' => $item['after_num'],
|
||||
'change_type' => $item['change_type'],
|
||||
'change_num' => $item['allot_num'],
|
||||
'store_id' => self::$storeId
|
||||
];
|
||||
}
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\recharge;
|
||||
|
||||
use app\common\model\recharge\Order as OrderModel;
|
||||
|
||||
/**
|
||||
* 用户充值订单模型
|
||||
* Class Order
|
||||
* @package app\store\model\recharge
|
||||
*/
|
||||
class Order extends OrderModel
|
||||
{
|
||||
/**
|
||||
* 获取订单列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 设置查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取列表数据
|
||||
return $this->with(['user.avatar', 'order_plan'])
|
||||
->alias('order')
|
||||
->field('order.*')
|
||||
->where($filter)
|
||||
->join('user', 'user.user_id = order.user_id')
|
||||
->order(['order.create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param): array
|
||||
{
|
||||
// 设置默认的检索数据
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'user_id' => 0, // 用户ID
|
||||
'search' => '', // 查询内容
|
||||
'recharge_type' => 0, // 充值方式
|
||||
'pay_status' => 0, // 支付状态
|
||||
'betweenTime' => [] // 起止时间
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 用户ID
|
||||
$params['user_id'] > 0 && $filter[] = ['order.user_id', '=', $params['user_id']];
|
||||
// 用户昵称/订单号
|
||||
!empty($params['search']) && $filter[] = ['order.order_no|user.nick_name', 'like', "%{$params['search']}%"];
|
||||
// 充值方式
|
||||
$params['recharge_type'] > 0 && $filter[] = ['order.recharge_type', '=', (int)$params['recharge_type']];
|
||||
// 支付状态
|
||||
$params['pay_status'] > 0 && $filter[] = ['order.pay_status', '=', (int)$params['pay_status']];
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['order.pay_time', '>=', $times['start_time']];
|
||||
$filter[] = ['order.pay_time', '<', $times['end_time'] + 86400];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\recharge;
|
||||
|
||||
use app\common\model\recharge\OrderPlan as OrderPlanModel;
|
||||
|
||||
/**
|
||||
* 用户充值订单套餐快照模型
|
||||
* Class OrderPlan
|
||||
* @package app\store\model\recharge
|
||||
*/
|
||||
class OrderPlan extends OrderPlanModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\recharge;
|
||||
|
||||
use app\common\model\recharge\Plan as PlanModel;
|
||||
|
||||
/**
|
||||
* 会员充值套餐模型
|
||||
* Class Plan
|
||||
* @package app\store\model\recharge
|
||||
*/
|
||||
class Plan extends PlanModel
|
||||
{
|
||||
/**
|
||||
* 列表记录
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 检索查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 查询列表数据
|
||||
return $this->where($filter)
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['sort', $this->getPk()])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检索查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param = []): array
|
||||
{
|
||||
// 默认查询条件
|
||||
$params = $this->setQueryDefaultValue($param, ['search' => '']);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
!empty($params['search']) && $filter[] = ['plan_name', 'like', "%{$params['search']}%"];
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param array $data
|
||||
* @return false|int
|
||||
*/
|
||||
public function add(array $data): bool
|
||||
{
|
||||
$data['store_id'] = self::$storeId;
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool|int
|
||||
*/
|
||||
public function edit(array $data): bool
|
||||
{
|
||||
return $this->save($data) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录 (软删除)
|
||||
* @return bool|int
|
||||
*/
|
||||
public function setDelete(): bool
|
||||
{
|
||||
return $this->save(['is_delete' => 1]) !== false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\store;
|
||||
|
||||
use app\common\model\store\Address as StoreAddressModel;
|
||||
|
||||
/**
|
||||
* 商家地址模型
|
||||
* Class Address
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Address extends StoreAddressModel
|
||||
{
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
return $this->where($this->getFilter($param))
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['sort', $this->getPk()])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部记录
|
||||
* @param array $param
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAll(array $param = [])
|
||||
{
|
||||
return $this->where($this->getFilter($param))
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['sort', $this->getPk()])
|
||||
->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据param检索查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param = [])
|
||||
{
|
||||
// 默认查询条件
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'type' => 0, // 地址类型(10发货地址 20退货地址)
|
||||
'search' => '', // 收货人姓名/联系电话
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
$params['type'] > 0 && $filter[] = ['type', '=', $params['type']];
|
||||
!empty($params['search']) && $filter[] = ['name|phone', 'like', "%{$params['search']}%"];
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加新记录
|
||||
* @param array $data
|
||||
* @return false|int
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
[$data['province_id'], $data['city_id'], $data['region_id']] = $data['cascader'];
|
||||
$data['store_id'] = self::$storeId;
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑记录
|
||||
* @param array $data
|
||||
* @return bool|int
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
[$data['province_id'], $data['city_id'], $data['region_id']] = $data['cascader'];
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* @return bool|int
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
return $this->save(['is_delete' => 1]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\store;
|
||||
|
||||
use app\common\model\store\Api as ApiModel;
|
||||
use app\common\library\helper;
|
||||
|
||||
/**
|
||||
* 商家用户权限模型
|
||||
* Class Api
|
||||
* @package app\store\model\store
|
||||
*/
|
||||
class Api extends ApiModel
|
||||
{
|
||||
/**
|
||||
* 获取权限列表 jstree格式
|
||||
* @param int $role_id 当前角色id
|
||||
* @return string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getJsTree($role_id = null)
|
||||
{
|
||||
$apiIds = is_null($role_id) ? [] : RoleAccess::getAccessIds($role_id);
|
||||
$jsTree = [];
|
||||
foreach ($this->getAll() as $item) {
|
||||
$jsTree[] = [
|
||||
'id' => $item['api_id'],
|
||||
'parent' => $item['parent_id'] > 0 ? $item['parent_id'] : '#',
|
||||
'text' => $item['name'],
|
||||
'state' => [
|
||||
'selected' => (in_array($item['api_id'], $apiIds) && !$this->hasChildren($item['api_id']))
|
||||
]
|
||||
];
|
||||
}
|
||||
return helper::jsonEncode($jsTree);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否存在子集
|
||||
* @param $api_id
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function hasChildren($api_id)
|
||||
{
|
||||
foreach (self::getAll() as $item) {
|
||||
if ($item['parent_id'] == $api_id)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\store;
|
||||
|
||||
use app\common\model\store\Menu as MenuModel;
|
||||
|
||||
/**
|
||||
* 商家后台菜单模型
|
||||
* Class Menu
|
||||
* @package app\store\model\store
|
||||
*/
|
||||
class Menu extends MenuModel
|
||||
{
|
||||
// 隐藏的字段
|
||||
protected $hidden = [
|
||||
'action_mark',
|
||||
'sort',
|
||||
'create_time',
|
||||
'update_time'
|
||||
];
|
||||
|
||||
/**
|
||||
* 根据菜单ID集获取列表
|
||||
* @param array $menuIds
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function getListByIds(array $menuIds)
|
||||
{
|
||||
// 菜单列表
|
||||
$list = static::getAll([['menu_id', 'in', $menuIds]]);
|
||||
// 整理菜单绑定的apiID集
|
||||
return (new static)->getTreeData($list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\store;
|
||||
|
||||
use app\common\model\store\MenuApi as MenuApiModel;
|
||||
|
||||
/**
|
||||
* 商家后台用户角色与菜单权限关系表模型
|
||||
* Class MenuApi
|
||||
* @package app\store\model\store
|
||||
*/
|
||||
class MenuApi extends MenuApiModel
|
||||
{
|
||||
/**
|
||||
* 获取指定角色的所有菜单id
|
||||
* @param array $menuIds 菜单ID集
|
||||
* @return array
|
||||
*/
|
||||
public static function getApiIds(array $menuIds)
|
||||
{
|
||||
return (new self)->where('menu_id', 'in', $menuIds)->column('api_id');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\store;
|
||||
|
||||
use app\common\library\helper;
|
||||
use app\common\model\store\Role as RoleModel;
|
||||
use app\store\model\store\RoleMenu as RoleMenuModel;
|
||||
|
||||
/**
|
||||
* 商家用户角色模型
|
||||
* Class Role
|
||||
* @package app\store\model\store
|
||||
*/
|
||||
class Role extends RoleModel
|
||||
{
|
||||
/**
|
||||
* 获取角色列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getList($where = [])
|
||||
{
|
||||
$list = $this->getAll($where);
|
||||
return $this->getTreeData($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有角色
|
||||
* @param array $where
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function getAll($where = [])
|
||||
{
|
||||
// 获取列表数据
|
||||
$list = $this->addHidden(['roleMenu'])
|
||||
->where($where)
|
||||
->with(['roleMenu','storeUser'])
|
||||
->order(['sort' => 'asc', 'create_time' => 'asc'])
|
||||
->select();
|
||||
// 整理角色的菜单ID集
|
||||
return $this->getRoleMenuIds($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 整理菜单的api ID集
|
||||
* @param $list
|
||||
* @return mixed
|
||||
*/
|
||||
private function getRoleMenuIds($list)
|
||||
{
|
||||
foreach ($list as &$item) {
|
||||
if (!empty($item['roleMenu'])) {
|
||||
$item['menuIds'] = helper::getArrayColumn($item['roleMenu'], 'menu_id');
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取树状列表
|
||||
* @param $list
|
||||
* @param int $parentId
|
||||
* @return array
|
||||
*/
|
||||
private function getTreeData(&$list, int $parentId = 0)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($list as $key => $item) {
|
||||
if ($item['parent_id'] == $parentId) {
|
||||
$children = $this->getTreeData($list, $item['role_id']);
|
||||
!empty($children) && $item['children'] = $children;
|
||||
$data[] = $item;
|
||||
unset($list[$key]);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
if (empty($data['menus'])) {
|
||||
$this->error = '菜单权限不能为空,请重新选择';
|
||||
return false;
|
||||
}
|
||||
$this->transaction(function () use ($data) {
|
||||
// 新增角色记录
|
||||
$data['store_id'] = self::$storeId;
|
||||
$this->save($data);
|
||||
// 新增角色菜单关系记录
|
||||
RoleMenuModel::increased((int)$this['role_id'], $data['menus']);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
if (empty($data['menus'])) {
|
||||
$this->error = '菜单权限不能为空,请重新选择';
|
||||
return false;
|
||||
}
|
||||
// 判断上级角色是否为当前子级
|
||||
if ($data['parent_id'] > 0) {
|
||||
// 获取所有上级id集
|
||||
$parentIds = $this->getTopRoleIds($data['parent_id']);
|
||||
if (in_array($this['role_id'], $parentIds)) {
|
||||
$this->error = '上级角色不允许设置为当前子角色';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$this->transaction(function () use ($data) {
|
||||
// 更新角色记录
|
||||
$this->allowField(['role_name', 'parent_id', 'sort'])->save($data);
|
||||
// 更新角色菜单关系记录
|
||||
RoleMenuModel::updates((int)$this['role_id'], $data['menus']);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有上级id集
|
||||
* @param int $roleId
|
||||
* @param null|array $list
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function getTopRoleIds(int $roleId, $list = null)
|
||||
{
|
||||
static $parentIds = [];
|
||||
is_null($list) && $list = $this->getAll();
|
||||
foreach ($list as $item) {
|
||||
if ($item['role_id'] == $roleId && $item['parent_id'] > 0) {
|
||||
$parentIds[] = $item['parent_id'];
|
||||
$this->getTopRoleIds($item['parent_id'], $list);
|
||||
}
|
||||
}
|
||||
return $parentIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
// 判断是否存在下级角色
|
||||
if (static::detail(['parent_id' => $this['role_id']])) {
|
||||
$this->error = '当前角色下存在子角色,不允许删除';
|
||||
return false;
|
||||
}
|
||||
// 判断当前角色下存在用户
|
||||
if (UserRole::isExistsUserByRoleId($this['role_id'])) {
|
||||
$this->error = '当前角色下存在用户,不允许删除';
|
||||
return false;
|
||||
}
|
||||
// 删除对应的菜单关系
|
||||
RoleMenuModel::deleteAll(['role_id' => $this['role_id']]);
|
||||
return $this->delete();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\store;
|
||||
|
||||
use app\common\model\store\RoleMenu as RoleMenuModel;
|
||||
|
||||
/**
|
||||
* 商家后台用户角色与菜单权限关系模型
|
||||
* Class RoleMenu
|
||||
* @package app\store\model\store
|
||||
*/
|
||||
class RoleMenu extends RoleMenuModel
|
||||
{
|
||||
/**
|
||||
* 新增关系记录
|
||||
* @param int $roleId
|
||||
* @param array $menuIds
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increased(int $roleId, array $menuIds)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($menuIds as $menuId) {
|
||||
$data[] = [
|
||||
'role_id' => $roleId,
|
||||
'menu_id' => $menuId,
|
||||
'store_id' => self::$storeId,
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新关系记录
|
||||
* @param int $roleId
|
||||
* @param array $newMenus
|
||||
* @return array|false
|
||||
*/
|
||||
public static function updates(int $roleId, array $newMenus)
|
||||
{
|
||||
// 已分配的权限集
|
||||
$assignMenuIds = self::getMenuIds([$roleId]);
|
||||
/**
|
||||
* 找出删除的权限
|
||||
* 假如已有的权限集合是A,界面传递过得权限集合是B
|
||||
* 权限集合A当中的某个权限不在权限集合B当中,就应该删除
|
||||
* 使用 array_diff() 计算补集
|
||||
*/
|
||||
if ($deleteMenuIds = array_diff($assignMenuIds, $newMenus)) {
|
||||
self::deleteAll([
|
||||
['role_id', '=', $roleId],
|
||||
['menu_id', 'in', $deleteMenuIds]
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* 找出添加的权限
|
||||
* 假如已有的权限集合是A,界面传递过得权限集合是B
|
||||
* 权限集合B当中的某个权限不在权限集合A当中,就应该添加
|
||||
* 使用 array_diff() 计算补集
|
||||
*/
|
||||
$newMenuIds = array_diff($newMenus, $assignMenuIds);
|
||||
$data = [];
|
||||
foreach ($newMenuIds as $menuId) {
|
||||
$data[] = [
|
||||
'role_id' => $roleId,
|
||||
'menu_id' => $menuId,
|
||||
'store_id' => self::$storeId,
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定角色的所有菜单id
|
||||
* @param array $roleIds 角色ID集
|
||||
* @return array
|
||||
*/
|
||||
public static function getMenuIds(array $roleIds): array
|
||||
{
|
||||
return (new self)->where('role_id', 'in', $roleIds)->column('menu_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,390 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\store;
|
||||
|
||||
use app\common\library\helper;
|
||||
use app\common\model\store\User as StoreUserModel;
|
||||
use app\admin\service\store\User as StoreUserService;
|
||||
use app\store\model\Merchant;
|
||||
use app\store\model\Order as OrderModel;
|
||||
|
||||
/**
|
||||
* 商家用户模型
|
||||
* Class StoreUser
|
||||
* @package app\store\model
|
||||
*/
|
||||
class User extends StoreUserModel
|
||||
{
|
||||
/**
|
||||
* 隐藏的字段
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
];
|
||||
|
||||
// 用户登录token
|
||||
private $token;
|
||||
|
||||
/**
|
||||
* 商家用户登录
|
||||
* @param array $data
|
||||
* @return array|bool|null|\think\Model
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function login(array $data)
|
||||
{
|
||||
// 验证用户名密码是否正确
|
||||
if (!$userInfo = $this->getUserInfoByLogin($data)) {
|
||||
return false;
|
||||
}
|
||||
// 验证商城状态是否正常
|
||||
if (empty($userInfo['store']) || $userInfo['store']['is_delete']) {
|
||||
$this->error = '登录失败, 未找到当前商城信息';
|
||||
return false;
|
||||
}
|
||||
if ($userInfo['store']['is_recycle']) {
|
||||
$this->error = '登录失败, 当前商城已删除';
|
||||
return false;
|
||||
}
|
||||
// 记录登录状态, 并记录token
|
||||
$this->token = StoreUserService::login($userInfo->toArray());
|
||||
return $userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回生成的token
|
||||
* @return mixed
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录用户信息
|
||||
* @param array $data
|
||||
* @return array|bool|null|\think\Model
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function getUserInfoByLogin(array $data)
|
||||
{
|
||||
// 用户信息
|
||||
$useInfo = static::withoutGlobalScope()
|
||||
->with(['store'])
|
||||
->where('user_name', '=', trim($data['username']))
|
||||
->where('is_delete', '=', 0)
|
||||
->find();
|
||||
if (empty($useInfo) || $useInfo['is_delete']) {
|
||||
$this->error = '登录失败, 该用户不存在或已删除';
|
||||
return false;
|
||||
}
|
||||
// 验证密码是否正确
|
||||
if (!password_verify($data['password'], $useInfo['password'])) {
|
||||
$this->error = '登录失败, 用户名或密码错误';
|
||||
return false;
|
||||
}
|
||||
return $useInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
* @param array $param
|
||||
* @param array $user
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList($param = [], $user = [])
|
||||
{
|
||||
// 查询模型
|
||||
$query = $this->getNewQuery();
|
||||
// 查询参数
|
||||
$params = $this->setQueryDefaultValue($param, ['search' => '']);
|
||||
// 关键词搜索
|
||||
!empty($params['search']) && $query->where('user_name|real_name', 'like', "%{$params['search']}%");
|
||||
$filter = [];
|
||||
if($user['is_super'] == 0) {
|
||||
$filter[] = ['store_user_id', 'in', self::getScope($user)];
|
||||
}
|
||||
// 查询列表记录
|
||||
$list = $query->with(['role'])
|
||||
->where('is_delete', '=', '0')
|
||||
->where($filter)
|
||||
->order(['sort' => 'asc', 'create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
// 整理所有角色id
|
||||
foreach ($list as &$item) {
|
||||
$item['roleIds'] = helper::getArrayColumn($item['role'], 'role_id');
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param array $data
|
||||
* @param array $user
|
||||
* @return bool
|
||||
*/
|
||||
public function add(array $data,array $user)
|
||||
{
|
||||
$data['user_name'] = strtolower($data['user_name']);
|
||||
if (self::checkExist($data['user_name'])) {
|
||||
$this->error = '用户名已存在';
|
||||
return false;
|
||||
}
|
||||
if ($data['password'] !== $data['password_confirm']) {
|
||||
$this->error = '确认密码不正确';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['roles'])) {
|
||||
$this->error = '请选择所属角色';
|
||||
return false;
|
||||
}
|
||||
/*if (empty($data['merchant_id']) && $user['is_super'] == 0) {
|
||||
$this->error = '请选择商户';
|
||||
return false;
|
||||
}*/
|
||||
$data['merchant_id'] = isset($data['merchant_id'])?$data['merchant_id']:0;
|
||||
// 整理数据
|
||||
$data['password'] = encryption_hash($data['password']);
|
||||
$data['store_id'] = self::$storeId;
|
||||
$data['is_super'] = 0;
|
||||
//账号层级
|
||||
if($data['merchant_id'] > 0) {
|
||||
$merchant = Merchant::detail($data['merchant_id']);
|
||||
$data['level'] = $merchant['level'] ?: 1;
|
||||
}
|
||||
$data['parent_id'] = $user['store_user_id'];
|
||||
// 事务处理
|
||||
$this->transaction(function () use ($data) {
|
||||
// 新增管理员记录
|
||||
$this->save($data);
|
||||
// 新增角色关系记录
|
||||
UserRole::increased((int)$this['store_user_id'], $data['roles']);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @param array $user
|
||||
* @return bool
|
||||
*/
|
||||
public function edit(array $data,$user = [])
|
||||
{
|
||||
$data['user_name'] = strtolower($data['user_name']);
|
||||
if ($this['user_name'] !== $data['user_name']
|
||||
&& self::checkExist($data['user_name'])) {
|
||||
$this->error = '用户名已存在';
|
||||
return false;
|
||||
}
|
||||
if (!empty($data['password']) && ($data['password'] !== $data['password_confirm'])) {
|
||||
$this->error = '确认密码不正确';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['roles']) && !$this['is_super'] && $user['store_user_id'] != $this['store_user_id']) {
|
||||
$this->error = '请选择所属角色';
|
||||
return false;
|
||||
}
|
||||
if (!empty($data['password'])) {
|
||||
$data['password'] = encryption_hash($data['password']);
|
||||
} else {
|
||||
unset($data['password']);
|
||||
}
|
||||
$data['merchant_id'] = isset($data['merchant_id'])?$data['merchant_id']:0;
|
||||
if($data['merchant_id'] > 0) {
|
||||
$merchant = Merchant::detail($data['merchant_id']);
|
||||
$data['level'] = $merchant['level'] ?: 1;
|
||||
}
|
||||
$this->transaction(function () use ($data,$user) {
|
||||
// 更新管理员记录
|
||||
$this->save($data);
|
||||
// 更新角色关系记录
|
||||
!$this['is_super'] && $user['store_user_id'] != $this['store_user_id'] && UserRole::updates((int)$this['store_user_id'], $data['roles']);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 软删除
|
||||
* @return false|int
|
||||
*/
|
||||
public function setDelete()
|
||||
{
|
||||
if ($this['is_super']) {
|
||||
$this->error = '超级管理员不允许删除';
|
||||
return false;
|
||||
}
|
||||
return $this->transaction(function () {
|
||||
// 删除对应的角色关系
|
||||
UserRole::deleteAll([['store_user_id', '=', (int)$this['store_user_id']]]);
|
||||
return $this->save(['is_delete' => 1]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新当前管理员信息
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function renew(array $data)
|
||||
{
|
||||
if (!empty($data['password']) && ($data['password'] !== $data['password_confirm'])) {
|
||||
$this->error = '确认密码不正确';
|
||||
return false;
|
||||
}
|
||||
if ($this['user_name'] !== $data['user_name']
|
||||
&& self::checkExist($data['user_name'])) {
|
||||
$this->error = '用户名已存在';
|
||||
return false;
|
||||
}
|
||||
!empty($data['password']) && $data['password'] = encryption_hash($data['password']);
|
||||
// 更新管理员信息
|
||||
if ($this->save($data) === false) {
|
||||
return false;
|
||||
}
|
||||
// 更新登录状态
|
||||
StoreUserService::update($this->toArray());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询权限范围
|
||||
* @param array $user
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getScope($user)
|
||||
{
|
||||
$model = new static;
|
||||
$filter = [];
|
||||
// if(isset($user['level'])) {
|
||||
// switch ($user['level']) {
|
||||
// //总账户查询所有人,如果是一级账户则查询所有下级和自己,
|
||||
// case 2:
|
||||
// /*$whereOr = ['parent_id' => $user['store_user_id'], 'store_user_id' => $user['store_user_id']];
|
||||
// $model->where(function ($query) use ($whereOr) {
|
||||
// $query->whereOr($whereOr);
|
||||
// });*/
|
||||
// $filter[] = ['parent_id|store_user_id', '=', $user['store_user_id']];
|
||||
// break;
|
||||
// case 3:
|
||||
// $filter[] = ['store_user_id', '=', $user['store_user_id']];
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
if($user['level'] > 1){
|
||||
$ids = [$user['store_user_id']];
|
||||
$ids = array_merge($ids, self::getBelowAll(['where'=>['parent_id', '=', $user['store_user_id']]]));
|
||||
$filter[] = ['store_user_id', 'in', $ids];
|
||||
}
|
||||
$result = $model->order(['create_time' => 'asc'])->where($filter)->field('store_user_id')->select()->toArray();
|
||||
return empty($result)?[]:array_column($result,'store_user_id');
|
||||
}
|
||||
|
||||
/** store_user_id
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public static function getBelowAll($data)
|
||||
{
|
||||
// 结果
|
||||
$model = new static;
|
||||
$result = $model->order(['create_time' => 'asc'])->where([$data['where']])->field('store_user_id')->select()->toArray();
|
||||
$temp = [];
|
||||
if (is_array($result) && count($result)>0) {
|
||||
foreach ($result as $value) {
|
||||
$temp[] = $value['store_user_id'];
|
||||
$temp = array_merge($temp,self::getBelowAll(['where'=>['parent_id', '=', $value['store_user_id']]]));
|
||||
}
|
||||
}
|
||||
return $temp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断是否已到当日收款上限
|
||||
* @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(['store_user_id'=>$order['store_user_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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户数据统计
|
||||
* @param $user
|
||||
* @param $get
|
||||
* @return \think\Paginator
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getUserStatistics($user,$get = [])
|
||||
{
|
||||
switch ($user['level'])
|
||||
{
|
||||
//总账户查询所有人,如果是一级账户则查询所有下级和自己,
|
||||
case 2:
|
||||
$whereOr = ['a.parent_id' => $user['store_user_id'],'a.store_user_id' => $user['store_user_id']];
|
||||
$this->where(function($query) use ($whereOr){
|
||||
$query->whereOr($whereOr);
|
||||
});
|
||||
break;
|
||||
case 3:
|
||||
$this->where('a.store_user_id', '=', $user['store_user_id']);
|
||||
break;
|
||||
}
|
||||
if(isset($get['user_name'])){
|
||||
$this->where('a.user_name', 'like', '%'.$get['user_name'].'%');
|
||||
}
|
||||
$and = "";
|
||||
if(isset($get['start_time'])){
|
||||
$and .= " and create_time >= '".strtotime($get['start_time'])."' ";
|
||||
}
|
||||
if(isset($get['end_time'])){
|
||||
$and .= " and create_time < '".strtotime($get['end_time'].' 23:59:59')."' ";
|
||||
}
|
||||
return $this->alias('a')
|
||||
->join([
|
||||
['yoshop_store_user b', 'a.parent_id=b.store_user_id','LEFT'],
|
||||
])
|
||||
->where('a.is_delete', '=', '0')
|
||||
->field('a.*, b.user_name as parent_user,(select IFNULL(sum(total_price),0) from yoshop_order where store_user_id = a.store_user_id and order_status = 20 '.$and.') as amount')
|
||||
->order(['a.create_time' => 'desc'])
|
||||
->paginate(15, false, [
|
||||
'query' => \request()->request()
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\store;
|
||||
|
||||
use app\common\model\store\UserRole as UserRoleModel;
|
||||
|
||||
/**
|
||||
* 商家用户角色模型
|
||||
* Class UserRole
|
||||
* @package app\store\model\store
|
||||
*/
|
||||
class UserRole extends UserRoleModel
|
||||
{
|
||||
/**
|
||||
* 新增关系记录
|
||||
* @param int $storeUserId
|
||||
* @param array $roleIds
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increased(int $storeUserId, array $roleIds)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($roleIds as $roleId) {
|
||||
$data[] = [
|
||||
'store_user_id' => $storeUserId,
|
||||
'role_id' => $roleId,
|
||||
'store_id' => self::$storeId,
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新关系记录
|
||||
* @param int $storeUserId
|
||||
* @param array $newRoles 新的角色集
|
||||
* @return array|false
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function updates(int $storeUserId, array $newRoles)
|
||||
{
|
||||
// 已分配的角色集
|
||||
$assignRoleIds = self::getRoleIdsByUserId($storeUserId);
|
||||
// 找出删除的角色
|
||||
$deleteRoleIds = array_diff($assignRoleIds, $newRoles);
|
||||
if (!empty($deleteRoleIds)) {
|
||||
self::deleteAll([
|
||||
['store_user_id', '=', $storeUserId],
|
||||
['role_id', 'in', $deleteRoleIds]
|
||||
]);
|
||||
}
|
||||
// 找出添加的角色
|
||||
$newRoleIds = array_diff($newRoles, $assignRoleIds);
|
||||
$data = [];
|
||||
foreach ($newRoleIds as $roleId) {
|
||||
$data[] = [
|
||||
'store_user_id' => $storeUserId,
|
||||
'role_id' => $roleId,
|
||||
'store_id' => self::$storeId,
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定管理员的所有角色id
|
||||
* @param int $storeUserId
|
||||
* @return array
|
||||
*/
|
||||
public static function getRoleIdsByUserId(int $storeUserId)
|
||||
{
|
||||
return (new static)->where('store_user_id', '=', $storeUserId)->column('role_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色ID判断是否存在用户
|
||||
* @param int $roleId
|
||||
* @return bool
|
||||
*/
|
||||
public static function isExistsUserByRoleId(int $roleId)
|
||||
{
|
||||
return !!(new static)->where('role_id', '=', $roleId)->count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\user;
|
||||
|
||||
use app\common\model\user\BalanceLog as BalanceLogModel;
|
||||
|
||||
/**
|
||||
* 用户余额变动明细模型
|
||||
* Class BalanceLog
|
||||
* @package app\store\model\user
|
||||
*/
|
||||
class BalanceLog extends BalanceLogModel
|
||||
{
|
||||
/**
|
||||
* 获取余额变动明细列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 设置查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取列表数据
|
||||
return $this->with(['user.avatar'])
|
||||
->alias('log')
|
||||
->field('log.*')
|
||||
->where($filter)
|
||||
->join('user', 'user.user_id = log.user_id')
|
||||
->order(['log.create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param): array
|
||||
{
|
||||
// 设置默认的检索数据
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'user_id' => 0, // 用户ID
|
||||
'search' => '', // 用户昵称
|
||||
'scene' => 0, // 余额变动场景
|
||||
'betweenTime' => [] // 起止时间
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 用户ID
|
||||
$params['user_id'] > 0 && $filter[] = ['log.user_id', '=', $params['user_id']];
|
||||
// 用户昵称
|
||||
!empty($params['search']) && $filter[] = ['user.nick_name', 'like', "%{$params['search']}%"];
|
||||
// 余额变动场景
|
||||
$params['scene'] > 0 && $filter[] = ['log.scene', '=', (int)$params['scene']];
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['log.create_time', '>=', $times['start_time']];
|
||||
$filter[] = ['log.create_time', '<', $times['end_time'] + 86400];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\user;
|
||||
|
||||
use app\common\model\user\Grade as GradeModel;
|
||||
|
||||
use app\store\model\User as UserModel;
|
||||
|
||||
/**
|
||||
* 用户会员等级模型
|
||||
* Class Grade
|
||||
* @package app\store\model\user
|
||||
*/
|
||||
class Grade extends GradeModel
|
||||
{
|
||||
// 表单验证场景: 新增
|
||||
const FORM_SCENE_ADD = 'add';
|
||||
|
||||
// 表单验证场景: 编辑
|
||||
const FORM_SCENE_EDIT = 'edit';
|
||||
|
||||
/**
|
||||
* 获取全部记录
|
||||
* @param array $param
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAll(array $param)
|
||||
{
|
||||
return $this->where($this->getFilter($param))
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['weight', $this->getPk()])
|
||||
->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表记录
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList(array $param)
|
||||
{
|
||||
return $this->where($this->getFilter($param))
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['weight', $this->getPk()])
|
||||
->paginate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param)
|
||||
{
|
||||
// 默认查询条件
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'status' => -1 // 状态(1启用 0禁用 -1全部)
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = $params['status'] > -1 ? ['status' => (int)$params['status']] : [];
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param $data
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
if (!$this->validateForm($data, self::FORM_SCENE_ADD)) {
|
||||
return false;
|
||||
}
|
||||
$data['store_id'] = self::$storeId;
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑记录
|
||||
* @param $data
|
||||
* @return false|int
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
if (!$this->validateForm($data, self::FORM_SCENE_EDIT)) {
|
||||
return false;
|
||||
}
|
||||
return $this->save($data) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 软删除
|
||||
* @return false|int
|
||||
*/
|
||||
public function setDelete()
|
||||
{
|
||||
// 判断该等级下是否存在会员
|
||||
if (UserModel::checkExistByGradeId((int)$this['grade_id'])) {
|
||||
$this->error = '该会员等级下存在用户,不允许删除';
|
||||
return false;
|
||||
}
|
||||
return $this->save(['is_delete' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单验证
|
||||
* @param $data
|
||||
* @param string $scene
|
||||
* @return bool
|
||||
*/
|
||||
private function validateForm(array $data, string $scene = self::FORM_SCENE_ADD)
|
||||
{
|
||||
if ($scene === self::FORM_SCENE_ADD) {
|
||||
// 需要判断等级权重是否已存在
|
||||
if (self::checkExistByWeight($data['weight'])) {
|
||||
$this->error = '等级权重已存在';
|
||||
return false;
|
||||
}
|
||||
} elseif ($scene === self::FORM_SCENE_EDIT) {
|
||||
// 需要判断等级权重是否已存在
|
||||
if (self::checkExistByWeight($data['weight'], $this['grade_id'])) {
|
||||
$this->error = '等级权重已存在';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\user;
|
||||
|
||||
use app\common\model\user\GradeLog as GradeLogModel;
|
||||
|
||||
/**
|
||||
* 用户会员等级变更记录模型
|
||||
* Class GradeLog
|
||||
* @package app\store\model\user
|
||||
*/
|
||||
class GradeLog extends GradeLogModel
|
||||
{
|
||||
/**
|
||||
* 新增变更记录
|
||||
* @param $data
|
||||
* @return int
|
||||
*/
|
||||
public function record($data)
|
||||
{
|
||||
return $this->records([$data]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\user;
|
||||
|
||||
use app\common\model\user\PointsLog as PointsLogModel;
|
||||
|
||||
/**
|
||||
* 用户余额变动明细模型
|
||||
* Class PointsLog
|
||||
* @package app\store\model\user
|
||||
*/
|
||||
class PointsLog extends PointsLogModel
|
||||
{
|
||||
/**
|
||||
* 获取积分明细列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
*/
|
||||
public function getList($param = [])
|
||||
{
|
||||
// 设置查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取列表数据
|
||||
return $this->with(['user.avatar'])
|
||||
->alias('m')
|
||||
->field('m.*')
|
||||
->where($filter)
|
||||
->join('user', 'user.user_id = m.user_id')
|
||||
->order(['m.create_time' => 'desc', $this->getPk()])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param): array
|
||||
{
|
||||
// 设置默认的检索数据
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'userId' => 0, // 会员ID
|
||||
'search' => '', // 搜索内容
|
||||
'betweenTime' => [], // 起止时间
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 用户ID
|
||||
$params['userId'] > 0 && $filter[] = ['m.user_id', '=', $params['userId']];
|
||||
// 搜索内容: 用户昵称
|
||||
!empty($params['search']) && $filter[] = ['user.nick_name', 'like', "%{$params['search']}%"];
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['m.create_time', '>=', $times['start_time']];
|
||||
$filter[] = ['m.create_time', '<', $times['end_time'] + 86400];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\wxapp;
|
||||
|
||||
use think\facade\Cache;
|
||||
use app\common\model\wxapp\Setting as SettingModel;
|
||||
|
||||
/**
|
||||
* 微信小程序设置模型
|
||||
* Class Setting
|
||||
* @package app\store\model\wxapp
|
||||
*/
|
||||
class Setting extends SettingModel
|
||||
{
|
||||
/**
|
||||
* 设置项描述
|
||||
* @var array
|
||||
*/
|
||||
private $describe = [
|
||||
'basic' => '基础设置',
|
||||
];
|
||||
|
||||
/**
|
||||
* 更新系统设置
|
||||
* @param string $key
|
||||
* @param array $values
|
||||
* @return bool
|
||||
*/
|
||||
public function edit(string $key, array $values): bool
|
||||
{
|
||||
$model = self::detail($key) ?: $this;
|
||||
// 删除小程序设置缓存
|
||||
Cache::delete('wxapp_setting_' . self::$storeId);
|
||||
// 写入cert证书文件
|
||||
$this->writeCertPemFiles($values['cert_pem'], $values['key_pem']);
|
||||
// 保存设置
|
||||
return $model->save([
|
||||
'key' => $key,
|
||||
'describe' => $this->describe[$key],
|
||||
'values' => $values,
|
||||
'update_time' => time(),
|
||||
'store_id' => self::$storeId,
|
||||
]) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入cert证书文件
|
||||
* @param string $certPem
|
||||
* @param string $keyPem
|
||||
* @return void
|
||||
*/
|
||||
private function writeCertPemFiles(string $certPem, string $keyPem): void
|
||||
{
|
||||
if (empty($certPem) && empty($keyPem)) {
|
||||
return;
|
||||
}
|
||||
// 证书目录
|
||||
$filePath = base_path() . 'common/library/wechat/cert/' . self::$storeId . '/';
|
||||
// 目录不存在则自动创建
|
||||
if (!is_dir($filePath)) {
|
||||
mkdir($filePath, 0755, true);
|
||||
}
|
||||
// 写入cert.pem文件
|
||||
if (!empty($certPem)) {
|
||||
file_put_contents($filePath . 'cert.pem', $certPem);
|
||||
}
|
||||
// 写入key.pem文件
|
||||
if (!empty($keyPem)) {
|
||||
file_put_contents($filePath . 'key.pem', $keyPem);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user