更新
This commit is contained in:
parent
01ddd9d11f
commit
50c8ad65e5
713
app/common/dao/store/product/SupplyProductDao.php
Normal file
713
app/common/dao/store/product/SupplyProductDao.php
Normal file
@ -0,0 +1,713 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\SupplyProduct as model;
|
||||
use app\common\repositories\store\product\SupplySpuRepository;
|
||||
// use app\common\repositories\store\StoreCategoryRepository;
|
||||
use think\db\BaseQuery;
|
||||
use think\db\exception\DbException;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
|
||||
class SupplyProductDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return model::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*/
|
||||
public function createAttr(int $id, array $data)
|
||||
{
|
||||
($this->getModel()::withTrashed()->find($id))->attr()->saveAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*/
|
||||
public function createAttrValue(int $id, array $data)
|
||||
{
|
||||
($this->getModel()::withTrashed()->find($id))->attrValue()->saveAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*/
|
||||
public function createContent(int $id, array $data)
|
||||
{
|
||||
($this->getModel()::withTrashed()->find($id))->content()->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param int $merId
|
||||
* @param $field
|
||||
* @param $value
|
||||
* @param null $except
|
||||
* @return bool
|
||||
*/
|
||||
public function merFieldExists(?int $merId, $field, $value, $except = null)
|
||||
{
|
||||
return model::withTrashed()->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->where($field, $value)->count() > 0;
|
||||
}
|
||||
|
||||
public function apiFieldExists(int $merId, $field, $value, $except = null)
|
||||
{
|
||||
return ($this->getModel())::getDB()->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->where(['status' => 1])->where($field, $value)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $merId
|
||||
* @param int $productId
|
||||
* @return bool
|
||||
* @author Qinii
|
||||
*/
|
||||
public function getDeleteExists(int $merId, int $productId)
|
||||
{
|
||||
return ($this->getModel())::onlyTrashed()->where('mer_id', $merId)->where($this->getPk(), $productId)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/11
|
||||
* @param int $merId
|
||||
* @param array $where
|
||||
* @return mixed
|
||||
*/
|
||||
public function search(?int $merId, array $where)
|
||||
{
|
||||
|
||||
$keyArray = $whereArr = [];
|
||||
$out = ['soft', 'us_status', 'mer_labels', 'sys_labels', 'order', 'hot_type', 'is_action'];
|
||||
foreach ($where as $key => $item) {
|
||||
if ($item !== '' && !in_array($key, $out)) {
|
||||
$keyArray[] = $key;
|
||||
$whereArr[$key] = $item;
|
||||
}
|
||||
}
|
||||
$query = isset($where['soft']) ? model::onlyTrashed()->alias('Product')->where('delete', 0) : model::alias('Product');
|
||||
if (isset($where['is_trader']) && $where['is_trader'] !== '') {
|
||||
$query->hasWhere('merchant', function ($query) use ($where) {
|
||||
$query->where('is_trader', $where['is_trader']);
|
||||
});
|
||||
}
|
||||
$query->withSearch($keyArray, $whereArr)->Join('StoreSpu U', 'Product.product_id = U.product_id')->where('U.product_type', $where['product_type'] ?? 0);
|
||||
|
||||
$query->when(($merId !== null), function ($query) use ($merId) {
|
||||
$query->where('Product.mer_id', $merId);
|
||||
})
|
||||
->when(isset($where['hot_type']) && $where['hot_type'] !== '', function ($query) use ($where) {
|
||||
if ($where['hot_type'] == 'new')
|
||||
$query->where('is_new', 1);
|
||||
else if ($where['hot_type'] == 'hot')
|
||||
$query->where('is_hot', 1);
|
||||
else if ($where['hot_type'] == 'best')
|
||||
$query->where('is_best', 1);
|
||||
else if ($where['hot_type'] == 'good')
|
||||
$query->where('is_benefit', 1);
|
||||
})
|
||||
->when(isset($where['us_status']) && $where['us_status'] !== '', function ($query) use ($where) {
|
||||
if ($where['us_status'] == 0) {
|
||||
$query->where('Product.is_show', 0)->where('Product.is_used', 1)->where('Product.status', 1);
|
||||
}
|
||||
if ($where['us_status'] == 1) {
|
||||
$query->where('Product.is_show', 1)->where('Product.is_used', 1)->where('Product.status', 1);
|
||||
}
|
||||
if ($where['us_status'] == -1) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('Product.is_used', 0)->whereOr('Product.status', '<>', 1);
|
||||
});
|
||||
}
|
||||
})
|
||||
->when(isset($where['mer_labels']) && $where['mer_labels'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('U.mer_labels', "%,{$where['mer_labels']},%");
|
||||
})
|
||||
//活动商品列表
|
||||
->when(isset($where['is_action']) && $where['is_action'] !== '', function ($query) use ($where) {
|
||||
$query->where('type', '<>', 2);
|
||||
})
|
||||
->when(isset($where['sys_labels']) && $where['sys_labels'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('U.sys_labels', "%,{$where['sys_labels']},%");
|
||||
})
|
||||
->when(isset($where['svip_price_type']) && $where['svip_price_type'] !== '', function ($query) use ($where) {
|
||||
$query->where('Product.svip_price_type', $where['svip_price_type']);
|
||||
})
|
||||
->when(isset($where['order']), function ($query) use ($where, $merId) {
|
||||
if (in_array($where['order'], ['is_new', 'price_asc', 'price_desc', 'rate', 'sales'])) {
|
||||
if ($where['order'] == 'price_asc') {
|
||||
$where['order'] = 'price ASC';
|
||||
} else if ($where['order'] == 'price_desc') {
|
||||
$where['order'] = 'price DESC';
|
||||
} else {
|
||||
$where['order'] = $where['order'] . ' DESC';
|
||||
}
|
||||
$query->order($where['order'] . ',rank DESC ,create_time DESC ');
|
||||
} else if ($where['order'] !== '') {
|
||||
$query->order('U.' . $where['order'] . ' DESC,U.create_time DESC');
|
||||
} else {
|
||||
$query->order('U.create_time DESC');
|
||||
}
|
||||
})
|
||||
->when(isset($where['star']), function ($query) use ($where) {
|
||||
$query->when($where['star'] !== '', function ($query) use ($where) {
|
||||
$query->where('U.star', $where['star']);
|
||||
});
|
||||
$query->order('U.star DESC,U.rank DESC,Product.create_time DESC');
|
||||
})
|
||||
->when(isset($where['is_good']) && $where['is_good'] !== '', function ($query) use ($where) {
|
||||
$query->where('Product.is_good', $where['is_good']);
|
||||
});
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param array $where
|
||||
* @return BaseQuery
|
||||
* @author Qinii
|
||||
* @day 2020-08-04
|
||||
*/
|
||||
public function seckillSearch(array $where)
|
||||
{
|
||||
$query = model::hasWhere('seckillActive', function ($query) use ($where) {
|
||||
$query->where('status', 1);
|
||||
$query->whereTime('start_day', '<=', $where['day'])->whereTime('end_day', '>=', $where['day']);
|
||||
$query->where('start_time', '<=', $where['start_time'])
|
||||
->where('end_time', '>', $where['start_time'])
|
||||
->where('end_time', '<=', $where['end_time']);
|
||||
});
|
||||
$query->where([
|
||||
'Product.is_show' => 1,
|
||||
'Product.status' => 1,
|
||||
'Product.is_used' => 1,
|
||||
'Product.mer_status' => 1,
|
||||
'Product.product_type' => 1,
|
||||
'Product.is_gift_bag' => 0,
|
||||
])
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('Product.mer_id', $where['mer_id']);
|
||||
})
|
||||
->when(isset($where['star']), function ($query) use ($where) {
|
||||
$query->Join('StoreSpu U', 'Product.product_id = U.product_id')->where('U.product_type', 1);
|
||||
$query->when($where['star'] !== '', function ($query) use ($where) {
|
||||
$query->where('U.star', $where['star']);
|
||||
});
|
||||
$query->order('U.star DESC,U.rank DESC');
|
||||
});
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/18
|
||||
* @param int $id
|
||||
* @param bool $soft
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function delete(int $id, $soft = false)
|
||||
{
|
||||
if ($soft) {
|
||||
(($this->getModel())::onlyTrashed()->find($id))->force()->delete();
|
||||
} else {
|
||||
$this->getModel()::where($this->getPk(), $id)->update(['is_del' => 1]);
|
||||
}
|
||||
app()->make(SupplySpuRepository::class)->getSearch(['product_id' => $id])->update(['is_del' => 1, 'status' => 0]);
|
||||
event('product.delete', compact('id'));
|
||||
}
|
||||
|
||||
public function destory(int $id)
|
||||
{
|
||||
try {
|
||||
$this->getModel()::withTrashed()->where('product_id', $id)->update(['delete' => 1]);
|
||||
app()->make(SupplySpuRepository::class)->getSearch(['product_id' => $id])->delete();
|
||||
event('product.delete', compact('id'));
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2020-07-03
|
||||
*/
|
||||
public function restore($id)
|
||||
{
|
||||
$res = ($this->getModel())::onlyTrashed()->find($id);
|
||||
app()->make(SupplySpuRepository::class)->delProduct($id, 0);
|
||||
return $res->restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/18
|
||||
* @param int $id
|
||||
* @param array $status
|
||||
* @return mixed
|
||||
*/
|
||||
public function switchStatus(int $id, array $status)
|
||||
{
|
||||
return ($this->getModel()::getDB())->where($this->getPk(), $id)->update($status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $merId
|
||||
* @param array $productIds
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020/5/26
|
||||
*/
|
||||
public function productIdByImage(int $merId, array $productIds)
|
||||
{
|
||||
return model::getDB()->where('mer_id', $merId)->whereIn('product_id', $productIds)->column('product_id,image');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020/5/30
|
||||
*/
|
||||
public function intersectionKey(array $ids): array
|
||||
{
|
||||
return model::getDB()->whereIn('product_id', $ids)->column('product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/30
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function productIdByMerId($id)
|
||||
{
|
||||
return model::getDB()->where('product_id', $id)->value('mer_id');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param int $desc
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
public function descStock(int $productId, int $desc)
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->update([
|
||||
'stock' => Db::raw('stock-' . $desc),
|
||||
'sales' => Db::raw('sales+' . $desc)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param int $inc
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
public function incStock(int $productId, int $inc)
|
||||
{
|
||||
model::getDB()->where('product_id', $productId)->inc('stock', $inc)->update();
|
||||
model::getDB()->where('product_id', $productId)->where('sales', '>=', $inc)->dec('sales', $inc)->update();
|
||||
}
|
||||
|
||||
public function descSales(int $productId, int $desc)
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->update([
|
||||
'sales' => Db::raw('sales-' . $desc)
|
||||
]);
|
||||
}
|
||||
|
||||
public function incSales(int $productId, int $inc)
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->update([
|
||||
'sales' => Db::raw('sales+' . $inc)
|
||||
]);
|
||||
}
|
||||
|
||||
public function descIntegral(int $productId, $integral_total, $integral_price_total)
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->update([
|
||||
'integral_total' => Db::raw('integral_total-' . $integral_total),
|
||||
'integral_price_total' => Db::raw('integral_price_total-' . $integral_price_total),
|
||||
]);
|
||||
}
|
||||
|
||||
public function incIntegral(int $productId, $integral_total, $integral_price_total)
|
||||
{
|
||||
model::getDB()->where('product_id', $productId)->inc('integral_total', $integral_total)->inc('integral_price_total', $integral_price_total)->update();
|
||||
}
|
||||
|
||||
public function visitProductGroup($date, $merId = null, $limit = 7)
|
||||
{
|
||||
return model::getDB()->alias('A')->leftJoin('UserRelation B', 'A.product_id = B.type_id')
|
||||
->field(Db::raw('count(B.type_id) as total,A.product_id,A.store_name,A.image'))
|
||||
->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'B.create_time');
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('A.mer_id', $merId);
|
||||
})->where('B.type', 1)->group('A.product_id')->limit($limit)->order('total DESC')->select();
|
||||
}
|
||||
|
||||
public function cartProductGroup($date, $merId = null, $limit = 7)
|
||||
{
|
||||
return model::getDB()->alias('A')->leftJoin('StoreCart B', 'A.product_id = B.product_id')
|
||||
->field(Db::raw('sum(B.cart_num) as total,A.product_id,A.store_name,A.image'))
|
||||
->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'B.create_time');
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('A.mer_id', $merId);
|
||||
})->where('B.product_type', 0)->where('B.is_pay', 0)->where('B.is_del', 0)
|
||||
->where('B.is_new', 0)->where('B.is_fail', 0)->group('A.product_id')->limit($limit)->order('total DESC')->select();
|
||||
}
|
||||
|
||||
public function changeMerchantProduct($merId, $data)
|
||||
{
|
||||
($this->getModel()::getDB())->where('mer_id', $merId)->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param int $productId
|
||||
* @author Qinii
|
||||
* @day 2020-07-09
|
||||
*/
|
||||
public function incCareCount(int $productId)
|
||||
{
|
||||
($this->getModel()::getDB())->where($this->getPk(), $productId)->inc('care_count', 1)->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param int $productId
|
||||
* @author Qinii
|
||||
* @day 2020-07-09
|
||||
*/
|
||||
public function decCareCount(array $productId)
|
||||
{
|
||||
($this->getModel()::getDB())->whereIn($this->getPk(), $productId)->where('care_count', '>', 0)->dec('care_count', 1)->update();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO api展示的商品条件
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 2020-08-18
|
||||
*/
|
||||
public function productShow()
|
||||
{
|
||||
return [
|
||||
'is_show' => 1, // 上架
|
||||
'status' => 1, // 审核通过
|
||||
'is_used' => 1, // 显示
|
||||
'product_type' => 0, // 普通商品
|
||||
'mer_status' => 1, //商铺状态正常
|
||||
'is_gift_bag' => 0, //不是礼包
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO api展示的礼包商品条件
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 2020-08-18
|
||||
*/
|
||||
public function bagShow()
|
||||
{
|
||||
return [
|
||||
'is_show' => 1,
|
||||
'status' => 1,
|
||||
'is_used' => 1,
|
||||
'mer_status' => 1,
|
||||
'product_type' => 0,
|
||||
'is_gift_bag' => 1,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO api展示的秒杀商品条件
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 2020-08-18
|
||||
*/
|
||||
public function seckillShow()
|
||||
{
|
||||
return [
|
||||
'is_show' => 1,
|
||||
'status' => 1,
|
||||
'is_used' => 1,
|
||||
'mer_status' => 1,
|
||||
'product_type' => 1,
|
||||
'is_gift_bag' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
public function getProductTypeById(int $productId, ?int $exsistType)
|
||||
{
|
||||
$product_type = $this->getModel()::getDB()
|
||||
->when($exsistType, function ($query) use ($exsistType) {
|
||||
$query->where('product_type', $exsistType);
|
||||
})
|
||||
->where($this->getPk(), $productId)->where('is_del', 0)->value('product_type');
|
||||
return $product_type == 0 ? true : false;
|
||||
}
|
||||
|
||||
public function getFailProduct(int $productId)
|
||||
{
|
||||
return $this->getModel()::withTrashed()->field('product_type,product_id,image,store_name,is_show,status,is_del,unit_name,price,mer_status,is_used,mer_form_id')->find($productId);
|
||||
}
|
||||
|
||||
public function geTrashedtProduct(int $id)
|
||||
{
|
||||
return model::withTrashed()->where($this->getPk(), $id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO 获取各种有效时间内的活动
|
||||
* @param int $productType
|
||||
* @return BaseQuery
|
||||
*
|
||||
* @date 2023/09/22
|
||||
* @author yyw
|
||||
*/
|
||||
public function activitSearch(int $productType)
|
||||
{
|
||||
$query = model::getDB()->alias('P')
|
||||
->where('P.is_del', 0)
|
||||
->where('P.mer_status', 1)
|
||||
->where('P.product_type', $productType);
|
||||
switch ($productType) {
|
||||
case 0:
|
||||
// $query->where('P.is_show',1)
|
||||
// ->where('P.is_used',1)
|
||||
// ->field('product_id,product_type,mer_id,store_name,keyword,price,rank,sort,image,status,temp_id');
|
||||
break;
|
||||
case 1:
|
||||
$query->join('StoreSeckillActive S', 'S.product_id = P.product_id')
|
||||
->field('P.*,S.status,S.seckill_active_id,S.end_time');
|
||||
break;
|
||||
case 2:
|
||||
$query->join('StoreProductPresell R', 'R.product_id = P.product_id')
|
||||
->where('R.is_del', 0)
|
||||
->field('P.*,R.product_presell_id,R.store_name,R.price,R.status,R.is_show,R.product_status,R.action_status');
|
||||
break;
|
||||
case 3:
|
||||
$query->join('StoreProductAssist A', 'A.product_id = P.product_id')
|
||||
->where('A.is_del', 0)
|
||||
->field('P.*,A.product_assist_id,A.store_name,A.status,A.is_show,A.product_status,A.action_status');
|
||||
break;
|
||||
case 4:
|
||||
$query->join('StoreProductGroup G', 'G.product_id = P.product_id')
|
||||
->where('G.is_del', 0)
|
||||
->field('P.*,G.product_group_id,G.price,G.status,G.is_show,G.product_status,G.action_status');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
public function commandChangeProductStatus($data)
|
||||
{
|
||||
$ret = [];
|
||||
|
||||
foreach ($data as $item) {
|
||||
$status = 0;
|
||||
switch ($item['product_type']) {
|
||||
case 0:
|
||||
if ($item['is_show'] && $item['is_used']) $status = 1;
|
||||
$ret[] = [
|
||||
'activity_id' => 0,
|
||||
'product_id' => $item['product_id'],
|
||||
'mer_id' => $item['mer_id'],
|
||||
'keyword' => $item['keyword'],
|
||||
'price' => $item['price'],
|
||||
'rank' => $item['rank'],
|
||||
'sort' => $item['sort'],
|
||||
'image' => $item['image'],
|
||||
'status' => $status,
|
||||
'temp_id' => $item['temp_id'],
|
||||
'store_name' => $item['store_name'],
|
||||
'product_type' => $item['product_type'],
|
||||
];
|
||||
break;
|
||||
case 1:
|
||||
if ($item['is_show'] && $item['is_used'] && $item['status'] && ($item['end_time'] > time())) $status = 1;
|
||||
$ret[] = [
|
||||
'activity_id' => $item['seckill_active_id'],
|
||||
'product_id' => $item['product_id'],
|
||||
'mer_id' => $item['mer_id'],
|
||||
'keyword' => $item['keyword'],
|
||||
'price' => $item['price'],
|
||||
'rank' => $item['rank'],
|
||||
'sort' => $item['sort'],
|
||||
'image' => $item['image'],
|
||||
'status' => $status,
|
||||
'temp_id' => $item['temp_id'],
|
||||
'store_name' => $item['store_name'],
|
||||
'product_type' => $item['product_type'],
|
||||
];
|
||||
break;
|
||||
case 2:
|
||||
if ($item['is_show'] && $item['action_status'] && $item['status'] && $item['product_status']) $status = 1;
|
||||
$ret[] = [
|
||||
'activity_id' => $item['product_presell_id'],
|
||||
'product_id' => $item['product_id'],
|
||||
'mer_id' => $item['mer_id'],
|
||||
'keyword' => $item['keyword'],
|
||||
'price' => $item['price'],
|
||||
'rank' => $item['rank'],
|
||||
'sort' => $item['sort'],
|
||||
'image' => $item['image'],
|
||||
'status' => $status,
|
||||
'temp_id' => $item['temp_id'],
|
||||
'store_name' => $item['store_name'],
|
||||
'product_type' => $item['product_type'],
|
||||
];
|
||||
break;
|
||||
case 3:
|
||||
if ($item['is_show'] && $item['action_status'] && $item['status'] && $item['product_status']) $status = 1;
|
||||
$ret[] = [
|
||||
'activity_id' => $item['product_assist_id'],
|
||||
'product_id' => $item['product_id'],
|
||||
'mer_id' => $item['mer_id'],
|
||||
'keyword' => $item['keyword'],
|
||||
'price' => $item['price'],
|
||||
'rank' => $item['rank'],
|
||||
'sort' => $item['sort'],
|
||||
'image' => $item['image'],
|
||||
'status' => $status,
|
||||
'temp_id' => $item['temp_id'],
|
||||
'store_name' => $item['store_name'],
|
||||
'product_type' => $item['product_type'],
|
||||
];
|
||||
break;
|
||||
case 4:
|
||||
if ($item['is_show'] && $item['action_status'] && $item['status'] && $item['product_status']) $status = 1;
|
||||
$ret[] = [
|
||||
'activity_id' => $item['product_group_id'],
|
||||
'product_id' => $item['product_id'],
|
||||
'mer_id' => $item['mer_id'],
|
||||
'keyword' => $item['keyword'],
|
||||
'price' => $item['price'],
|
||||
'rank' => $item['rank'],
|
||||
'sort' => $item['sort'],
|
||||
'image' => $item['image'],
|
||||
'status' => $status,
|
||||
'temp_id' => $item['temp_id'],
|
||||
'store_name' => $item['store_name'],
|
||||
'product_type' => $item['product_type'],
|
||||
];
|
||||
break;
|
||||
default:
|
||||
if ($item['is_show'] && $item['is_used']) $status = 1;
|
||||
$ret[] = [
|
||||
'activity_id' => 0,
|
||||
'product_id' => $item['product_id'],
|
||||
'mer_id' => $item['mer_id'],
|
||||
'keyword' => $item['keyword'],
|
||||
'price' => $item['price'],
|
||||
'rank' => $item['rank'],
|
||||
'sort' => $item['sort'],
|
||||
'image' => $item['image'],
|
||||
'status' => $status,
|
||||
'temp_id' => $item['temp_id'],
|
||||
'store_name' => $item['store_name'],
|
||||
'product_type' => $item['product_type'],
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 软删除商户的所有商品
|
||||
* @param $merId
|
||||
* @author Qinii
|
||||
* @day 5/15/21
|
||||
*/
|
||||
public function clearProduct($merId)
|
||||
{
|
||||
$this->getModel()::withTrashed()->where('mer_id', $merId)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取好物推荐列表
|
||||
* @param array|null $good_ids
|
||||
* @param $is_mer
|
||||
* @return array|mixed
|
||||
*
|
||||
* @date 2023/10/30
|
||||
* @author yyw
|
||||
*/
|
||||
public function getGoodList(array $good_ids, int $merId, $is_show = true)
|
||||
{
|
||||
if (empty($good_ids) && !$is_show) return [];
|
||||
$filed = 'product_id,image,store_name,price,create_time,is_gift_bag,is_good,is_show,mer_id,sales,status';
|
||||
$where = [];
|
||||
$limit = 30;
|
||||
if ($is_show) {
|
||||
$where = $this->productShow();
|
||||
$limit = 18;
|
||||
}
|
||||
$query = $this->getModel()::getDB()->where('mer_id', $merId)->where($where)
|
||||
->when(!empty($good_ids), function ($query) use ($good_ids) {
|
||||
$query->whereIn($this->getPk(), $good_ids);
|
||||
})->field($filed);
|
||||
$list = $query->limit($limit)->select()->toArray();
|
||||
|
||||
if ($is_show && count($list) < 6) {
|
||||
$res = $query->where('is_good', 1)->orderRaw("RAND()")->limit(6 - count($list))->select()->toArray();
|
||||
if ($res) $list = array_merge($list,$res);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function deleteProductFormByFormId(int $form_id, int $mer_id)
|
||||
{
|
||||
return $this->getModel()::getDB()->where('mer_form_id', $form_id)->where('mer_id', $mer_id)->update(['mer_form_id' => 0]);
|
||||
}
|
||||
}
|
399
app/common/dao/system/menu/SupplyMenuDao.php
Normal file
399
app/common/dao/system/menu/SupplyMenuDao.php
Normal file
@ -0,0 +1,399 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\system\menu;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\system\auth\SupplyMenu;
|
||||
use app\common\repositories\system\RelevanceRepository;
|
||||
use think\db\BaseQuery;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* Class SupplyMenuDao
|
||||
* @package app\common\dao\system\menu
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
class SupplyMenuDao extends BaseDao
|
||||
{
|
||||
/**
|
||||
* @return BaseModel
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return SupplyMenu::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @param int $is_mer
|
||||
* @return BaseQuery
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
public function search(array $where, int $is_mer = 0)
|
||||
{
|
||||
$query = SupplyMenu::getDB()->where('is_mer', $is_mer)->order('sort DESC,menu_id ASC');
|
||||
if (isset($where['pid'])) $query->where('pid', (int)$where['pid']);
|
||||
if (isset($where['keyword'])) $query->whereLike('menu_name|route', "%{$where['keyword']}%");
|
||||
if (isset($where['is_menu'])) $query->where('is_menu', (int)$where['is_menu']);
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $is_mer
|
||||
* @return array
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
public function getAllMenu($is_mer = 0)
|
||||
{
|
||||
return SupplyMenu::getDB()->where('is_mer', $is_mer)->where('is_menu', 1)->order('sort DESC,menu_id ASC')->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $is_mer
|
||||
* @return array
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
public function getAll($is_mer = 0)
|
||||
{
|
||||
return SupplyMenu::getInstance()->where('is_mer', $is_mer)->order('sort DESC,menu_id ASC')->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $is_mer
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
public function menuExists(int $id, $is_mer = 0)
|
||||
{
|
||||
return SupplyMenu::getDB()->where($this->getPk(), $id)->where('is_menu', 1)->where('is_mer', $is_mer)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $is_mer
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020-04-16
|
||||
*/
|
||||
public function merExists(int $id, $is_mer = 0)
|
||||
{
|
||||
return SupplyMenu::getDB()->where($this->getPk(), $id)->where('is_mer', $is_mer)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $is_mer
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
public function authExists(int $id, $is_mer = 0)
|
||||
{
|
||||
return SupplyMenu::getDB()->where($this->getPk(), $id)->where('is_menu', 0)->where('is_mer', $is_mer)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param int $is_mer
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
public function routeExists(string $route, $is_mer = 0)
|
||||
{
|
||||
return SupplyMenu::getDB()->where('route', $route)->where('is_menu', 0)->where('is_mer', $is_mer)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $is_mer
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
public function getAllMenuOptions($is_mer = 0)
|
||||
{
|
||||
return SupplyMenu::getDB()->where('is_menu', 1)->where('is_mer', $is_mer)->order('sort DESC,menu_id ASC')->column('menu_name,pid', 'menu_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $rule
|
||||
* @param int $is_mer
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020-04-10
|
||||
*/
|
||||
public function ruleByMenuList(array $rule, $is_mer = 0)
|
||||
{
|
||||
$paths = SupplyMenu::getDB()->whereIn($this->getPk(), $rule)->column('path', 'menu_id');
|
||||
$ids = [];
|
||||
foreach ($paths as $id => $path) {
|
||||
$ids = array_merge($ids, explode('/', trim($path, '/')));
|
||||
array_push($ids, $id);
|
||||
}
|
||||
|
||||
return SupplyMenu::getDB()->where('is_menu', 1)->where('is_show', 1)->order('sort DESC,menu_id ASC')->where('is_mer', $is_mer)
|
||||
->whereIn('menu_id', array_unique(array_filter($ids)))
|
||||
->column('menu_name title,route path,params,icon,pid,menu_id id');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $is_mer
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020-04-10
|
||||
*/
|
||||
public function getValidMenuList($is_mer = 0)
|
||||
{
|
||||
return SupplyMenu::getDB()->where('is_menu', 1)->where('is_show', 1)->order('sort DESC,menu_id ASC')->where('is_mer', $is_mer)
|
||||
->column('menu_name title,route path,params,icon,pid,menu_id id');
|
||||
}
|
||||
|
||||
public function typesByValidMenuList($typeId)
|
||||
{
|
||||
$paths = SupplyMenu::getDB()->alias('A')->leftJoin('Relevance B', 'A.menu_id = B.right_id')
|
||||
->where('is_show', 1)
|
||||
->order('sort DESC,menu_id ASC')
|
||||
->where('B.left_id', $typeId)
|
||||
->where('B.type', RelevanceRepository::TYPE_MERCHANT_AUTH)
|
||||
->column('path', 'menu_id');
|
||||
$ids = [];
|
||||
foreach ($paths as $id => $path) {
|
||||
$ids = array_merge($ids, explode('/', trim($path, '/')));
|
||||
array_push($ids, $id);
|
||||
}
|
||||
return SupplyMenu::getDB()->where('is_menu', 1)->where('is_show', 1)->order('sort DESC,menu_id ASC')->where('is_mer', 1)
|
||||
->whereIn('menu_id', array_unique(array_filter($ids)))
|
||||
->column('menu_name title,route path,params,icon,pid,menu_id id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $is_mer
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
public function getAllOptions($is_mer = 0, $all = false, $where = [], $filed = 'menu_name,pid')
|
||||
{
|
||||
return SupplyMenu::getDB()->where('is_mer', $is_mer ? 1 : 0)
|
||||
->when(isset($where['ids']) && !empty($where['ids']), function($query) use($where) {
|
||||
$query->whereIn('menu_id', $where['ids']);
|
||||
})
|
||||
->when(!$all, function ($query) {
|
||||
$query->where(function ($query) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('is_show', 1)->where('is_menu', 1);
|
||||
})->whereOr('is_menu', 0);
|
||||
});
|
||||
})
|
||||
->order('sort DESC,menu_id ASC')->column($filed, 'menu_id');
|
||||
}
|
||||
|
||||
public function merchantTypeByOptions($typeId, $all = false)
|
||||
{
|
||||
return SupplyMenu::getDB()->alias('A')->leftJoin('Relevance B', 'A.menu_id = B.right_id')->where('is_mer', 1)
|
||||
->where('B.left_id', $typeId)->where('B.type', RelevanceRepository::TYPE_MERCHANT_AUTH)->when(!$all, function ($query) {
|
||||
$query->where(function ($query) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('is_show', 1)->where('is_menu', 1);
|
||||
})->whereOr('is_menu', 0);
|
||||
});
|
||||
})->order('sort DESC,menu_id ASC')->column('menu_name,pid', 'menu_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param int $is_mer
|
||||
* @return mixed
|
||||
* @author xaboy
|
||||
* @day 2020-04-09
|
||||
*/
|
||||
public function getPath($id, $is_mer = 0)
|
||||
{
|
||||
return SupplyMenu::getDB()->where('is_mer', $is_mer)->where('menu_id', $id)->value('path');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $is_mer
|
||||
* @return array|Model|null
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
public function getMenu(int $id, $is_mer = 0)
|
||||
{
|
||||
return SupplyMenu::getDB()->where('is_mer', $is_mer)->where('is_menu', 1)->where($this->getPk(), $id)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $is_mer
|
||||
* @return array|Model|null
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
public function getAuth(int $id, $is_mer = 0)
|
||||
{
|
||||
return SupplyMenu::getDB()->where('is_mer', $is_mer)->where('is_menu', 0)->where($this->getPk(), $id)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $is_mer
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
public function delete(int $id, $is_mer = 0)
|
||||
{
|
||||
return SupplyMenu::getDB()->where('is_mer', $is_mer)->delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
public function pidExists(int $id)
|
||||
{
|
||||
return $this->fieldExists('pid', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020-04-10
|
||||
*/
|
||||
public function idsByRoutes(array $ids)
|
||||
{
|
||||
return SupplyMenu::getDB()->where('is_menu', 0)->whereIn($this->getPk(), $ids)->column('params,route');
|
||||
}
|
||||
|
||||
public function typesByRoutes($typeId, array $ids)
|
||||
{
|
||||
return SupplyMenu::getDB()->alias('A')->leftJoin('Relevance B', 'A.menu_id = B.right_id')->where('is_menu', 0)
|
||||
->where('B.left_id', $typeId)->whereIn('B.right_id', $ids)->where('B.type', RelevanceRepository::TYPE_MERCHANT_AUTH)->column('params,route');
|
||||
}
|
||||
|
||||
public function merchantTypeByRoutes($typeId)
|
||||
{
|
||||
return SupplyMenu::getDB()->alias('A')->leftJoin('Relevance B', 'A.menu_id = B.right_id')->where('is_menu', 0)
|
||||
->where('B.left_id', $typeId)->where('B.type', RelevanceRepository::TYPE_MERCHANT_AUTH)->column('params,route');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 商户顶级管理员权限
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 9/6/21
|
||||
*/
|
||||
public function merAdminRoutes()
|
||||
{
|
||||
return SupplyMenu::getDB()->where('is_menu', 0)->where('is_show', 1)->column('params,route');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $oldPath
|
||||
* @param string $path
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-04-30
|
||||
*/
|
||||
public function updatePath(string $oldPath, string $path)
|
||||
{
|
||||
SupplyMenu::getDB()->whereLike('path', $oldPath . '%')->field('menu_id,path')->select()->each(function ($val) use ($oldPath, $path) {
|
||||
$newPath = str_replace($oldPath, $path, $val['path']);
|
||||
SupplyMenu::getDB()->where('menu_id', $val['menu_id'])->update(['path' => $newPath]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/26
|
||||
* @param $field
|
||||
* @param $value
|
||||
* @return array|Model|null
|
||||
*/
|
||||
public function getFieldExists($field,$value)
|
||||
{
|
||||
return (($this->getModel()::getDB())->where($field,$value)->find());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/26
|
||||
* @param array $data
|
||||
* @return int
|
||||
*/
|
||||
public function insertAll(array $data)
|
||||
{
|
||||
return ($this->getModel()::getDB())->insertAll($data);
|
||||
}
|
||||
|
||||
public function deleteCommandMenu($where)
|
||||
{
|
||||
$this->getModel()::getDB()->where($where)->delete();
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
return ($this->getModel()::getDB())->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据每个路由分组获取是否存在父级
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/9/8
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMenuPid(string $route, $isMer, $isMenu)
|
||||
{
|
||||
return ($this->getModel()::getDB())
|
||||
->where('route',$route)
|
||||
->where('is_mer',$isMer)
|
||||
->where('is_menu',$isMenu)
|
||||
->order('path ASC')->find();
|
||||
}
|
||||
}
|
111
app/common/dao/system/menu/SupplyRoleDao.php
Normal file
111
app/common/dao/system/menu/SupplyRoleDao.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\system\menu;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\system\auth\SupplyRole;
|
||||
|
||||
/**
|
||||
* Class SupplyRoleDao
|
||||
* @package app\common\dao\system\menu
|
||||
* @author xaboy
|
||||
* @day 2020-04-18
|
||||
*/
|
||||
class SupplyRoleDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* @return BaseModel
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return SupplyRole::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $merId
|
||||
* @param array $where
|
||||
* @return BaseModel|SupplyRole
|
||||
* @author xaboy
|
||||
* @day 2020-04-18
|
||||
*/
|
||||
public function search($merId, array $where = [])
|
||||
{
|
||||
$roleModel = SupplyRole::getInstance();
|
||||
|
||||
if (isset($where['role_name'])) {
|
||||
$roleModel = $roleModel->whereLike('role_name', '%' . $where['role_name'] . '%');
|
||||
}
|
||||
|
||||
if (isset($where['status'])) {
|
||||
$roleModel = $roleModel->where('status', intval($where['status']));
|
||||
}
|
||||
|
||||
if (isset($where['role_ids']) && $where['role_ids'] !== '') {
|
||||
$roleModel = $roleModel->whereIn('role_id', $where['role_ids']);
|
||||
}
|
||||
|
||||
return $roleModel->where('mer_id', $merId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $merId
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020-04-18
|
||||
*/
|
||||
public function getAllOptions(int $merId)
|
||||
{
|
||||
return SupplyRole::getDB()->where('status', 1)->where('mer_id', $merId)->column('role_name', 'role_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $merId
|
||||
* @param array $ids
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020-04-18
|
||||
*/
|
||||
public function idsByRules($merId, array $ids)
|
||||
{
|
||||
$rules = SupplyRole::getDB()->where('status', 1)->where('mer_id', $merId)->whereIn($this->getPk(), $ids)->column('rules');
|
||||
$data = [];
|
||||
foreach ($rules as $rule) {
|
||||
$data = array_merge(explode(',', $rule), $data);
|
||||
}
|
||||
return array_unique($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $merId
|
||||
* @param int $id
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020-04-18
|
||||
*/
|
||||
public function merExists(int $merId, int $id)
|
||||
{
|
||||
return SupplyRole::getDB()->where($this->getPk(), $id)->where('mer_id', $merId)->count() > 0;
|
||||
}
|
||||
|
||||
public function getRolesListByIds(array $ids = [])
|
||||
{
|
||||
return SupplyRole::getDB()->whereIn($this->getPk(), $ids)->select()->toArray();
|
||||
}
|
||||
}
|
||||
|
128
app/common/model/store/order/SupplyStoreRefundOrder.php
Normal file
128
app/common/model/store/order/SupplyStoreRefundOrder.php
Normal file
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model\store\order;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
// use app\common\model\store\service\StoreService;
|
||||
use app\common\model\system\supply\Supply;
|
||||
use app\common\model\system\supply\SupplyAdmin;
|
||||
use app\common\model\user\User;
|
||||
|
||||
class SupplyStoreRefundOrder extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'refund_order_id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_store_refund_order';
|
||||
}
|
||||
|
||||
public function getPicsAttr($val)
|
||||
{
|
||||
return $val ? explode(',', $val) : [];
|
||||
}
|
||||
|
||||
public function setPicsAttr($val)
|
||||
{
|
||||
return $val ? implode(',', $val) : '';
|
||||
}
|
||||
|
||||
public function refundProduct()
|
||||
{
|
||||
return $this->hasMany(SupplyStoreRefundProduct::class, 'refund_order_id', 'refund_order_id');
|
||||
}
|
||||
|
||||
public function admin()
|
||||
{
|
||||
return $this->hasOne(SupplyAdmin::class, 'merchant_admin_id', 'admin_id');
|
||||
}
|
||||
public function services()
|
||||
{
|
||||
return '';
|
||||
// return $this->hasOne(StoreService::class, 'service_id', 'admin_id');
|
||||
}
|
||||
|
||||
|
||||
public function merchant()
|
||||
{
|
||||
return $this->hasOne(Supply::class, 'mer_id', 'mer_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne(User::class, 'uid', 'uid');
|
||||
}
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->hasOne(SupplyStoreOrder::class, 'order_id', 'order_id');
|
||||
}
|
||||
|
||||
public function searchDataAttr($query, $value)
|
||||
{
|
||||
return getModelTime($query, $value);
|
||||
}
|
||||
|
||||
public function getPhoneAttr($value)
|
||||
{
|
||||
if (env('SHOW_PHONE',false) && app('request')->hasMacro('adminInfo') && $value && is_numeric($value)){
|
||||
if (app('request')->userType() !== 2 || app('request')->adminInfo()['level'] != 0) {
|
||||
return substr_replace($value, '****', 3, 4);
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getAutoRefundTimeAttr()
|
||||
{
|
||||
$merAgree = systemConfig('mer_refund_order_agree') ?: 7;
|
||||
return strtotime('+' . $merAgree . ' day', strtotime($this->status_time));
|
||||
}
|
||||
|
||||
public function getCombineRefundParams()
|
||||
{
|
||||
return [
|
||||
'sub_mchid' => $this->merchant->sub_mchid,
|
||||
'order_sn' => $this->order->order_sn,
|
||||
'refund_order_sn' => $this->refund_order_sn,
|
||||
'refund_price' => $this->refund_price,
|
||||
'pay_price' => $this->order->pay_price,
|
||||
'refund_message' => $this->refund_message,
|
||||
'open_id' => $this->user->wechat->routine_openid ?? null,
|
||||
'transaction_id' => $this->order->transaction_id,
|
||||
];
|
||||
}
|
||||
|
||||
public function getCreateUserAttr()
|
||||
{
|
||||
switch ($this->user_type){
|
||||
case 1:
|
||||
return $this->user->nickname ?? '无';
|
||||
break;
|
||||
case 3:
|
||||
return $this->admin->real_name ?? '无';
|
||||
break;
|
||||
case 4:
|
||||
return $this->services->nickname ?? '无';
|
||||
break;
|
||||
}
|
||||
return '无';
|
||||
}
|
||||
|
||||
}
|
41
app/common/model/store/order/SupplyStoreRefundProduct.php
Normal file
41
app/common/model/store/order/SupplyStoreRefundProduct.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model\store\order;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class SupplyStoreRefundProduct extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'refund_product_id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_store_refund_product';
|
||||
}
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->hasOne(SupplyStoreOrderProduct::class,'order_product_id','order_product_id');
|
||||
}
|
||||
|
||||
public function refundOrder()
|
||||
{
|
||||
return $this->hasOne(SupplyStoreRefundOrder::class,'refund_order_id','refund_order_id');
|
||||
}
|
||||
}
|
117
app/common/model/system/SupplyRelevance.php
Normal file
117
app/common/model/system/SupplyRelevance.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model\system;
|
||||
|
||||
use app\common\model\store\product\SupplySpu;
|
||||
use app\common\model\BaseModel;
|
||||
// use app\common\model\community\Community;
|
||||
use app\common\model\store\SupplyStoreCategory;
|
||||
use app\common\model\system\auth\SupplyMenu;
|
||||
use app\common\model\system\supply\Supply;
|
||||
use app\common\model\user\User;
|
||||
// use app\common\repositories\system\RelevanceRepository;
|
||||
|
||||
class SupplyRelevance extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @return string
|
||||
* @author Qinii
|
||||
* @day 10/26/21
|
||||
*/
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'relevance_id';
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @return string
|
||||
* @author Qinii
|
||||
* @day 10/26/21
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_relevance';
|
||||
}
|
||||
|
||||
public function fans()
|
||||
{
|
||||
return $this->hasOne(User::class,'uid','left_id');
|
||||
}
|
||||
|
||||
public function focus()
|
||||
{
|
||||
return $this->hasOne(User::class,'uid','right_id');
|
||||
}
|
||||
|
||||
public function community()
|
||||
{
|
||||
return '';
|
||||
// return $this->hasOne(Community::class,'community_id','right_id')
|
||||
// ->bind(['community_id','title','image','start','uid','create_time','count_start','author','is_type']);
|
||||
}
|
||||
|
||||
public function getIsStartAttr()
|
||||
{
|
||||
return 0;
|
||||
// return self::where('left_id', $this->right_id)
|
||||
// ->where('right_id',$this->left_id)
|
||||
// ->where('type',RelevanceRepository::TYPE_COMMUNITY_FANS)
|
||||
// ->count() > 0;
|
||||
}
|
||||
|
||||
public function spu()
|
||||
{
|
||||
return $this->hasOne(SupplySpu::class, 'spu_id','right_id');
|
||||
}
|
||||
public function merchant()
|
||||
{
|
||||
return $this->hasOne(Supply::class, 'mer_id','right_id');
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->hasOne(SupplyStoreCategory::class, 'store_category_id','right_id');
|
||||
}
|
||||
|
||||
|
||||
public function auth()
|
||||
{
|
||||
return $this->hasOne(SupplyMenu::class, 'menu_id','right_id');
|
||||
}
|
||||
|
||||
public function searchLeftIdAttr($query, $value)
|
||||
{
|
||||
$query->where('left_id', $value);
|
||||
}
|
||||
|
||||
public function searchRightIdAttr($query, $value)
|
||||
{
|
||||
if ($value) {
|
||||
if (is_array($value)) {
|
||||
$query->whereIn('right_id', $value);
|
||||
} else {
|
||||
$query->where('right_id', $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function searchTypeAttr($query, $value)
|
||||
{
|
||||
$query->where('type', $value);
|
||||
}
|
||||
|
||||
}
|
52
app/common/model/system/auth/SupplyMenu.php
Normal file
52
app/common/model/system/auth/SupplyMenu.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model\system\auth;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class SupplyMenu extends BaseModel
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'menu_id';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_system_menu';
|
||||
}
|
||||
|
||||
public function searchMenuIdAttr($query,$value)
|
||||
{
|
||||
$query->where('menu_id', $value);
|
||||
}
|
||||
|
||||
public function searchRouteAttr($query,$value)
|
||||
{
|
||||
$query->where('route', $value);
|
||||
}
|
||||
|
||||
|
||||
}
|
68
app/common/model/system/auth/SupplyRole.php
Normal file
68
app/common/model/system/auth/SupplyRole.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model\system\auth;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class SupplyRole extends BaseModel
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'role_id';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_system_role';
|
||||
}
|
||||
|
||||
public function ruleNames($isArray = false)
|
||||
{
|
||||
$menusName = SupplyMenu::getDB()->whereIn('menu_id', $this->rules)->column('menu_name');
|
||||
return $isArray ? $menusName : implode(',', $menusName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
public function getRulesAttr($value)
|
||||
{
|
||||
return array_map('intval', explode(',', $value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
public function setRulesAttr($value)
|
||||
{
|
||||
return implode(',', $value);
|
||||
}
|
||||
}
|
94
app/common/model/system/financial/SupplyFinancial.php
Normal file
94
app/common/model/system/financial/SupplyFinancial.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model\system\financial;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\system\admin\Admin;
|
||||
use app\common\model\system\supply\Supply;
|
||||
use app\common\model\system\supply\SupplyAdmin;
|
||||
use think\facade\Db;
|
||||
|
||||
class SupplyFinancial extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'financial_id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_financial';
|
||||
}
|
||||
|
||||
public function merchant()
|
||||
{
|
||||
return $this->hasOne(Supply::class,'mer_id','mer_id');
|
||||
}
|
||||
|
||||
public function getFinancialAccountAttr($value)
|
||||
{
|
||||
return json_decode($value);
|
||||
}
|
||||
|
||||
public function getImageAttr($value)
|
||||
{
|
||||
return explode(',',$value);
|
||||
}
|
||||
|
||||
public function getAdminIdAttr($value)
|
||||
{
|
||||
return Admin::where('admin_id',$value)->value('real_name');
|
||||
}
|
||||
|
||||
public function getMerAdminIdAttr($value)
|
||||
{
|
||||
return SupplyAdmin::where('merchant_admin_id',$value)->value('real_name');
|
||||
}
|
||||
|
||||
public function searchFinancialIdAttr($query,$value)
|
||||
{
|
||||
$query->where('financial_id',$value);
|
||||
}
|
||||
public function searchMerIdAttr($query,$value)
|
||||
{
|
||||
$query->where('mer_id',$value);
|
||||
}
|
||||
public function searchStatusAttr($query,$value)
|
||||
{
|
||||
$query->where('status',$value);
|
||||
}
|
||||
public function searchFinancailStatusAttr($query,$value)
|
||||
{
|
||||
$query->where('financial_status',$value);
|
||||
}
|
||||
public function searchFinancailTypeAttr($query,$value)
|
||||
{
|
||||
$query->where('financial_type',$value);
|
||||
}
|
||||
public function searchKeywordsAttr($query,$value)
|
||||
{
|
||||
$query->whereLike('keywords',"%{$value}%");
|
||||
}
|
||||
public function searchDateAttr($query,$value)
|
||||
{
|
||||
getModelTime($query,$value);
|
||||
}
|
||||
public function searchIsDelAttr($query,$value)
|
||||
{
|
||||
$query->where('is_del',$value);
|
||||
}
|
||||
|
||||
}
|
84
app/common/model/system/serve/SupplyServeOrder.php
Normal file
84
app/common/model/system/serve/SupplyServeOrder.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\model\system\serve;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\system\supply\Supply;
|
||||
use app\common\model\user\User;
|
||||
|
||||
class SupplyServeOrder extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'order_id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_serve_order';
|
||||
}
|
||||
|
||||
public function getOrderInfoAttr($value)
|
||||
{
|
||||
return json_decode($value);
|
||||
}
|
||||
|
||||
public function merchant()
|
||||
{
|
||||
return $this->hasOne(Supply::class,'mer_id','mer_id');
|
||||
}
|
||||
|
||||
public function userInfo()
|
||||
{
|
||||
return $this->hasOne(User::class,'mer_id','ud');
|
||||
}
|
||||
|
||||
public function searchTypeAttr($query, $value)
|
||||
{
|
||||
$query->where('type', $value);
|
||||
}
|
||||
|
||||
public function searchStatusAttr($query, $value)
|
||||
{
|
||||
$query->where('status', $value);
|
||||
}
|
||||
|
||||
public function searchOrderSnAttr($query, $value)
|
||||
{
|
||||
$query->where('order_sn', $value);
|
||||
}
|
||||
|
||||
public function searchIsDelAttr($query, $value)
|
||||
{
|
||||
$query->where('is_del', $value);
|
||||
}
|
||||
|
||||
public function searchMealIdAttr($query, $value)
|
||||
{
|
||||
$query->where('meal_id', $value);
|
||||
}
|
||||
|
||||
public function searchMerIdAttr($query, $value)
|
||||
{
|
||||
$query->where('mer_id', $value);
|
||||
}
|
||||
|
||||
public function searchDateAttr($query,$value)
|
||||
{
|
||||
getModelTime($query, $value);
|
||||
}
|
||||
|
||||
public function searchPayTypeAttr($query,$value)
|
||||
{
|
||||
$query->where('value');
|
||||
}
|
||||
}
|
@ -15,8 +15,8 @@ namespace app\common\model\system\supply;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\order\StoreRefundOrder;
|
||||
use app\common\model\store\order\SupplyStoreOrder;
|
||||
use app\common\model\store\order\SupplyStoreRefundOrder;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserOrder;
|
||||
|
||||
@ -30,7 +30,7 @@ class FinancialRecord extends BaseModel
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'financial_record';
|
||||
return 'supply_financial_record';
|
||||
}
|
||||
|
||||
public function user()
|
||||
@ -45,12 +45,12 @@ class FinancialRecord extends BaseModel
|
||||
|
||||
public function orderInfo()
|
||||
{
|
||||
return $this->hasOne(StoreOrder::class, 'order_sn', 'order_sn');
|
||||
return $this->hasOne(SupplyStoreOrder::class, 'order_sn', 'order_sn');
|
||||
}
|
||||
|
||||
public function refundOrder()
|
||||
{
|
||||
return $this->hasOne(StoreRefundOrder::class, 'refund_order_sn', 'order_sn');
|
||||
return $this->hasOne(SupplyStoreRefundOrder::class, 'refund_order_sn', 'order_sn');
|
||||
}
|
||||
|
||||
public function userOrder()
|
||||
|
@ -14,16 +14,16 @@
|
||||
namespace app\common\model\system\supply;
|
||||
|
||||
|
||||
use app\common\dao\store\product\ProductDao;
|
||||
use app\common\dao\store\product\SupplyProductDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\coupon\StoreCouponUser;
|
||||
use app\common\model\store\product\Product;
|
||||
use app\common\model\store\product\Spu;
|
||||
use app\common\model\store\service\StoreService;
|
||||
// use app\common\model\store\coupon\StoreCouponUser;
|
||||
use app\common\model\store\product\SupplyProduct;
|
||||
use app\common\model\store\product\SupplySpu;
|
||||
// use app\common\model\store\service\StoreService;
|
||||
use app\common\model\system\config\SystemConfigValue;
|
||||
use app\common\model\system\financial\Financial;
|
||||
use app\common\model\system\serve\ServeOrder;
|
||||
use app\common\repositories\store\StoreActivityRepository;
|
||||
use app\common\model\system\financial\SupplyFinancial;
|
||||
use app\common\model\system\serve\SupplyServeOrder;
|
||||
// use app\common\repositories\store\StoreActivityRepository;
|
||||
|
||||
class Supply extends BaseModel
|
||||
{
|
||||
@ -56,7 +56,7 @@ class Supply extends BaseModel
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->hasMany(Product::class, 'mer_id', 'mer_id');
|
||||
return $this->hasMany(SupplyProduct::class, 'mer_id', 'mer_id');
|
||||
}
|
||||
|
||||
public function config()
|
||||
@ -66,8 +66,8 @@ class Supply extends BaseModel
|
||||
|
||||
public function showProduct()
|
||||
{
|
||||
return $this->hasMany(Product::class, 'mer_id', 'mer_id')
|
||||
->where((new ProductDao())->productShow())
|
||||
return $this->hasMany(SupplyProduct::class, 'mer_id', 'mer_id')
|
||||
->where((new SupplyProductDao())->productShow())
|
||||
->field('mer_id,product_id,store_name,image,price,is_show,status,is_gift_bag,is_good')
|
||||
->order('is_good DESC,sort DESC');
|
||||
}
|
||||
@ -80,56 +80,57 @@ class Supply extends BaseModel
|
||||
*/
|
||||
public function getAllRecommendAttr()
|
||||
{
|
||||
$list = Product::where('mer_id', $this['mer_id'])
|
||||
->where((new ProductDao())->productShow())
|
||||
$list = SupplyProduct::where('mer_id', $this['mer_id'])
|
||||
->where((new SupplyProductDao())->productShow())
|
||||
->field('mer_id,product_id,store_name,image,price,is_show,status,is_gift_bag,is_good,cate_id')
|
||||
->order('is_good DESC, sort DESC, create_time DESC')
|
||||
->limit(3)
|
||||
->select()->append(['show_svip_info']);
|
||||
if ($list) {
|
||||
$data = [];
|
||||
$make = app()->make(StoreActivityRepository::class);
|
||||
foreach ($list as $item) {
|
||||
$spu = Spu::where('product_id',$item->product_id)->where('product_type' ,0)->find();
|
||||
$spu_id = $spu->spu_id;
|
||||
$act = $make->getActivityBySpu(StoreActivityRepository::ACTIVITY_TYPE_BORDER,$spu_id,$item['cate_id'],$item['mer_id'],$spu->sys_labels);
|
||||
$item['border_pic'] = $act['pic'] ?? '';
|
||||
$data[] = $item;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
return [];
|
||||
// if ($list) {
|
||||
// $data = [];
|
||||
// $make = app()->make(StoreActivityRepository::class);
|
||||
// foreach ($list as $item) {
|
||||
// $spu = SupplySpu::where('product_id',$item->product_id)->where('product_type' ,0)->find();
|
||||
// $spu_id = $spu->spu_id;
|
||||
// $act = $make->getActivityBySpu(StoreActivityRepository::ACTIVITY_TYPE_BORDER,$spu_id,$item['cate_id'],$item['mer_id'],$spu->sys_labels);
|
||||
// $item['border_pic'] = $act['pic'] ?? '';
|
||||
// $data[] = $item;
|
||||
// }
|
||||
// return $data;
|
||||
// }
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getCityRecommendAttr()
|
||||
{
|
||||
$list = Product::where('mer_id', $this['mer_id'])
|
||||
->where((new ProductDao())->productShow())
|
||||
$list = SupplyProduct::where('mer_id', $this['mer_id'])
|
||||
->where((new SupplyProductDao())->productShow())
|
||||
->whereLike('delivery_way',"%1%")
|
||||
->field('mer_id,product_id,store_name,image,price,is_show,status,is_gift_bag,is_good,cate_id')
|
||||
->order('sort DESC, create_time DESC')
|
||||
->limit(3)
|
||||
->select();
|
||||
if ($list) {
|
||||
$data = [];
|
||||
$make = app()->make(StoreActivityRepository::class);
|
||||
foreach ($list as $item) {
|
||||
$spu = Spu::where('product_id',$item->product_id)->where('product_type' ,0)->find();
|
||||
$spu_id = $spu->spu_id;
|
||||
$act = $make->getActivityBySpu(StoreActivityRepository::ACTIVITY_TYPE_BORDER,$spu_id,$item['cate_id'],$item['mer_id'],$spu->sys_labels);
|
||||
$item['border_pic'] = $act['pic'] ?? '';
|
||||
$data[] = $item;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
return [];
|
||||
return $list;
|
||||
// if ($list) {
|
||||
// $data = [];
|
||||
// $make = app()->make(StoreActivityRepository::class);
|
||||
// foreach ($list as $item) {
|
||||
// $spu = SupplySpu::where('product_id',$item->product_id)->where('product_type' ,0)->find();
|
||||
// $spu_id = $spu->spu_id;
|
||||
// $act = $make->getActivityBySpu(StoreActivityRepository::ACTIVITY_TYPE_BORDER,$spu_id,$item['cate_id'],$item['mer_id'],$spu->sys_labels);
|
||||
// $item['border_pic'] = $act['pic'] ?? '';
|
||||
// $data[] = $item;
|
||||
// }
|
||||
// return $data;
|
||||
// }
|
||||
// return [];
|
||||
}
|
||||
|
||||
|
||||
public function recommend()
|
||||
{
|
||||
return $this->hasMany(Product::class, 'mer_id', 'mer_id')
|
||||
->where((new ProductDao())->productShow())
|
||||
return $this->hasMany(SupplyProduct::class, 'mer_id', 'mer_id')
|
||||
->where((new SupplyProductDao())->productShow())
|
||||
->where('is_good', 1)
|
||||
->field('mer_id,product_id,store_name,image,price,is_show,status,is_gift_bag,is_good,sales,create_time')
|
||||
->order('is_good DESC,sort DESC,create_time DESC')
|
||||
@ -139,39 +140,41 @@ class Supply extends BaseModel
|
||||
|
||||
public function coupon()
|
||||
{
|
||||
$time = date('Y-m-d H:i:s');
|
||||
return $this->hasMany(StoreCouponUser::class, 'mer_id', 'mer_id')->where('start_time', '<', $time)->where('end_time', '>', $time)
|
||||
->where('is_fail', 0)->where('status', 0)->order('coupon_price DESC, coupon_user_id ASC')
|
||||
->with(['product' => function ($query) {
|
||||
$query->field('coupon_id,product_id');
|
||||
}, 'coupon' => function ($query) {
|
||||
$query->field('coupon_id,type');
|
||||
}]);
|
||||
return [];
|
||||
// $time = date('Y-m-d H:i:s');
|
||||
// return $this->hasMany(StoreCouponUser::class, 'mer_id', 'mer_id')->where('start_time', '<', $time)->where('end_time', '>', $time)
|
||||
// ->where('is_fail', 0)->where('status', 0)->order('coupon_price DESC, coupon_user_id ASC')
|
||||
// ->with(['product' => function ($query) {
|
||||
// $query->field('coupon_id,product_id');
|
||||
// }, 'coupon' => function ($query) {
|
||||
// $query->field('coupon_id,type');
|
||||
// }]);
|
||||
}
|
||||
|
||||
public function getServicesTypeAttr()
|
||||
{
|
||||
//0 支持在线聊天 1 支持电话 -1 暂无客服
|
||||
$services_type = merchantConfig($this->mer_id,'services_type');
|
||||
if ($services_type) {
|
||||
if (!$this->service_phone) $services_type = -1;
|
||||
} else {
|
||||
$services_type = 0;
|
||||
$where = ['mer_id' => $this->mer_id, 'is_open' => 1,'status' => 1];
|
||||
$service = StoreService::where($where)->count();
|
||||
if (!$service) $services_type = -1;
|
||||
}
|
||||
return $services_type;
|
||||
return 1;
|
||||
// $services_type = merchantConfig($this->mer_id,'services_type');
|
||||
// if ($services_type) {
|
||||
// if (!$this->service_phone) $services_type = -1;
|
||||
// } else {
|
||||
// $services_type = 0;
|
||||
// $where = ['mer_id' => $this->mer_id, 'is_open' => 1,'status' => 1];
|
||||
// $service = StoreService::where($where)->count();
|
||||
// if (!$service) $services_type = -1;
|
||||
// }
|
||||
// return $services_type;
|
||||
}
|
||||
|
||||
public function marginOrder()
|
||||
{
|
||||
return $this->hasMany(ServeOrder::class, 'mer_id','mer_id')->where('type', 10)->order('create_time DESC');
|
||||
return $this->hasMany(SupplyServeOrder::class, 'mer_id','mer_id')->where('type', 10)->order('create_time DESC');
|
||||
}
|
||||
|
||||
public function refundMarginOrder()
|
||||
{
|
||||
return $this->hasOne(Financial::class, 'mer_id', 'mer_id')
|
||||
return $this->hasOne(SupplyFinancial::class, 'mer_id', 'mer_id')
|
||||
->where('type',1)
|
||||
->where('status', -1)
|
||||
->order('create_time DESC')
|
||||
|
@ -37,7 +37,7 @@ class SupplyAdmin extends BaseModel
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'merchant_admin';
|
||||
return 'supply_admin';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,7 @@ class SupplyApplyments extends BaseModel
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'merchant_applyments';
|
||||
return 'supply_applyments';
|
||||
}
|
||||
|
||||
public function merchant()
|
||||
|
@ -42,6 +42,6 @@ class SupplyCategory extends BaseModel
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'merchant_category';
|
||||
return 'supply_category';
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class SupplyIntention extends BaseModel
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'merchant_intention';
|
||||
return 'supply_intention';
|
||||
}
|
||||
|
||||
public function setImagesAttr($value)
|
||||
|
@ -14,7 +14,7 @@ namespace app\common\model\system\supply;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\system\Relevance;
|
||||
use app\common\model\system\SupplyRelevance;
|
||||
use app\common\repositories\system\RelevanceRepository;
|
||||
|
||||
class SupplyType extends BaseModel
|
||||
@ -27,12 +27,12 @@ class SupplyType extends BaseModel
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'merchant_type';
|
||||
return 'supply_type';
|
||||
}
|
||||
|
||||
public function auth()
|
||||
{
|
||||
return $this->hasMany(Relevance::class, 'left_id', 'mer_type_id')->where('type', RelevanceRepository::TYPE_MERCHANT_AUTH);
|
||||
return $this->hasMany(SupplyRelevance::class, 'left_id', 'mer_type_id')->where('type', RelevanceRepository::TYPE_MERCHANT_AUTH);
|
||||
}
|
||||
public function getMerchantCountAttr()
|
||||
{
|
||||
|
343
app/common/repositories/system/auth/SupplyMenuRepository.php
Normal file
343
app/common/repositories/system/auth/SupplyMenuRepository.php
Normal file
@ -0,0 +1,343 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\repositories\system\auth;
|
||||
|
||||
|
||||
//附件
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\dao\system\menu\SupplyMenuDao;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use FormBuilder\Exception\FormBuilderException;
|
||||
use FormBuilder\Factory\Elm;
|
||||
use FormBuilder\Form;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
use think\facade\Route;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* Class BaseRepository
|
||||
* @package common\repositories
|
||||
* @mixin SupplyMenuDao
|
||||
*/
|
||||
class SupplyMenuRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* SupplyMenuRepository constructor.
|
||||
* @param SupplyMenuDao $dao
|
||||
*/
|
||||
protected $styles = array(
|
||||
'success' => "\033[0;32m%s\033[0m",
|
||||
'error' => "\033[31;31m%s\033[0m",
|
||||
'info' => "\033[33;33m%s\033[0m"
|
||||
);
|
||||
|
||||
public $prompt = 'all';
|
||||
|
||||
public function __construct(SupplyMenuDao $dao)
|
||||
{
|
||||
/**
|
||||
* @var SupplyMenuDao
|
||||
*/
|
||||
$this->dao = $dao;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @param int $merId
|
||||
* @return array
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-04-16
|
||||
*/
|
||||
public function getList(array $where, $merId = 0)
|
||||
{
|
||||
$query = $this->dao->search($where, $merId);
|
||||
$count = $query->count();
|
||||
$list = $query->hidden(['update_time', 'path'])->select()->toArray();
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return BaseDao|Model
|
||||
* @author xaboy
|
||||
* @day 2020-04-09
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
$data['path'] = '/';
|
||||
if ($data['pid']) {
|
||||
$data['path'] = $this->getPath($data['pid']) . $data['pid'] . '/';
|
||||
}
|
||||
return $this->dao->create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020-04-09
|
||||
*/
|
||||
public function update(int $id, array $data)
|
||||
{
|
||||
$menu = $this->dao->get($id);
|
||||
if ($menu->pid != $data['pid']) {
|
||||
Db::transaction(function () use ($menu, $data) {
|
||||
$data['path'] = '/';
|
||||
if ($data['pid']) {
|
||||
$data['path'] = $this->getPath($data['pid']) . $data['pid'] . '/';
|
||||
}
|
||||
$this->dao->updatePath($menu->path . $menu->menu_id . '/', $data['path'] . $menu->menu_id . '/');
|
||||
$menu->save($data);
|
||||
});
|
||||
} else {
|
||||
unset($data['path']);
|
||||
$this->dao->update($id, $data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $is_mer
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020-04-18
|
||||
*/
|
||||
public function getTree($merType = 0)
|
||||
{
|
||||
if (!$merType) {
|
||||
$options = $this->dao->getAllOptions();
|
||||
} else {
|
||||
$options = $this->dao->merchantTypeByOptions($merType);
|
||||
}
|
||||
return formatTree($options, 'menu_name');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $isMer
|
||||
* @param int|null $id
|
||||
* @param array $formData
|
||||
* @return Form
|
||||
* @throws FormBuilderException
|
||||
* @author xaboy
|
||||
* @day 2020-04-16
|
||||
*/
|
||||
public function menuForm(int $isMer = 0, ?int $id = null, array $formData = []): Form
|
||||
{
|
||||
$action = $isMer == 0 ? (is_null($id) ? Route::buildUrl('systemMenuCreate')->build() : Route::buildUrl('systemMenuUpdate', ['id' => $id])->build())
|
||||
: (is_null($id) ? Route::buildUrl('systemMerchantMenuCreate')->build() : Route::buildUrl('systemMerchantMenuUpdate', ['id' => $id])->build());
|
||||
|
||||
$form = Elm::createForm($action);
|
||||
$form->setRule([
|
||||
Elm::cascader('pid', '父级分类:')->options(function () use ($id, $isMer) {
|
||||
$menus = $this->dao->getAllOptions($isMer, true);
|
||||
if ($id && isset($menus[$id])) unset($menus[$id]);
|
||||
$menus = formatCascaderData($menus, 'menu_name');
|
||||
array_unshift($menus, ['label' => '顶级分类:', 'value' => 0]);
|
||||
return $menus;
|
||||
})->placeholder('请选择分级分类')->props(['props' => ['checkStrictly' => true, 'emitPath' => false]]),
|
||||
Elm::select('is_menu', '权限类型:', 1)->options([
|
||||
['value' => 1, 'label' => '菜单'],
|
||||
['value' => 0, 'label' => '权限'],
|
||||
])->control([
|
||||
[
|
||||
'value' => 0,
|
||||
'rule' => [
|
||||
Elm::input('menu_name', '路由名称:')->placeholder('请输入路由名称')->required(),
|
||||
Elm::textarea('params', '参数:')->placeholder("路由参数:\r\nkey1:value1\r\nkey2:value2"),
|
||||
]
|
||||
], [
|
||||
'value' => 1,
|
||||
'rule' => [
|
||||
Elm::switches('is_show', '是否显示:', 1)->inactiveValue(0)->activeValue(1)->inactiveText('关')->activeText('开'),
|
||||
Elm::frameInput('icon', '菜单图标:', '/' . config('admin.admin_prefix') . '/setting/icons?field=icon')->icon('el-icon-circle-plus-outline')->height('338px')->width('700px')->modal(['modal' => false]),
|
||||
Elm::input('menu_name', '菜单名称:')->placeholder('请输入菜单名称')->required(),
|
||||
]
|
||||
]
|
||||
]),
|
||||
Elm::input('route', '路由:')->placeholder('请输入路由'),
|
||||
Elm::number('sort', '排序:', 0)->precision(0)->max(99999)
|
||||
]);
|
||||
|
||||
return $form->setTitle(is_null($id) ? '添加菜单' : '编辑菜单')->formData($formData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $merId
|
||||
* @return Form
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws FormBuilderException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-04-16
|
||||
*/
|
||||
public function updateMenuForm(int $id, $merId = 0)
|
||||
{
|
||||
return $this->menuForm($merId, $id, $this->dao->get($id)->toArray());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $params
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020-04-22
|
||||
*/
|
||||
public function tidyParams(?string $params)
|
||||
{
|
||||
return $params ? array_reduce(explode('|', $params), function ($initial, $val) {
|
||||
$data = explode(':', $val, 2);
|
||||
if (count($data) != 2) return $initial;
|
||||
$initial[$data[0]] = $data[1];
|
||||
return $initial;
|
||||
}, []) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @param array $routeParams
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020-04-23
|
||||
*/
|
||||
public function checkParams(array $params, array $routeParams)
|
||||
{
|
||||
foreach ($routeParams as $k => $param) {
|
||||
if (isset($params[$k]) && $params[$k] != $param)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function formatPath($is_mer = 0)
|
||||
{
|
||||
$options = $this->getAll($is_mer);
|
||||
$options = formatCategory($options, 'menu_id');
|
||||
Db::transaction(function () use ($options) {
|
||||
foreach ($options as $option) {
|
||||
$this->_formatPath($option);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected function _formatPath($parent, $path = '/')
|
||||
{
|
||||
$this->dao->update($parent['menu_id'], ['path' => $path]);
|
||||
foreach ($parent['children'] ?? [] as $item) {
|
||||
$itemPath = $path . $item['pid'] . '/';
|
||||
$this->_formatPath($item, $itemPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function commandMenu($type, $data, $prompt)
|
||||
{
|
||||
$res = [];
|
||||
if ($prompt) $this->prompt = $prompt;
|
||||
$isMer = ($type == 'sys') ? 0 : 1;
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
try{
|
||||
$result = $this->dao->getMenuPid($key, $isMer, 0);
|
||||
if (!$result) {
|
||||
$route = $key;
|
||||
$isAppend =0;
|
||||
if (substr($key,0,7) === 'append_') {
|
||||
$isAppend = 1;
|
||||
$route = substr($key,7);
|
||||
}
|
||||
$result = $this->dao->getMenuPid($route, $isMer, 1);
|
||||
if (!$result && $key !== 'self') {
|
||||
printf($this->styles['info'], '未找到菜单: '. $key);
|
||||
echo PHP_EOL;
|
||||
continue;
|
||||
} else {
|
||||
$result = $this->dao->create([
|
||||
'pid' => $key == 'self' ? 0 : $result['menu_id'],
|
||||
'path' => $key == 'self' ? '/' : $result['path'] . $result['menu_id'] . '/',
|
||||
'menu_name' => $isAppend ? '附加权限' : '权限' ,
|
||||
'route' => $key,
|
||||
'is_mer' => $isMer,
|
||||
'is_menu' => 0
|
||||
]);
|
||||
}
|
||||
}
|
||||
$res = array_merge($res, $this->createSlit($isMer, $result['menu_id'], $result['path'], $value));
|
||||
}catch (\Exception $exception) {
|
||||
throw new Exception($key);
|
||||
}
|
||||
}
|
||||
$count = count($res);
|
||||
if (!empty($res)) $this->dao->insertAll($res);
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 新增权限数据整理
|
||||
* @param int $isMer
|
||||
* @param int $menuId
|
||||
* @param string $path
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 3/18/22
|
||||
*/
|
||||
public function createSlit(int $isMer,int $menuId, string $path,array $data)
|
||||
{
|
||||
$arr = [];
|
||||
try {
|
||||
foreach ($data as $k => $v) {
|
||||
$result = $this->dao->getWhere(['route' => $v['route'], 'pid' => $menuId]);
|
||||
if (!$result) {
|
||||
$arr[] = [
|
||||
'pid' => $menuId,
|
||||
'path' => $path . $menuId . '/',
|
||||
'menu_name' => $v['menu_name'],
|
||||
'route' => $v['route'],
|
||||
'is_mer' => $isMer,
|
||||
'is_menu' => 0,
|
||||
'params' => $v['params'] ?? [],
|
||||
];
|
||||
if ($this->prompt == 's') {
|
||||
printf($this->styles['success'], '新增权限: ' . $v['menu_name'] . ' [' . $v['route'] . ']');
|
||||
echo PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
}catch (\Exception $exception) {
|
||||
halt($isMer, $menuId, $path, $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
135
app/common/repositories/system/auth/SupplyRoleRepository.php
Normal file
135
app/common/repositories/system/auth/SupplyRoleRepository.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\repositories\system\auth;
|
||||
|
||||
|
||||
//附件
|
||||
use app\common\dao\system\menu\SupplyRoleDao;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use FormBuilder\Exception\FormBuilderException;
|
||||
use FormBuilder\Factory\Elm;
|
||||
use FormBuilder\Form;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Route;
|
||||
|
||||
|
||||
/**
|
||||
* Class BaseRepository
|
||||
* @package common\repositories
|
||||
* @mixin SupplyRoleDao
|
||||
*/
|
||||
class SupplyRoleRepository extends BaseRepository
|
||||
{
|
||||
public function __construct(SupplyRoleDao $dao)
|
||||
{
|
||||
/**
|
||||
* @var SupplyRoleDao
|
||||
*/
|
||||
$this->dao = $dao;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $merId
|
||||
* @param array $where
|
||||
* @param $page
|
||||
* @param $limit
|
||||
* @return array
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-04-18
|
||||
*/
|
||||
public function search(int $merId, array $where, $page, $limit)
|
||||
{
|
||||
$query = $this->dao->search($merId, $where);
|
||||
$count = $query->count();
|
||||
$list = $query->page($page, $limit)->select();
|
||||
|
||||
foreach ($list as $k => $role) {
|
||||
$list[$k]['rule_name'] = $role->ruleNames();
|
||||
}
|
||||
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020-04-09
|
||||
*/
|
||||
public function update(int $id, array $data)
|
||||
{
|
||||
if (isset($data['rules']))
|
||||
$data['rules'] = implode(',', $data['rules']);
|
||||
return $this->dao->update($id, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $is_mer
|
||||
* @param int|null $id
|
||||
* @param array $formData
|
||||
* @return Form
|
||||
* @throws FormBuilderException
|
||||
* @author xaboy
|
||||
* @day 2020-04-18
|
||||
*/
|
||||
public function form($merType = 0, ?int $id = null, array $formData = []): Form
|
||||
{
|
||||
if ($merType)
|
||||
$form = Elm::createForm(is_null($id) ? Route::buildUrl('merchantRoleCreate')->build() : Route::buildUrl('merchantRoleUpdate', ['id' => $id])->build());
|
||||
else
|
||||
$form = Elm::createForm(is_null($id) ? Route::buildUrl('systemRoleCreate')->build() : Route::buildUrl('systemRoleUpdate', ['id' => $id])->build());
|
||||
|
||||
$options = app()->make(MenuRepository::class)->getTree($merType);
|
||||
|
||||
$form->setRule([
|
||||
Elm::input('role_name', '身份名称:')->placeholder('请输入身份名称')->required(),
|
||||
Elm::tree('rules', '权限:')->data($options)->showCheckbox(true),
|
||||
Elm::switches('status', '是否开启:', 1)->inactiveValue(0)->activeValue(1)->inactiveText('关')->activeText('开'),
|
||||
]);
|
||||
|
||||
return $form->setTitle(is_null($id) ? '添加身份' : '编辑身份')->formData($formData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param bool $is_mer
|
||||
* @param int $id
|
||||
* @return Form
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws FormBuilderException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-04-18
|
||||
*/
|
||||
public function updateForm($is_mer, int $id)
|
||||
{
|
||||
return $this->form($is_mer, $id, $this->dao->get($id)->toArray());
|
||||
}
|
||||
|
||||
public function checkRole(array $role, $merId)
|
||||
{
|
||||
$rest = $this->dao->search($merId, ['role_ids' => $role,'status' => 1])->column('role_id');
|
||||
sort($role);
|
||||
sort($rest);
|
||||
return (sort($role) == sort($rest)) ? true: false;
|
||||
}
|
||||
}
|
@ -49,7 +49,7 @@ class Menu extends BaseController
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->repository = $repository;
|
||||
$this->merchant = $this->request->param('merchant', 2) == 0 ? 0 : 2;
|
||||
$this->merchant = $this->request->param('merchant', 0) == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
211
app/controller/admin/system/auth/SupplyMenu.php
Normal file
211
app/controller/admin/system/auth/SupplyMenu.php
Normal file
@ -0,0 +1,211 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\controller\admin\system\auth;
|
||||
|
||||
use crmeb\basic\BaseController;
|
||||
use app\common\repositories\system\auth\SupplyMenuRepository;
|
||||
use app\validate\admin\MenuValidate;
|
||||
use FormBuilder\Exception\FormBuilderException;
|
||||
use think\App;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
|
||||
/**
|
||||
* Class SupplyMenu
|
||||
* @package app\controller\admin\system\menu
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
class SupplyMenu extends BaseController
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $merchant;
|
||||
|
||||
/**
|
||||
* @var SupplyMenuRepository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Menu constructor.
|
||||
* @param App $app
|
||||
* @param SupplyMenuRepository $repository
|
||||
*/
|
||||
public function __construct(App $app, SupplyMenuRepository $repository)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->repository = $repository;
|
||||
$this->merchant = $this->request->param('merchant', 0) == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
$data = $this->repository->getList([], $this->merchant);
|
||||
$data['list'] = formatCategory($data['list'], 'menu_id');
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param MenuValidate $validate
|
||||
* @return mixed
|
||||
* @author 张先生
|
||||
* @date 2020-03-30
|
||||
*/
|
||||
public function create(MenuValidate $validate)
|
||||
{
|
||||
$data = $this->checkParam($validate);
|
||||
if (!$data['pid']) $data['pid'] = 0;
|
||||
if ($data['pid'] && !$this->repository->merExists($data['pid'], $this->merchant))
|
||||
return app('json')->fail('父级分类不存在');
|
||||
$data['is_mer'] = $this->merchant;
|
||||
$this->repository->create($data);
|
||||
return app('json')->success('添加成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @param int $id id
|
||||
* @param MenuValidate $validate
|
||||
* @return mixed
|
||||
* @throws DbException
|
||||
* @author 张先生
|
||||
* @date 2020-03-30
|
||||
*/
|
||||
public function update($id, MenuValidate $validate)
|
||||
{
|
||||
$data = $this->checkParam($validate);
|
||||
if (!$data['pid']) $data['pid'] = 0;
|
||||
if (!$this->repository->merExists($id, $this->merchant))
|
||||
return app('json')->fail('数据不存在');
|
||||
if ($data['pid'] && !$this->repository->merExists($data['pid'], $this->merchant))
|
||||
return app('json')->fail('父级分类不存在');
|
||||
$this->repository->update($id, $data);
|
||||
return app('json')->success('编辑成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @throws FormBuilderException
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
public function createForm()
|
||||
{
|
||||
return app('json')->success(formToData($this->repository->menuForm($this->merchant)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws FormBuilderException
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
public function updateForm($id)
|
||||
{
|
||||
if (!$this->repository->merExists($id, $this->merchant))
|
||||
return app('json')->fail('数据不存在');
|
||||
return app('json')->success(formToData($this->repository->updateMenuForm($id, $this->merchant)));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param MenuValidate $validate 验证规则
|
||||
* @return mixed
|
||||
* @author 张先生
|
||||
* @date 2020-03-30
|
||||
*/
|
||||
private function checkParam(MenuValidate $validate)
|
||||
{
|
||||
$data = $this->request->params([['pid', 0], 'icon', 'menu_name', 'route', ['params', '[]'], 'sort', ['is_show', 0], ['is_menu', 0]]);
|
||||
if ($data['is_menu'] != 1) $validate->isAuth();
|
||||
$validate->check($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020-04-08
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if ($this->repository->pidExists($id))
|
||||
return app('json')->fail('存在下级,无法删除');
|
||||
$this->repository->delete($id, $this->merchant);
|
||||
|
||||
return app('json')->success('删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @author xaboy
|
||||
* @day 2020-04-10
|
||||
*/
|
||||
public function menus()
|
||||
{
|
||||
$pre = '/' . config('admin.' . ($this->merchant ? 'merchant' : 'admin') . '_prefix');
|
||||
$menus = $this->request->adminInfo()->level
|
||||
? $this->repository->ruleByMenuList($this->request->adminRule(), $this->merchant)
|
||||
: $this->repository->getValidMenuList($this->merchant);
|
||||
foreach ($menus as $k => $menu) {
|
||||
$menu['path'] = $pre . $menu['path'];
|
||||
$menus[$k] = $menu;
|
||||
}
|
||||
return app('json')->success(array_values(array_filter(formatCategory($menus, 'id'), function ($v) {
|
||||
return 0 == $v['pid'];
|
||||
})));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @author xaboy
|
||||
* @day 2020-04-10
|
||||
*/
|
||||
public function merchantMenus()
|
||||
{
|
||||
$pre = '/' . config('admin.supply_prefix');
|
||||
$merchant = $this->request->merchant();
|
||||
if ($this->request->adminInfo()->level) {
|
||||
$menus = $this->repository->ruleByMenuList($this->request->adminRule(), $this->merchant);
|
||||
} else {
|
||||
$menus = $merchant->type_id ? $this->repository->typesByValidMenuList($merchant->type_id) : $this->repository->getValidMenuList($this->merchant);
|
||||
}
|
||||
foreach ($menus as $k => $menu) {
|
||||
|
||||
$menu['path'] = $pre . $menu['path'];
|
||||
$menus[$k] = $menu;
|
||||
}
|
||||
return app('json')->success(array_values(array_filter(formatCategory($menus, 'id'), function ($v) {
|
||||
return 0 == $v['pid'];
|
||||
})));
|
||||
}
|
||||
}
|
174
app/controller/admin/system/auth/SupplyRole.php
Normal file
174
app/controller/admin/system/auth/SupplyRole.php
Normal file
@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\controller\admin\system\auth;
|
||||
|
||||
|
||||
use crmeb\basic\BaseController;
|
||||
use app\common\repositories\system\auth\SupplyRoleRepository;
|
||||
use app\validate\admin\RoleValidate;
|
||||
use Exception;
|
||||
use FormBuilder\Exception\FormBuilderException;
|
||||
use think\App;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\response\Json;
|
||||
|
||||
class SupplyRole extends BaseController
|
||||
{
|
||||
protected $repository;
|
||||
|
||||
public function __construct(App $app, SupplyRoleRepository $repository)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @throws FormBuilderException
|
||||
* @author xaboy
|
||||
* @day 2020-04-09
|
||||
*/
|
||||
public function createForm()
|
||||
{
|
||||
return app('json')->success(formToData($this->repository->form()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws FormBuilderException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-04-09
|
||||
*/
|
||||
public function updateForm($id)
|
||||
{
|
||||
if (!$this->repository->exists($id))
|
||||
return app('json')->fail('数据不存在');
|
||||
return app('json')->success(formToData($this->repository->updateForm(false, $id)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-04-09
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
[$page, $limit] = $this->getPage();
|
||||
return app('json')->success($this->repository->search(0, [], $page, $limit));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个
|
||||
* @param int $id
|
||||
* @return Json
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author 张先生
|
||||
* @date 2020-03-26
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
$data = $this->repository->get($id);
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020-04-09
|
||||
*/
|
||||
public function switchStatus($id)
|
||||
{
|
||||
$status = $this->request->param('status');
|
||||
if (!$this->repository->merExists(0, $id))
|
||||
return app('json')->fail('数据不存在');
|
||||
$this->repository->update($id, ['status' => $status == 1 ? 1 : 0]);
|
||||
return app('json')->success('编辑成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除单个
|
||||
* @param int $id
|
||||
* @return Json
|
||||
* @throws Exception
|
||||
* @author 张先生
|
||||
* @date 2020-03-30
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if (!$this->repository->merExists(0, $id))
|
||||
return app('json')->fail('数据不存在');
|
||||
$this->repository->delete($id);
|
||||
return app('json')->success('删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param RoleValidate $validate
|
||||
* @return mixed
|
||||
* @author 张先生
|
||||
* @date 2020-03-30
|
||||
*/
|
||||
public function create(RoleValidate $validate)
|
||||
{
|
||||
$data = $this->checkParam($validate);
|
||||
$data['mer_id'] = 0;
|
||||
$this->repository->create($data);
|
||||
return app('json')->success('添加成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @param int $id id
|
||||
* @param RoleValidate $validate
|
||||
* @return mixed
|
||||
* @throws DbException
|
||||
* @author 张先生
|
||||
* @date 2020-03-30
|
||||
*/
|
||||
public function update($id, RoleValidate $validate)
|
||||
{
|
||||
$data = $this->checkParam($validate);
|
||||
if (!$this->repository->merExists(0, $id))
|
||||
return app('json')->fail('数据不存在');
|
||||
$this->repository->update($id, $data);
|
||||
return app('json')->success('编辑成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加和修改参数验证
|
||||
* @param RoleValidate $validate 验证规则
|
||||
* @return mixed
|
||||
* @author 张先生
|
||||
* @date 2020-03-30
|
||||
*/
|
||||
private function checkParam(RoleValidate $validate)
|
||||
{
|
||||
$data = $this->request->params(['role_name', ['rules', []], ['status', 0]]);
|
||||
$validate->check($data);
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -122,7 +122,7 @@ Route::group(function () {
|
||||
//配置
|
||||
Route::group( function () {
|
||||
Route::get('config', 'supply.Common/config');
|
||||
Route::get('menus', 'admin.system.auth.Menu/supplyMenus')->append(['merchant' => 1]);
|
||||
Route::get('menus', 'admin.system.auth.SupplyMenu/Menus')->append(['merchant' => 1]);
|
||||
Route::get('logout', 'supply.system.admin.Login/logout');
|
||||
//获取版本号
|
||||
Route::get('version', 'admin.Common/version');
|
||||
|
Loading…
x
Reference in New Issue
Block a user