更新
This commit is contained in:
parent
3ded469859
commit
cf1366e68c
72
app/common/dao/store/SupplyStoreBrandDao.php
Normal file
72
app/common/dao/store/SupplyStoreBrandDao.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?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;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\SupplyStoreBrand as model;
|
||||
use crmeb\traits\CategoresDao;
|
||||
|
||||
class SupplyStoreBrandDao extends BaseDao
|
||||
{
|
||||
|
||||
use CategoresDao;
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return model::class;
|
||||
}
|
||||
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
$query = $this->getModel()::hasWhere('brandCategory',function($query){
|
||||
$query->where('is_show',1);
|
||||
});
|
||||
$query->where('StoreBrand.is_show',1);
|
||||
$list = $query->order('StoreBrand.sort DESC,StoreBrand.create_time DESC')->select()->toArray();
|
||||
array_push($list,[
|
||||
"brand_id" => 0,
|
||||
"brand_category_id" => 0,
|
||||
"brand_name" => "其他",
|
||||
"sort" => 999,
|
||||
"pic" => "",
|
||||
"is_show" => 1,
|
||||
"create_time" => "",
|
||||
]);
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
public function merFieldExists($field, $value, $except = null)
|
||||
{
|
||||
return ($this->getModel())::getDB()
|
||||
->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})
|
||||
->where($field, $value)->count() > 0;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
$query = $this->getModel()::getDB();
|
||||
if(isset($where['brand_category_id']) && $where['brand_category_id'])
|
||||
$query->where('brand_category_id',$where['brand_category_id']);
|
||||
if(isset($where['brand_name']) && $where['brand_name'])
|
||||
$query->where('brand_name','like','%'.$where['brand_name'].'%');
|
||||
if((isset($where['ids']) && $where['ids']))
|
||||
$query->where($this->getPk(),'in',$where['ids']);
|
||||
return $query->order('sort DESC,create_time desc');
|
||||
|
||||
}
|
||||
|
||||
}
|
117
app/common/dao/store/SupplyStoreCategoryDao.php
Normal file
117
app/common/dao/store/SupplyStoreCategoryDao.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\dao\store;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\SupplyStoreCategory as model;
|
||||
use crmeb\traits\CategoresDao;
|
||||
|
||||
class SupplyStoreCategoryDao extends BaseDao
|
||||
{
|
||||
|
||||
use CategoresDao;
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return model::class;
|
||||
}
|
||||
|
||||
public function getAll($mer_id = 0,$status = null, $type = 0)
|
||||
{
|
||||
return $this->getModel()::getDB()
|
||||
->where('mer_id', $mer_id)
|
||||
->where('type',$type)
|
||||
->when(($status !== null),function($query)use($status){
|
||||
$query->where($this->getStatus(),$status);
|
||||
})
|
||||
->order('sort DESC,'.$this->getPk().' DESC')
|
||||
->select()
|
||||
->append(['has_product']);
|
||||
}
|
||||
|
||||
public function findChildrenId($id)
|
||||
{
|
||||
return model::getDB()->whereLike('path', '%/'. $id . '/%')->column('store_category_id');
|
||||
}
|
||||
|
||||
public function selectChildrenId(array $ids)
|
||||
{
|
||||
if (!is_array($ids) || empty($ids)) return [];
|
||||
$query = model::getDB()->where(function($query) use($ids){
|
||||
foreach ($ids as $id) {
|
||||
$query->whereOr('path', 'like','%/'. $id . '/%');
|
||||
}
|
||||
});
|
||||
return $query->column('store_category_id');
|
||||
}
|
||||
|
||||
|
||||
public function fieldExistsList(?int $merId,$field,$value,$except = null)
|
||||
{
|
||||
return ($this->getModel()::getDB())->when($except ,function($query)use($field,$except){
|
||||
$query->where($field,'<>',$except);
|
||||
})->when(($merId !== null) ,function($query)use($merId){
|
||||
$query->where('mer_id',$merId);
|
||||
})->where($field,$value);
|
||||
|
||||
}
|
||||
|
||||
public function getTwoLevel($merId = 0)
|
||||
{
|
||||
$pid = model::getDB()->where('pid', 0)->where('is_show',1)->where('type',0)->where('mer_id', $merId)->order('sort DESC')->column('store_category_id');
|
||||
return model::getDB()->whereIn('pid', $pid)->where('is_show', 1)->where('mer_id', $merId)->limit(20)->order('sort DESC')->column('store_category_id,cate_name,pid');
|
||||
}
|
||||
|
||||
public function children($pid, $merId = 0)
|
||||
{
|
||||
return model::getDB()->where('pid', $pid)->where('mer_id', $merId)->where('is_show', 1)->order('sort DESC')->column('store_category_id,cate_name,pic');
|
||||
}
|
||||
|
||||
public function allChildren($id)
|
||||
{
|
||||
$path = model::getDB()->where('store_category_id', is_array($id) ? 'IN' : '=', $id)->where('mer_id', 0)->column('path', 'store_category_id');
|
||||
if (!count($path)) return [];
|
||||
return model::getDB()->where(function ($query) use ($path) {
|
||||
foreach ($path as $k => $v) {
|
||||
$query->whereOr('path', 'LIKE', "$v$k/%");
|
||||
}
|
||||
})->where('mer_id', 0)->order('sort DESC')->column('store_category_id');
|
||||
}
|
||||
|
||||
public function idsByAllChildren(array $ids)
|
||||
{
|
||||
$paths = model::getDB()->whereIn('store_category_id', $ids)->where('mer_id', 0)->column('path');
|
||||
if (!count($paths)) return [];
|
||||
return model::getDB()->where(function ($query) use ($paths) {
|
||||
foreach ($paths as $path) {
|
||||
$query->whereOr('path', 'LIKE', "$path%");
|
||||
}
|
||||
})->where('mer_id', 0)->order('sort DESC')->column('store_category_id');
|
||||
}
|
||||
|
||||
public function getMaxLevel($merId = null)
|
||||
{
|
||||
if($merId) return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function searchLevelAttr($query, $value)
|
||||
{
|
||||
$query->where('level', $value);
|
||||
}
|
||||
|
||||
public function clear(int $id, string $field)
|
||||
{
|
||||
$this->getModel()::getDB()->where($field, $id)->delete();
|
||||
}
|
||||
}
|
156
app/common/dao/store/order/SupplyStoreCartDao.php
Normal file
156
app/common/dao/store/order/SupplyStoreCartDao.php
Normal file
@ -0,0 +1,156 @@
|
||||
<?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\order;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\order\SupplyStoreCart;
|
||||
use app\common\model\user\UserAddress;
|
||||
use app\common\repositories\store\order\SupplyStoreCartRepository;
|
||||
use think\model\Relation;
|
||||
|
||||
class SupplyStoreCartDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return SupplyStoreCart::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @param $uid
|
||||
* @param int|null $merId
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020/6/5
|
||||
*/
|
||||
public function validIntersection(array $ids, $uid, int $merId = null): array
|
||||
{
|
||||
return SupplyStoreCart::getDB()->whereIn('cart_id', $ids)
|
||||
->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})
|
||||
->where('is_del', 0)->where('is_fail', 0)->where('is_pay', 0)->where('uid', $uid)->column('cart_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/6/1
|
||||
* @param int $uid
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAll(int $uid)
|
||||
{
|
||||
$query = ($this->getModel())::where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0])
|
||||
->with([
|
||||
'product' => function ($query) {
|
||||
$query->field('product_id,image,store_name,is_show,status,is_del,unit_name,price,mer_status,is_used,product_type,once_max_count,once_min_count,pay_limit,mer_svip_status,svip_price_type');
|
||||
},
|
||||
'productAttr' => function ($query) {
|
||||
$query->field('product_id,stock,price,unique,sku,image,svip_price');
|
||||
},
|
||||
'merchant' => function ($query) {
|
||||
$query->field('mer_id,mer_name,mer_state,mer_avatar,is_trader,type_id')->with(['type_name']);
|
||||
}
|
||||
])->limit(SupplyStoreCartRepository::CART_LIMIT_COUNT)->select();
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function cartIbByData(array $ids, int $uid, ?UserAddress $address)
|
||||
{
|
||||
return SupplyStoreCart::getDb()->where('uid', $uid)->with([
|
||||
'product' => function (Relation $query) use ($address) {
|
||||
$query->field('product_id,cate_id,image,store_name,is_show,status,is_del,unit_name,price,mer_status,temp_id,give_coupon_ids,is_gift_bag,is_used,product_type,old_product_id,integral_rate,delivery_way,delivery_free,type,extend,pay_limit,once_max_count,once_min_count,mer_svip_status,svip_price_type,refund_switch,mer_form_id');
|
||||
if ($address) {
|
||||
$cityIds = array_filter([$address->province_id, $address->city_id, $address->district_id, $address->street_id]);
|
||||
$query->with([
|
||||
'temp' => [
|
||||
'region' => function (Relation $query) use ($cityIds) {
|
||||
$query->where(function ($query) use ($cityIds) {
|
||||
foreach ($cityIds as $v) {
|
||||
$query->whereOr('city_id', 'like', "%/{$v}/%");
|
||||
}
|
||||
$query->whereOr('city_id', '0');
|
||||
})->order('shipping_template_region_id DESC')->withLimit(1);
|
||||
},
|
||||
'undelives' => function ($query) use ($cityIds) {
|
||||
foreach ($cityIds as $v) {
|
||||
$query->whereOr('city_id', 'like', "%/{$v}/%");
|
||||
}
|
||||
},
|
||||
'free' => function (Relation $query) use ($cityIds) {
|
||||
foreach ($cityIds as $v) {
|
||||
$query->whereOr('city_id', 'like', "%/{$v}/%");
|
||||
}
|
||||
$query->order('shipping_template_free_id DESC')->withLimit(1);
|
||||
}]]);
|
||||
}
|
||||
},
|
||||
'productAttr' => function (Relation $query) {
|
||||
$query->field('value_id,image,extension_one,extension_two,product_id,stock,price,unique,sku,volume,weight,ot_price,cost,svip_price')
|
||||
->append(['bc_extension_one', 'bc_extension_two']);
|
||||
},
|
||||
'merchant' => function (Relation $query) use ($uid) {
|
||||
$query->field('mer_id,mer_name,mer_state,mer_avatar,delivery_way,commission_rate,category_id')
|
||||
->with([
|
||||
'coupon' => function ($query) use ($uid) {
|
||||
$query->where('uid', $uid);
|
||||
},
|
||||
'config' => function ($query) {
|
||||
$query->whereIn('config_key', ['mer_integral_status', 'mer_integral_rate', 'mer_store_stock', 'mer_take_status', 'mer_take_name', 'mer_take_phone', 'mer_take_address', 'mer_take_location', 'mer_take_day', 'mer_take_time']);
|
||||
},
|
||||
'merchantCategory'
|
||||
]);
|
||||
}])->whereIn('cart_id', $ids)->order('product_type DESC,cart_id DESC')->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $cartIds
|
||||
* @param int $uid
|
||||
* @author Qinii
|
||||
*/
|
||||
public function batchDelete(array $cartIds, int $uid)
|
||||
{
|
||||
return ($this->getModel()::getDB())->where('uid', $uid)->whereIn('cart_id', $cartIds)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $uid
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
*/
|
||||
public function getCartCount(int $uid)
|
||||
{
|
||||
$data = ($this->getModel()::getDB())->where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0])->field('SUM(cart_num) as count')->select();
|
||||
$data[0]['count'] = $data[0]['count'] ? $data[0]['count'] : 0;
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $source
|
||||
* @param array|null $ids
|
||||
* @author xaboy
|
||||
* @day 2020/8/31
|
||||
*/
|
||||
public function getSourcePayInfo($source, ?array $ids = null)
|
||||
{
|
||||
return SupplyStoreCart::getDB()->alias('A')->where('A.source', $source)->where('A.is_pay', 1)->when($ids, function ($query, $ids) {
|
||||
$query->whereIn('A.source_id', $ids);
|
||||
})->leftJoin('SupplyStoreOrderProduct B', 'A.cart_id = B.cart_id')
|
||||
->field('sum(B.product_num) as pay_num,sum(B.product_price) as pay_price,A.source_id')->group('A.source_id')->select();
|
||||
}
|
||||
}
|
968
app/common/dao/store/order/SupplyStoreOrderDao.php
Normal file
968
app/common/dao/store/order/SupplyStoreOrderDao.php
Normal file
@ -0,0 +1,968 @@
|
||||
<?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\order;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\order\SupplyStoreOrder;
|
||||
use app\common\model\store\order\SupplyStoreOrderProduct;
|
||||
use app\common\model\store\order\SupplyStoreOrderStatus;
|
||||
use app\common\model\user\User;
|
||||
// use app\common\repositories\store\product\ProductAssistSetRepository;
|
||||
// use app\common\repositories\store\product\ProductGroupBuyingRepository;
|
||||
use think\db\BaseQuery;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* Class SupplyStoreOrderDao
|
||||
* @package app\common\dao\store\order
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
class SupplyStoreOrderDao extends BaseDao
|
||||
{
|
||||
//订单状态(0:待发货;1:待收货;2:待评价;3:已完成; 9: 拼团中 10: 待付尾款 11:尾款超时未付 -1:已退款)
|
||||
const ORDER_STATUS_BE_SHIPPED = 0;
|
||||
const ORDER_STATUS_BE_RECEIVE = 1;
|
||||
const ORDER_STATUS_REPLY = 2;
|
||||
const ORDER_STATUS_SUCCESS = 3;
|
||||
const ORDER_STATUS_SPELL = 9;
|
||||
const ORDER_STATUS_TAIL = 10;
|
||||
const ORDER_STATUS_TAIL_FAIL = 11;
|
||||
const ORDER_STATUS_REFUND = -1;
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return SupplyStoreOrder::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @param int $sysDel
|
||||
* @return BaseQuery
|
||||
* @author xaboyCRMEB
|
||||
* @day 2020/6/16
|
||||
*/
|
||||
public function search(array $where, $sysDel = 0)
|
||||
{
|
||||
$query = SupplyStoreOrder::hasWhere('merchant', function ($query) use ($where) {
|
||||
if (isset($where['is_trader']) && $where['is_trader'] !== '') {
|
||||
$query->where('is_trader', $where['is_trader']);
|
||||
}
|
||||
$query->where('is_del', 0);
|
||||
});
|
||||
$query->where('SupplyStoreOrder.activity_type', '<>', 20);
|
||||
$query->when(($sysDel !== null), function ($query) use ($sysDel) {
|
||||
$query->where('is_system_del', $sysDel);
|
||||
});
|
||||
$query->when(isset($where['order_type']) && $where['order_type'] >= 0 && $where['order_type'] !== '', function ($query) use ($where) {
|
||||
if ($where['order_type'] == 2) {
|
||||
$query->where('is_virtual', 1);
|
||||
} else if ($where['order_type'] == 3) { // 卡密商品
|
||||
$query->where('is_virtual', 2);
|
||||
} else {
|
||||
$query->where('order_type', $where['order_type']);
|
||||
}
|
||||
});
|
||||
$query->when(isset($where['activity_type']) && $where['activity_type'] !== '', function ($query) use ($where) {
|
||||
$query->where('SupplyStoreOrder.activity_type', $where['activity_type']);
|
||||
})
|
||||
->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
|
||||
switch ($where['status']) {
|
||||
case 0 :
|
||||
$query->whereIn('SupplyStoreOrder.status', [0, 9]);
|
||||
break;
|
||||
case -2 :
|
||||
$query->where('paid', 1)->whereNotIn('SupplyStoreOrder.status', [10, 11]);
|
||||
break;
|
||||
case 10 :
|
||||
$query->where('paid', 1)->whereIn('SupplyStoreOrder.status', [10, 11]);
|
||||
break;
|
||||
default:
|
||||
$query->where('SupplyStoreOrder.status', $where['status']);
|
||||
break;
|
||||
}
|
||||
})
|
||||
->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
|
||||
$query->where('uid', $where['uid']);
|
||||
})
|
||||
->when(isset($where['is_spread']) && $where['is_spread'] !== '', function ($query) use ($where) {
|
||||
if ($where['is_spread']) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('SupplyStoreOrder.spread_uid', '>', 0)->whereOr('SupplyStoreOrder.top_uid', '>', 0);
|
||||
});
|
||||
}
|
||||
})
|
||||
->when(isset($where['is_user']) && $where['is_user'] !== '', function ($query) use ($where) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('order_type', 0)->whereOr(function ($query) {
|
||||
$query->where('order_type', 1)->where('main_id', 0);
|
||||
});
|
||||
});
|
||||
})
|
||||
//待核销订单
|
||||
->when(isset($where['is_verify']) && $where['is_verify'], function ($query) use ($where) {
|
||||
$query->where('SupplyStoreOrder.order_type', 1)->where('SupplyStoreOrder.status', 0)->where('paid', 1);
|
||||
})
|
||||
->when(isset($where['pay_type']) && $where['pay_type'] !== '', function ($query) use ($where) {
|
||||
if (is_int($where['pay_type'])) {
|
||||
$query->where('SupplyStoreOrder.pay_type', $where['pay_type']);
|
||||
} else {
|
||||
$query->whereIn('SupplyStoreOrder.pay_type', $where['pay_type']);
|
||||
}
|
||||
})
|
||||
->when(isset($where['order_ids']) && $where['order_ids'] !== '', function ($query) use ($where) {
|
||||
$query->whereIn('order_id', $where['order_ids']);
|
||||
})
|
||||
->when(isset($where['order_id']) && $where['order_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('order_id', $where['order_id']);
|
||||
})
|
||||
->when(isset($where['take_order']) && $where['take_order'] != '', function ($query) use ($where) {
|
||||
$query->where('order_type', 1)->whereNotNull('verify_time');
|
||||
})
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('SupplyStoreOrder.mer_id', $where['mer_id']);
|
||||
})
|
||||
->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
|
||||
getModelTime($query, $where['date'], 'SupplyStoreOrder.create_time');
|
||||
})
|
||||
->when(isset($where['verify_date']) && $where['verify_date'] !== '', function ($query) use ($where) {
|
||||
getModelTime($query, $where['verify_date'], 'verify_time');
|
||||
})
|
||||
->when(isset($where['order_sn']) && $where['order_sn'] !== '', function ($query) use ($where) {
|
||||
$query->where('order_sn', 'like', '%' . $where['order_sn'] . '%');
|
||||
})
|
||||
->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
|
||||
$query->where('SupplyStoreOrder.paid', $where['paid']);
|
||||
})
|
||||
->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
|
||||
$query->where('SupplyStoreOrder.is_del', $where['is_del']);
|
||||
})
|
||||
->when(isset($where['service_id']) && $where['service_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('service_id', $where['service_id']);
|
||||
})
|
||||
->when(isset($where['username']) && $where['username'] !== '', function ($query) use ($where) {
|
||||
$query->join('User U', 'SupplyStoreOrder.uid = U.uid')
|
||||
->where(function ($query) use ($where) {
|
||||
$query->where('nickname', 'like', "%{$where['username']}%")
|
||||
->whereOr('phone', 'like', "%{$where['username']}%")
|
||||
->whereOr('SupplyStoreOrder.user_phone', 'like', "%{$where['username']}%");
|
||||
});
|
||||
})
|
||||
->when(isset($where['spread_name']) && $where['spread_name'] !== '', function ($query) use ($where) {
|
||||
$uid = User::where('nickname', 'like', "%{$where['spread_name']}%")->column('uid');
|
||||
$query->whereIn('SupplyStoreOrder.spread_uid', $uid);
|
||||
})
|
||||
->when(isset($where['top_spread_name']) && $where['top_spread_name'] !== '', function ($query) use ($where) {
|
||||
$uid = User::where('nickname', 'like', "%{$where['top_spread_name']}%")->column('uid');
|
||||
$query->whereIn('SupplyStoreOrder.top_uid', $uid);
|
||||
})
|
||||
->when(isset($where['store_name']) && $where['store_name'] !== '', function ($query) use ($where) {
|
||||
$orderId = SupplyStoreOrderProduct::alias('op')
|
||||
->join('supplyStoreProduct sp', 'op.product_id = sp.product_id')
|
||||
->whereLike('store_name', "%{$where['store_name']}%")
|
||||
->when((isset($where['sp.mer_id']) && $where['mer_id'] !== ''), function ($query) use ($where) {
|
||||
$query->where('mer_id', $where['mer_id']);
|
||||
})->column('order_id');
|
||||
$query->whereIn('order_id', $orderId ?: '');
|
||||
})
|
||||
->when(isset($where['search']) && $where['search'] !== '', function ($query) use ($where) {
|
||||
$orderId = SupplyStoreOrderProduct::alias('op')
|
||||
->join('supplyStoreProduct sp', 'op.product_id = sp.product_id')
|
||||
->whereLike('store_name', "%{$where['search']}%")
|
||||
->when((isset($where['sp.mer_id']) && $where['mer_id'] !== ''), function ($query) use ($where) {
|
||||
$query->where('mer_id', $where['mer_id']);
|
||||
})->column('order_id');
|
||||
$query->where(function ($query) use ($orderId, $where) {
|
||||
$query->whereIn('order_id', $orderId ? $orderId : '')
|
||||
->whereOr('order_sn', 'like', "%{$where['search']}%")
|
||||
->whereOr('SupplyStoreOrder.user_phone', 'like', "%{$where['search']}%");
|
||||
});
|
||||
})
|
||||
->when(isset($where['group_order_sn']) && $where['group_order_sn'] !== '', function ($query) use ($where) {
|
||||
$query->join('StoreGroupOrder GO', 'SupplyStoreOrder.group_order_id = GO.group_order_id')->where('group_order_sn', $where['group_order_sn']);
|
||||
})
|
||||
->when(isset($where['keywords']) && $where['keywords'] !== '', function ($query) use ($where) {
|
||||
$query->where(function ($query) use ($where) {
|
||||
$query->whereLike('SupplyStoreOrder.real_name|SupplyStoreOrder.user_phone|order_sn', "%" . $where['keywords'] . "%");
|
||||
});
|
||||
})
|
||||
->when(isset($where['filter_delivery']) && $where['filter_delivery'] !== '', function ($query) use ($where) {
|
||||
//1 快递 2 配送 3 虚拟
|
||||
//按发货方式:1快递订单、2配送订单、4核销订单、3虚拟发货、6自动发货
|
||||
switch ($where['filter_delivery']) {
|
||||
case 1:
|
||||
$query->whereIn('delivery_type', '1,4');
|
||||
break;
|
||||
case 2:
|
||||
$query->whereIn('delivery_type', '2,5');
|
||||
break;
|
||||
case 3:
|
||||
$query->whereIn('delivery_type', '3');
|
||||
break;
|
||||
case 4:
|
||||
$query->where('order_type', 1);
|
||||
break;
|
||||
case 6:
|
||||
$query->whereIn('delivery_type', '6');
|
||||
break;
|
||||
}
|
||||
})
|
||||
->when(isset($where['filter_product']) && $where['filter_product'] !== '', function ($query) use ($where) {
|
||||
// 1 实物商品、2虚拟商品、3卡密商品
|
||||
switch ($where['filter_product']) {
|
||||
case 1:
|
||||
$query->where('is_virtual', 0);
|
||||
break;
|
||||
case 2:
|
||||
$query->where('is_virtual', 1);
|
||||
break;
|
||||
case 3:
|
||||
$query->where('is_virtual', 2);
|
||||
break;
|
||||
}
|
||||
})
|
||||
->order('SupplyStoreOrder.create_time DESC');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function searchAll(array $where, $sysDel = 0, $is_points = null)
|
||||
{
|
||||
$query = SupplyStoreOrder::getDB()->alias('SupplyStoreOrder');
|
||||
$query->when(($sysDel !== null), function ($query) use ($sysDel) {
|
||||
$query->where('is_system_del', $sysDel);
|
||||
});
|
||||
$query->when(!is_null($is_points), function ($query) use ($is_points) {
|
||||
if ($is_points) {
|
||||
$query->where('activity_type', 20);
|
||||
} else {
|
||||
$query->where('activity_type', '<>', 20);
|
||||
}
|
||||
});
|
||||
$query->when(isset($where['order_type']) && $where['order_type'] >= 0 && $where['order_type'] !== '', function ($query) use ($where) {
|
||||
if ($where['order_type'] == 2) {
|
||||
$query->where('is_virtual', 1);
|
||||
} else if ($where['order_type'] == 0) { //实体发货订单
|
||||
$query->where('order_type', 0)->where('is_virtual', 0);
|
||||
} else if ($where['order_type'] == 3) { //发货订单
|
||||
$query->where('order_type', 0);
|
||||
} else {
|
||||
$query->where('order_type', $where['order_type']);
|
||||
}
|
||||
});
|
||||
$query->when(isset($where['activity_type']) && $where['activity_type'] !== '', function ($query) use ($where) {
|
||||
$query->where('activity_type', $where['activity_type']);
|
||||
})
|
||||
->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
|
||||
switch ($where['status']) {
|
||||
case 0 :
|
||||
$query->whereIn('SupplyStoreOrder.status', [0, 9])->where('paid', 1)->where('is_del', 0);
|
||||
break;
|
||||
case -2 :
|
||||
$query->where('paid', 1)->whereNotIn('SupplyStoreOrder.status', [10, 11])->where('is_del', 0);
|
||||
break;
|
||||
case -3 :
|
||||
$query->where('paid', 0)->where('is_del', 0);
|
||||
break;
|
||||
case 10 :
|
||||
$query->where('paid', 1)->whereIn('SupplyStoreOrder.status', [10, 11])->where('is_del', 0);
|
||||
break;
|
||||
default:
|
||||
$query->where('SupplyStoreOrder.status', $where['status'])->where('is_del', 0);
|
||||
break;
|
||||
}
|
||||
|
||||
})
|
||||
->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
|
||||
$query->where('uid', $where['uid']);
|
||||
})
|
||||
->when(isset($where['is_user']) && $where['is_user'] !== '', function ($query) use ($where) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('order_type', 0)->whereOr(function ($query) {
|
||||
$query->where('order_type', 1)->where('main_id', 0);
|
||||
});
|
||||
});
|
||||
})
|
||||
//待核销订单
|
||||
->when(isset($where['is_verify']) && $where['is_verify'], function ($query) use ($where) {
|
||||
$query->where('SupplyStoreOrder.order_type', 1)->where('SupplyStoreOrder.status', 0);
|
||||
})
|
||||
->when(isset($where['pay_type']) && $where['pay_type'] !== '', function ($query) use ($where) {
|
||||
$query->where('SupplyStoreOrder.pay_type', $where['pay_type']);
|
||||
})
|
||||
->when(isset($where['order_ids']) && $where['order_ids'] !== '', function ($query) use ($where) {
|
||||
$query->whereIn('order_id', $where['order_ids']);
|
||||
})
|
||||
->when(isset($where['order_id']) && $where['order_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('order_id', $where['order_id']);
|
||||
})
|
||||
->when(isset($where['take_order']) && $where['take_order'] != '', function ($query) use ($where) {
|
||||
$query->where('order_type', 1)->whereNotNull('verify_time');
|
||||
})
|
||||
->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
|
||||
getModelTime($query, $where['date'], 'SupplyStoreOrder.create_time');
|
||||
})
|
||||
->when(isset($where['order_sn']) && $where['order_sn'] !== '', function ($query) use ($where) {
|
||||
$query->where('order_sn', 'like', '%' . $where['order_sn'] . '%');
|
||||
})
|
||||
->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
|
||||
$query->where('SupplyStoreOrder.paid', $where['paid']);
|
||||
})
|
||||
->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
|
||||
$query->where('SupplyStoreOrder.is_del', $where['is_del']);
|
||||
})
|
||||
->when(isset($where['service_id']) && $where['service_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('service_id', $where['service_id']);
|
||||
})
|
||||
->when(isset($where['username']) && $where['username'] !== '', function ($query) use ($where) {
|
||||
$query->join('User U', 'SupplyStoreOrder.uid = U.uid')
|
||||
->where(function ($query) use ($where) {
|
||||
$query->where('nickname', 'like', "%{$where['username']}%")
|
||||
->whereOr('phone', 'like', "%{$where['username']}%")
|
||||
->whereOr('user_phone', 'like', "%{$where['username']}%");
|
||||
});
|
||||
})
|
||||
->when(isset($where['nickname']) && $where['nickname'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('SupplyStoreOrder.real_name', "%" . $where['nickname'] . "%");
|
||||
})
|
||||
->when(isset($where['phone']) && $where['phone'] !== '', function ($query) use ($where) {
|
||||
$query->join('User U', 'SupplyStoreOrder.uid = U.uid')->where('phone', 'like', "%{$where['phone']}%");
|
||||
})
|
||||
->when(isset($where['store_name']) && $where['store_name'] !== '', function ($query) use ($where) {
|
||||
$orderId = SupplyStoreOrderProduct::alias('op')
|
||||
->join('supplyStoreProduct sp', 'op.product_id = sp.product_id')
|
||||
->whereLike('store_name', "%{$where['store_name']}%")
|
||||
->when((isset($where['sp.mer_id']) && $where['mer_id'] !== ''), function ($query) use ($where) {
|
||||
$query->where('mer_id', $where['mer_id']);
|
||||
})->column('order_id');
|
||||
$query->whereIn('order_id', $orderId ?: '');
|
||||
})
|
||||
->when(isset($where['search']) && $where['search'] !== '', function ($query) use ($where) {
|
||||
$orderId = SupplyStoreOrderProduct::alias('op')
|
||||
->join('supplyStoreProduct sp', 'op.product_id = sp.product_id')
|
||||
->whereLike('store_name', "%{$where['search']}%")
|
||||
->when((isset($where['sp.mer_id']) && $where['mer_id'] !== ''), function ($query) use ($where) {
|
||||
$query->where('mer_id', $where['mer_id']);
|
||||
})->column('order_id');
|
||||
$query->where(function ($query) use ($orderId, $where) {
|
||||
$query->whereIn('order_id', $orderId ? $orderId : '')
|
||||
->whereOr('order_sn', 'like', "%{$where['search']}%")
|
||||
->whereOr('user_phone', 'like', "%{$where['search']}%");
|
||||
});
|
||||
})
|
||||
->when(isset($where['product_id']) && $where['product_id'] !== '', function ($query) use ($where) {
|
||||
$orderId = SupplyStoreOrderProduct::alias('op')
|
||||
->join('supplyStoreProduct sp', 'op.product_id = sp.product_id')
|
||||
->where('sp.product_id', $where['product_id'])
|
||||
->column('order_id');
|
||||
$query->whereIn('order_id', $orderId ? $orderId : '');
|
||||
})
|
||||
->when(isset($where['group_order_sn']) && $where['group_order_sn'] !== '', function ($query) use ($where) {
|
||||
$query->join('StoreGroupOrder GO', 'SupplyStoreOrder.group_order_id = GO.group_order_id')->where('group_order_sn', $where['group_order_sn']);
|
||||
})
|
||||
->when(isset($where['keywords']) && $where['keywords'] !== '', function ($query) use ($where) {
|
||||
$query->where(function ($query) use ($where) {
|
||||
$query->whereLike('SupplyStoreOrder.real_name|SupplyStoreOrder.user_phone|order_sn', "%" . $where['keywords'] . "%");
|
||||
});
|
||||
})
|
||||
->order('SupplyStoreOrder.create_time DESC');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $uid
|
||||
* @return array|Model|null
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020/6/11
|
||||
*/
|
||||
public function userOrder($id, $uid)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->where('order_id', $id)->where('uid', $uid)->where('is_del', 0)->where('paid', 1)->where('is_system_del', 0)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @param $ids
|
||||
* @return BaseQuery
|
||||
* @author xaboy
|
||||
* @day 2020/6/26
|
||||
*/
|
||||
public function usersOrderQuery(array $where, $ids, $uid)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->where(function ($query) use ($uid, $ids) {
|
||||
$query->whereIn('uid', $ids)
|
||||
->whereOr(function ($query) use ($uid) {
|
||||
if ($uid) {
|
||||
$query->where('uid', $uid)->where('is_selfbuy', 1);
|
||||
}
|
||||
});
|
||||
})->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
|
||||
getModelTime($query, $where['date'], 'pay_time');
|
||||
})->when(isset($where['create_time']) && $where['create_time'] !== '', function ($query) use ($where) {
|
||||
getModelTime($query, $where['create_time'], 'create_time');
|
||||
})->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
|
||||
$_uid = User::where('nickname', 'like', "%{$where['keyword']}%")->column('uid');
|
||||
$orderId = SupplyStoreOrderProduct::alias('op')
|
||||
->join('supplyStoreProduct sp', 'op.product_id = sp.product_id')
|
||||
->whereLike('store_name', "%{$where['keyword']}%")
|
||||
->column('order_id');
|
||||
$query->where(function ($query) use ($orderId, $where, $_uid) {
|
||||
$query->whereLike('order_id|order_sn', "%{$where['keyword']}%")->whereOr('order_id', 'in', $orderId)->whereOr('uid', 'in', $_uid);
|
||||
});
|
||||
})->where('paid', 1)->order('pay_time DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $field
|
||||
* @param $value
|
||||
* @param int|null $except
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020/6/11
|
||||
*/
|
||||
public function fieldExists($field, $value, ?int $except = null): bool
|
||||
{
|
||||
return ($this->getModel()::getDB())->when($except, function ($query) use ($field, $except) {
|
||||
$query->where($field, '<>', $except);
|
||||
})->where($field, $value)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @author xaboy
|
||||
* @day 2020/6/12
|
||||
*/
|
||||
public function getMerId($id)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->where('order_id', $id)->value('mer_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @return bool
|
||||
* @author Qinii
|
||||
* @day 2020-06-12
|
||||
*/
|
||||
public function merFieldExists(array $where)
|
||||
{
|
||||
return ($this->getModel()::getDB())->where($where)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param $reconciliation_id
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2020-06-15
|
||||
*/
|
||||
public function reconciliationUpdate($reconciliation_id)
|
||||
{
|
||||
return ($this->getModel()::getDB())->whereIn('reconciliation_id', $reconciliation_id)->update(['reconciliation_id' => 0]);
|
||||
}
|
||||
|
||||
public function dayOrderNum($day, $merId = null)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->where('paid', 1)->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->when($day, function ($query, $day) {
|
||||
getModelTime($query, $day, 'pay_time');
|
||||
})->count();
|
||||
}
|
||||
|
||||
public function dayOrderPrice($day, $merId = null)
|
||||
{
|
||||
return getModelTime(SupplyStoreOrder::getDB()->where('paid', 1)->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
}), $day, 'pay_time')->sum('pay_price');
|
||||
}
|
||||
|
||||
public function dateOrderPrice($date, $merId = null)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->where('paid', 1)->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->sum('pay_price');
|
||||
}
|
||||
|
||||
public function dateOrderNum($date, $merId = null)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->where('paid', 1)->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->count();
|
||||
}
|
||||
|
||||
public function dayOrderUserNum($day, $merId = null)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->where('paid', 1)->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->when($day, function ($query, $day) {
|
||||
getModelTime($query, $day, 'pay_time');
|
||||
})->group('uid')->count();
|
||||
}
|
||||
|
||||
public function orderUserNum($date, $paid = null, $merId = null)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->when($paid, function ($query, $paid) {
|
||||
$query->where('paid', $paid);
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->when($date, function ($query, $date) use ($paid) {
|
||||
if (!$paid) {
|
||||
getModelTime($query, $date);
|
||||
} else
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->group('uid')->count();
|
||||
}
|
||||
|
||||
public function orderUserGroup($date, $paid = null, $merId = null)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->when($paid, function ($query, $paid) {
|
||||
$query->where('paid', $paid);
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->group('uid')->field(Db::raw('uid,sum(pay_price) as pay_price,count(order_id) as total'))->select();
|
||||
}
|
||||
|
||||
public function oldUserNum(array $ids, $merId = null)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->whereIn('uid', $ids)->where('paid', 1)->group('uid')->count();
|
||||
}
|
||||
|
||||
public function oldUserIds(array $ids, $merId = null)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->whereIn('uid', $ids)->where('paid', 1)->group('uid')->column('uid');
|
||||
}
|
||||
|
||||
public function orderPrice($date, $paid = null, $merId = null)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->when($paid, function ($query, $paid) {
|
||||
$query->where('paid', $paid);
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->when($date, function ($query, $date) use ($paid) {
|
||||
if (!$paid) {
|
||||
$query->where(function ($query) use ($date) {
|
||||
$query->where(function ($query) use ($date) {
|
||||
$query->where('paid', 1);
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->whereOr(function ($query) use ($date) {
|
||||
$query->where('paid', 0);
|
||||
getModelTime($query, $date);
|
||||
});
|
||||
});
|
||||
} else
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->sum('pay_price');
|
||||
}
|
||||
|
||||
public function orderGroupNum($date, $merId = null)
|
||||
{
|
||||
$field = Db::raw('sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,pay_time,from_unixtime(unix_timestamp(pay_time),\'%m-%d\') as `day`');
|
||||
if ($date == 'year') {
|
||||
$field = Db::raw('sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,pay_time,from_unixtime(unix_timestamp(pay_time),\'%m\') as `day`');
|
||||
}
|
||||
$query = SupplyStoreOrder::getDB()->field($field)
|
||||
->where('paid', 1)->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
});
|
||||
return $query->order('pay_time ASC')->group('day')->select();
|
||||
}
|
||||
|
||||
public function orderGroupNumPage($where, $page, $limit, $merId = null)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->when(isset($where['dateRange']), function ($query) use ($where) {
|
||||
getModelTime($query, date('Y/m/d 00:00:00', $where['dateRange']['start']) . '-' . date('Y/m/d 00:00:00', $where['dateRange']['stop']), 'pay_time');
|
||||
})->field(Db::raw('sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,pay_time,from_unixtime(unix_timestamp(pay_time),\'%m-%d\') as `day`'))
|
||||
->where('paid', 1)->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->order('pay_time DESC')->page($page, $limit)->group('day')->select();
|
||||
}
|
||||
|
||||
public function dayOrderPriceGroup($date, $merId = null)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->field(Db::raw('sum(pay_price) as price, from_unixtime(unix_timestamp(pay_time),\'%H:%i\') as time'))
|
||||
->where('paid', 1)->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->group('time')->select();
|
||||
}
|
||||
|
||||
public function dayOrderNumGroup($date, $merId = null)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->field(Db::raw('count(*) as total, from_unixtime(unix_timestamp(pay_time),\'%H:%i\') as time'))
|
||||
->where('paid', 1)->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->group('time')->select();
|
||||
}
|
||||
|
||||
public function dayOrderUserGroup($date, $merId = null)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->field(Db::raw('count(DISTINCT uid) as total, from_unixtime(unix_timestamp(pay_time),\'%H:%i\') as time'))
|
||||
->where('paid', 1)->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->group('time')->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间到指定时间的支付金额 管理员
|
||||
* @param string $start 开始时间
|
||||
* @param string $stop 结束时间
|
||||
* @return mixed
|
||||
*/
|
||||
public function chartTimePrice($start, $stop, $merId = null)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->where('paid', 1)
|
||||
->where('pay_time', '>=', $start)
|
||||
->where('pay_time', '<', $stop)
|
||||
->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})
|
||||
->field('sum(pay_price) as num,FROM_UNIXTIME(unix_timestamp(pay_time), \'%Y-%m-%d\') as time')
|
||||
->group('time')
|
||||
->order('pay_time ASC')->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $date
|
||||
* @param null $merId
|
||||
* @return mixed
|
||||
*/
|
||||
public function chartTimeNum($date, $merId = null)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->where('paid', 1)->when($date, function ($query) use ($date) {
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->field('count(order_id) as num,FROM_UNIXTIME(unix_timestamp(pay_time), \'%Y-%m-%d\') as time')
|
||||
->group('time')
|
||||
->order('pay_time ASC')->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $end
|
||||
* @return mixed
|
||||
* @author xaboy
|
||||
* @day 2020/9/16
|
||||
*/
|
||||
public function getFinishTimeoutIds($end)
|
||||
{
|
||||
return SupplyStoreOrderStatus::getDB()->alias('A')->leftJoin('SupplyStoreOrder B', 'A.order_id = B.order_id')
|
||||
->where('A.change_type', 'take')
|
||||
->where('A.change_time', '<', $end)->where('B.paid', 1)->where('B.status', 2)
|
||||
->column('A.order_id');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO 参与人数
|
||||
* @param array $data
|
||||
* @param int|null $uid
|
||||
* @return BaseQuery
|
||||
* @author Qinii
|
||||
* @day 2020-11-11
|
||||
*/
|
||||
public function getTattendCount(array $data, ?int $uid)
|
||||
{
|
||||
$query = SupplyStoreOrder::hasWhere('orderProduct', function ($query) use ($data, $uid) {
|
||||
$query->when(isset($data['activity_id']), function ($query) use ($data) {
|
||||
$query->where('activity_id', $data['activity_id']);
|
||||
})
|
||||
->when(isset($data['product_sku']), function ($query) use ($data) {
|
||||
$query->where('product_sku', $data['product_sku']);
|
||||
})
|
||||
->when(isset($data['product_id']), function ($query) use ($data) {
|
||||
$query->where('product_id', $data['product_id']);
|
||||
})
|
||||
// ->when(isset($data['exsits_id']), function ($query) use ($data) {
|
||||
// switch ($data['product_type']) {
|
||||
// case 3:
|
||||
// $make = app()->make(ProductAssistSetRepository::class);
|
||||
// $id = 'product_assist_id';
|
||||
// break;
|
||||
// case 4:
|
||||
// $make = app()->make(ProductGroupBuyingRepository::class);
|
||||
// $id = 'product_group_id';
|
||||
// break;
|
||||
// }
|
||||
// $where = [$id => $data['exsits_id']];
|
||||
// $activity_id = $make->getSearch($where)->column($make->getPk());
|
||||
// if ($activity_id) {
|
||||
// $id = array_unique($activity_id);
|
||||
// $query->where('activity_id', 'in', $id);
|
||||
// } else {
|
||||
// $query->where('activity_id', '<', 0);
|
||||
// }
|
||||
// })
|
||||
->where('product_type', $data['product_type']);
|
||||
if ($uid) $query->where('uid', $uid);
|
||||
});
|
||||
$query->where('activity_type', $data['product_type']);
|
||||
switch ($data['product_type']) {
|
||||
case 0:
|
||||
$query->where(function ($query) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('paid', 1);
|
||||
})->whereOr(function ($query) {
|
||||
$query->where('paid', 0)->where('is_del', 0);
|
||||
});
|
||||
});
|
||||
break;
|
||||
case 1: //秒杀
|
||||
$query->where(function ($query) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('paid', 1);
|
||||
})->whereOr(function ($query) {
|
||||
$query->where('paid', 0)->where('is_del', 0);
|
||||
});
|
||||
})->when(isset($data['day']), function ($query) use ($data) {
|
||||
$query->whereDay('SupplyStoreOrder.create_time', $data['day']);
|
||||
});
|
||||
break;
|
||||
case 2: //预售
|
||||
|
||||
/**
|
||||
* 第一阶段参与人数:所有人
|
||||
* 第二阶段参与人数:支付了第一阶段
|
||||
*/
|
||||
//第二阶段
|
||||
if ($data['type'] == 1) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('paid', 1)->whereOr(function ($query) {
|
||||
$query->where('paid', 0)->where('is_del', 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
if ($data['type'] == 2) $query->where('paid', 1)->where('status', 'in', [0, 1, 2, 3, -1]);
|
||||
break;
|
||||
case 3: //助力
|
||||
$query->where(function ($query) {
|
||||
$query->where('paid', 1)->whereOr(function ($query) {
|
||||
$query->where('paid', 0)->where('is_del', 0);
|
||||
});
|
||||
});
|
||||
break;
|
||||
case 4: //
|
||||
$query->where(function ($query) {
|
||||
$query->where('paid', 1)->whereOr(function ($query) {
|
||||
$query->where('paid', 0)->where('is_del', 0);
|
||||
})
|
||||
->where('status', '>', -1);
|
||||
});
|
||||
break;
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 未使用
|
||||
* TODO 成功支付人数
|
||||
* @param int $productType
|
||||
* @param int $activityId
|
||||
* @param int|null $uid
|
||||
* @param int|null $status
|
||||
* @author Qinii
|
||||
* @day 2020-10-30
|
||||
*/
|
||||
public function getTattendSuccessCount($data, ?int $uid)
|
||||
{
|
||||
$query = SupplyStoreOrder::hasWhere('orderProduct', function ($query) use ($data, $uid) {
|
||||
$query->when(isset($data['activity_id']), function ($query) use ($data) {
|
||||
$query->where('activity_id', $data['activity_id']);
|
||||
})
|
||||
->when(isset($data['product_sku']), function ($query) use ($data) {
|
||||
$query->where('product_sku', $data['product_sku']);
|
||||
})
|
||||
->when(isset($data['product_id']), function ($query) use ($data) {
|
||||
$query->where('product_id', $data['product_id']);
|
||||
})
|
||||
// ->when(isset($data['exsits_id']), function ($query) use ($data) {
|
||||
// switch ($data['product_type']) {
|
||||
// case 3:
|
||||
// $make = app()->make(ProductAssistSetRepository::class);
|
||||
// $id = 'product_assist_id';
|
||||
// break;
|
||||
// case 4:
|
||||
// $make = app()->make(ProductGroupBuyingRepository::class);
|
||||
// $id = 'product_group_id';
|
||||
// break;
|
||||
// }
|
||||
// $where = [$id => $data['exsits_id']];
|
||||
// $activity_id = $make->getSearch($where)->column($make->getPk());
|
||||
// if ($activity_id) {
|
||||
// $id = array_unique($activity_id);
|
||||
// $query->where('activity_id', 'in', $id);
|
||||
// } else {
|
||||
// $query->where('activity_id', '<', 0);
|
||||
// }
|
||||
// })
|
||||
->where('product_type', $data['product_type']);
|
||||
if ($uid) $query->where('uid', $uid);
|
||||
});
|
||||
$query->where('activity_type', $data['product_type'])->where('paid', 1);
|
||||
|
||||
switch ($data['product_type']) {
|
||||
case 1: //秒杀
|
||||
$query->where(function ($query) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('paid', 1);
|
||||
});
|
||||
})->when(isset($data['day']), function ($query) use ($data) {
|
||||
$query->whereDay('SupplyStoreOrder.create_time', $data['day']);
|
||||
});
|
||||
break;
|
||||
case 2: //预售
|
||||
if ($data['type'] == 1) { //第一阶段
|
||||
$query->where('status', 'in', [0, 1, 2, 3, 10]);
|
||||
} else { //第二阶段
|
||||
$query->where('status', 'in', [0, 1, 2, 3]);
|
||||
}
|
||||
break;
|
||||
case 3: //助力
|
||||
break;
|
||||
case 4:
|
||||
break;
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO 获取退款单数量
|
||||
* @param $where
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 1/4/21
|
||||
*/
|
||||
public function getSeckillRefundCount($where, $type = 1)
|
||||
{
|
||||
$query = SupplyStoreOrderProduct::getDB()->alias('P')->join('StoreRefundOrder R', 'P.order_id = R.order_id');
|
||||
$query->join('SupplyStoreOrder O', 'O.order_id = P.order_id');
|
||||
$query
|
||||
->when(isset($where['activity_id']), function ($query) use ($where) {
|
||||
$query->where('P.activity_id', $where['activity_id']);
|
||||
})
|
||||
->when(isset($where['product_sku']), function ($query) use ($where) {
|
||||
$query->where('P.product_sku', $where['product_sku']);
|
||||
})
|
||||
->when(isset($where['day']), function ($query) use ($where) {
|
||||
$query->whereDay('P.create_time', $where['day']);
|
||||
})
|
||||
->when($type == 1, function ($query) use ($where) {
|
||||
$query->where('O.verify_time', null)->where('O.delivery_type', null);
|
||||
}, function ($query) {
|
||||
$query->where('R.refund_type', 2);
|
||||
})
|
||||
->where('P.product_type', 1)->where('R.status', 3);
|
||||
return $query->sum('R.refund_num');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO 用户的某个商品购买数量
|
||||
* @param int $uid
|
||||
* @param int $productId
|
||||
* @return int
|
||||
* @author Qinii
|
||||
* @day 2022/9/26
|
||||
*/
|
||||
public function getMaxCountNumber(int $uid, int $productId)
|
||||
{
|
||||
// return StoreOrder::hasWhere('orderProduct',function($query) use($productId){
|
||||
// $query->where('product_id', $productId);
|
||||
// })
|
||||
// ->where(function($query) {
|
||||
// $query->where('is_del',0)->whereOr(function($query){
|
||||
// $query->where('is_del',1)->where('paid',1);
|
||||
// });
|
||||
// })->where('StoreOrder.uid',$uid)->select()
|
||||
// ;
|
||||
return (int)SupplyStoreOrderProduct::hasWhere('orderInfo', function ($query) use ($uid) {
|
||||
$query->where('uid', $uid)->where(function ($query) {
|
||||
$query->where('is_del', 0)->whereOr(function ($query) {
|
||||
$query->where('is_del', 1)->where('paid', 1);
|
||||
});
|
||||
});
|
||||
})->where('product_id', $productId)->sum('product_num');
|
||||
}
|
||||
|
||||
public function getOrderSn($order_id)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->where($this->getPk(), $order_id)->value('order_sn', '');
|
||||
}
|
||||
|
||||
public function getSubOrderNotSend(int $group_order_id, int $order_id)
|
||||
{
|
||||
return SupplyStoreOrder::getDB()->where('group_order_id', $group_order_id)->where('status', 0)->where('order_id', '<>', $order_id)->count();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取商户排行
|
||||
* @param string $date
|
||||
* @param string $type
|
||||
* @param string $sort
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMerchantTop(string $date, string $type = 'sales', string $sort = 'desc')
|
||||
{
|
||||
|
||||
$query = SupplyStoreOrder::getDB()->with(['merchant' => function ($query) {
|
||||
$query->field('mer_id,mer_name,mer_avatar');
|
||||
}]);
|
||||
$query = getModelTime($query, $date)->where('paid', 1)->where('mer_id', '>', 0)->field('mer_id,sum(total_num) as sales,sum(pay_price + pay_postage) as price')->group('mer_id');
|
||||
switch ($type) {
|
||||
case 'sales':
|
||||
$query->order('sales ' . $sort);
|
||||
break;
|
||||
case 'price':
|
||||
$query->order('price ' . $sort);
|
||||
break;
|
||||
}
|
||||
|
||||
return $query->limit(0, 10)->select()->toArray();
|
||||
}
|
||||
}
|
197
app/common/dao/store/order/SupplyStoreOrderProductDao.php
Normal file
197
app/common/dao/store/order/SupplyStoreOrderProductDao.php
Normal file
@ -0,0 +1,197 @@
|
||||
<?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\order;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\order\SupplyStoreOrderProduct;
|
||||
use think\facade\Db;
|
||||
use think\model\Relation;
|
||||
|
||||
/**
|
||||
* Class SupplyStoreOrderProductDao
|
||||
* @package app\common\dao\store\order
|
||||
* @author xaboy
|
||||
* @day 2020/6/10
|
||||
*/
|
||||
class SupplyStoreOrderProductDao extends BaseDao
|
||||
{
|
||||
const ORDER_VERIFY_STATUS_ = 1;
|
||||
const ORDER_VERIFY_STATUS_SUCCESS = 3;
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020/6/10
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return SupplyStoreOrderProduct::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $uid
|
||||
* @return array|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020/6/10
|
||||
*/
|
||||
public function userOrderProduct($id, $uid)
|
||||
{
|
||||
return SupplyStoreOrderProduct::getDB()->where('uid', $uid)->where('order_product_id', $id)->with(['orderInfo' => function (Relation $query) {
|
||||
$query->field('order_id,order_sn,mer_id')->where('status', 2);
|
||||
}])->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $orderId
|
||||
* @return int
|
||||
* @author xaboy
|
||||
* @day 2020/6/12
|
||||
*/
|
||||
public function noReplyProductCount($orderId)
|
||||
{
|
||||
return SupplyStoreOrderProduct::getDB()->where('order_id', $orderId)->where('is_refund','<>','3')->where('is_reply', 0)
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @param $uid
|
||||
* @param null $orderId
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020/6/12
|
||||
*/
|
||||
public function userRefundProducts(array $ids, $uid, $orderId = null,$refund_switch = 1)
|
||||
{
|
||||
return SupplyStoreOrderProduct::getDB()
|
||||
->when($ids,function($query) use($ids){
|
||||
$query->whereIn('order_product_id', $ids);
|
||||
})
|
||||
->when($orderId, function ($query) use($orderId) {
|
||||
$query->where('order_id', $orderId);
|
||||
})
|
||||
->when($uid, function ($query) use($uid) {
|
||||
$query->where('uid', $uid);
|
||||
})
|
||||
->when($refund_switch, function ($query) use($refund_switch) {
|
||||
$query->where('refund_switch', $refund_switch);
|
||||
})
|
||||
->where('refund_num', '>', 0)->select();
|
||||
}
|
||||
|
||||
public function orderProductGroup($date, $merId = null, $limit = 7)
|
||||
{
|
||||
return SupplyStoreOrderProduct::getDB()->alias('A')->leftJoin('SupplyStoreOrder B', 'A.order_id = B.order_id')
|
||||
->field(Db::raw('sum(A.product_num) as total,A.product_id,cart_info'))
|
||||
->withAttr('cart_info', function ($val) {
|
||||
return json_decode($val, true);
|
||||
})->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'B.pay_time');
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('B.mer_id', $merId);
|
||||
})->where('B.paid', 1)->group('A.product_id')->limit($limit)->order('total DESC')->select();
|
||||
}
|
||||
|
||||
public function dateProductNum($date)
|
||||
{
|
||||
return SupplyStoreOrderProduct::getDB()->alias('A')->leftJoin('SupplyStoreOrder B', 'A.order_id = B.order_id')->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'B.pay_time');
|
||||
})->where('B.paid',1)->sum('A.product_num');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 用户购买活动商品数量
|
||||
* @param int $activityId
|
||||
* @param int $uid
|
||||
* @param int $orderType
|
||||
* @return int
|
||||
* @author Qinii
|
||||
* @day 2020-10-23
|
||||
*/
|
||||
public function getUserPayCount(int $activityId,int $uid,int $productType)
|
||||
{
|
||||
$query = SupplyStoreOrderProduct::hasWhere('orderInfo',function($query){
|
||||
// 已支付/未支付
|
||||
$query->where('is_del',0)->whereOr(function($query){
|
||||
$query->where('paid',1)->where('is_del',1);
|
||||
});
|
||||
});
|
||||
$query->where('uid',$uid)->where('product_type',$productType)->where('activity_id',$activityId);
|
||||
$count = $query->count();
|
||||
return $count;
|
||||
}
|
||||
|
||||
|
||||
public function getUserPayProduct(?string $keyword, int $uid)
|
||||
{
|
||||
$query = SupplyStoreOrderProduct::hasWhere('spu',function($query) use($keyword){
|
||||
$query->when($keyword, function ($query) use($keyword) {
|
||||
$query->whereLike('store_name',"%{$keyword}%");
|
||||
});
|
||||
$query->where('product_type',0);
|
||||
});
|
||||
$query->where('uid', $uid)->where('SupplyStoreOrderProduct.product_type',0);
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 统计已支付的订单 商品相关信息
|
||||
* @param int $mer_id
|
||||
* @param $type 统计类型 金额/数量/支付时间
|
||||
* @param $date 统计时间段
|
||||
* @param $limit
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2023/11/28
|
||||
*/
|
||||
public function getProductRate(int $mer_id, $date = '', $type = 'number', $limit = 10, string $group = 'P.product_id')
|
||||
{
|
||||
$query = SupplyStoreOrderProduct::getDB()->alias('P')->leftJoin('SupplyStoreOrder O', 'O.order_id = P.order_id')
|
||||
->with(['product' => function ($query) {
|
||||
$query->field('product_id,store_name,image');
|
||||
}])->where('O.paid', 1);
|
||||
switch($type){
|
||||
case 'number':
|
||||
$field = "P.product_id,O.pay_price as number,sum(P.product_num) as count,P.create_time, P.order_id,O.mer_id";
|
||||
break;
|
||||
case 'count':
|
||||
$field = "P.product_id,sum(P.product_num) as count,O.pay_price as number,P.create_time, P.order_id,O.mer_id";
|
||||
break;
|
||||
case 'paytime':
|
||||
$field = 'P.product_id,O.pay_time paytime,O.pay_price as number,P.create_time, P.order_id,O.mer_id';
|
||||
break;
|
||||
default:
|
||||
$field = 'P.*';
|
||||
break;
|
||||
}
|
||||
$query->when($mer_id, function ($query) use($mer_id) {
|
||||
$query->where('O.mer_id', $mer_id);
|
||||
})->when($date, function($query) use ($date) {
|
||||
getModelTime($query, $date,'P.create_time');
|
||||
});
|
||||
|
||||
return $query->field($field)->when(!empty($group), function ($query) use ($group) {
|
||||
$query->group($group);
|
||||
})->order("$type DESC")->limit($limit)->select();
|
||||
}
|
||||
}
|
32
app/common/dao/store/parameter/SupplyParameterValueDao.php
Normal file
32
app/common/dao/store/parameter/SupplyParameterValueDao.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?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\parameter;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\parameter\SupplyParameterValue;
|
||||
|
||||
class SupplyParameterValueDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return SupplyParameterValue::class;
|
||||
}
|
||||
|
||||
public function clear($id,$field)
|
||||
{
|
||||
$this->getModel()::getDB()->where($field, $id)->delete();
|
||||
}
|
||||
|
||||
|
||||
}
|
303
app/common/dao/store/product/SupplyProductAttrValueDao.php
Normal file
303
app/common/dao/store/product/SupplyProductAttrValueDao.php
Normal file
@ -0,0 +1,303 @@
|
||||
<?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\SupplyProductAttrValue as model;
|
||||
// use app\common\repositories\store\product\ProductCdkeyRepository;
|
||||
use app\common\repositories\store\product\SupplyProductRepository;
|
||||
use think\db\exception\DbException;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* Class SupplyProductAttrValueDao
|
||||
* @package app\common\dao\store\product
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
class SupplyProductAttrValueDao extends BaseDao
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return model::class;
|
||||
}
|
||||
|
||||
public function add($data,$isType)
|
||||
{
|
||||
if ($isType == 2) {
|
||||
foreach ($data as $datum) {
|
||||
if (!isset($datum['cdkey'])){
|
||||
$this->insertAll($data);
|
||||
break;
|
||||
}
|
||||
$cdkey = $datum['cdkey'];
|
||||
unset($datum['cdkey']);
|
||||
$sku = $this->create($datum);
|
||||
$arr = array_chunk($cdkey, 30);
|
||||
foreach ($arr as $item){
|
||||
$sku->productCdkey()->saveAll($item);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->insertAll($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param int $productId
|
||||
* @return mixed
|
||||
*/
|
||||
public function clearAttr(int $productId)
|
||||
{
|
||||
// ($this->getModel())::where('product_id', $productId)->delete();
|
||||
// app()->make(ProductCdkeyRepository::class)->clearAttr($productId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param int $merId
|
||||
* @param $field
|
||||
* @param $value
|
||||
* @param null $except
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFieldColumnt($key, $value, $field, $except = null)
|
||||
{
|
||||
return ($this->getModel()::getDB())->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})->where($key, $value)->column($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/11
|
||||
* @param $key
|
||||
* @param $value
|
||||
* @param $field
|
||||
* @param null $except
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFieldSum($key, $value, $field, $except = null)
|
||||
{
|
||||
return ($this->getModel()::getDB())->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})->where($key, $value)->sum($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/11
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function insert(array $data)
|
||||
{
|
||||
return ($this->getModel()::getDB())->insertAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/11
|
||||
* @param int|null $merId
|
||||
* @param $field
|
||||
* @param $value
|
||||
* @param null $except
|
||||
* @return bool
|
||||
*/
|
||||
public function merFieldExists(?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($field, $value)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
public function getSku($id)
|
||||
{
|
||||
return ($this->getModel())::where('product_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $merId
|
||||
* @param $field
|
||||
* @param $value
|
||||
* @param null $except
|
||||
* @return mixed
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
public function getFieldExists(?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($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param string $unique
|
||||
* @param int $desc
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
public function descStock(int $productId, string $unique, int $desc)
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->where('unique', $unique)->update([
|
||||
'stock' => Db::raw('stock-' . $desc),
|
||||
'sales' => Db::raw('sales+' . $desc)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param string $sku
|
||||
* @param int $desc
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
public function descSkuStock(int $productId, string $sku, int $desc)
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->where('sku', $sku)->update([
|
||||
'stock' => Db::raw('stock-' . $desc),
|
||||
'sales' => Db::raw('sales+' . $desc)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param string $unique
|
||||
* @param int $inc
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
public function incStock(int $productId, string $unique, int $inc)
|
||||
{
|
||||
model::getDB()->where('product_id', $productId)->where('unique', $unique)->inc('stock', $inc)->update();
|
||||
model::getDB()->where('product_id', $productId)->where('unique', $unique)->where('sales', '>=', $inc)->dec('sales', $inc)->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param string $sku
|
||||
* @param int $inc
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
public function incSkuStock(int $productId, string $sku, int $inc)
|
||||
{
|
||||
model::getDB()->where('product_id', $productId)->where('sku', $sku)->inc('stock', $inc)->update();
|
||||
model::getDB()->where('product_id', $productId)->where('sku', $sku)->where('sales', '>', $inc)->dec('sales', $inc)->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param string $unique
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
public function attrExists(int $productId, string $unique): bool
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->where('unique', $unique)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param string $sku
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
public function skuExists(int $productId, string $sku): bool
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->where('sku', $sku)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 商品佣金是否大于设置佣金比例
|
||||
* @param $productId
|
||||
* @return bool
|
||||
* @author Qinii
|
||||
* @day 2020-06-25
|
||||
*/
|
||||
public function checkExtensionById($productId)
|
||||
{
|
||||
$extension_one_rate = systemConfig('extension_one_rate');
|
||||
$extension_two_rate = systemConfig('extension_two_rate');
|
||||
|
||||
$count = ($this->getModel()::getDb())->where(function($query)use($productId,$extension_one_rate){
|
||||
$query->where('product_id',$productId)->whereRaw('price * '.$extension_one_rate.' > extension_one');
|
||||
})->whereOr(function($query)use($productId,$extension_two_rate){
|
||||
$query->where('product_id',$productId)->whereRaw('price * '.$extension_two_rate.' > extension_two');
|
||||
})->count();
|
||||
return $count ? false : true;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
$query = ($this->getModel()::getDb())
|
||||
->when(isset($where['product_id']) && $where['product_id'] !== '',function($query)use($where){
|
||||
$query->where('product_id',$where['product_id']);
|
||||
})
|
||||
->when(isset($where['sku']) && $where['sku'] !== '',function($query)use($where){
|
||||
$query->where('sku',$where['sku']);
|
||||
})
|
||||
->when(isset($where['unique']) && $where['unique'] !== '',function($query)use($where){
|
||||
$query->where('unique',$where['unique']);
|
||||
});
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function updates(array $ids, array $data)
|
||||
{
|
||||
$this->getModel()::getDb()->whereIn('product_id',$ids)->update($data);
|
||||
}
|
||||
|
||||
public function updatesExtension(array $ids, array $data)
|
||||
{
|
||||
app()->make(SupplyProductRepository::class)->updates($ids,['extension_type' => 1]);
|
||||
$query = $this->getModel()::getDb()->where('product_id','in',$ids);
|
||||
$query->chunk(100, function($list) use($data){
|
||||
foreach ($list as $item) {
|
||||
$arr['extension_one'] = bcmul($item->price,$data['extension_one'],2);
|
||||
$arr['extension_two'] = bcmul($item->price,$data['extension_two'],2);
|
||||
$this->getModel()::getDb()->where('unique',$item->unique)->update($arr);
|
||||
}
|
||||
},'product_id');
|
||||
}
|
||||
}
|
253
app/common/dao/store/product/SupplySpuDao.php
Normal file
253
app/common/dao/store/product/SupplySpuDao.php
Normal file
@ -0,0 +1,253 @@
|
||||
<?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\SupplyProductCate;
|
||||
use app\common\model\store\product\SupplySpu;
|
||||
use app\common\model\store\SupplyStoreCategory;
|
||||
use app\common\repositories\store\SupplyStoreCategoryRepository;
|
||||
use app\common\repositories\system\supply\SupplyRepository;
|
||||
use crmeb\services\VicWordService;
|
||||
|
||||
class SupplySpuDao extends BaseDao
|
||||
{
|
||||
public function getModel(): string
|
||||
{
|
||||
return SupplySpu::class;
|
||||
}
|
||||
|
||||
public function search($where)
|
||||
{
|
||||
$order = 'P.sort DESC';
|
||||
if(isset($where['order'])){
|
||||
if(in_array($where['order'], ['is_new', 'price_asc', 'price_desc', 'rate', 'sales','ot_price','ot_price_desc','ot_price_asc'])){
|
||||
switch ($where['order']) {
|
||||
case 'price_asc':
|
||||
$order = 'S.price ASC';
|
||||
break;
|
||||
case 'price_desc':
|
||||
$order = 'S.price DESC';
|
||||
break;
|
||||
case 'ot_price_asc':
|
||||
$order = 'S.ot_price ASC';
|
||||
break;
|
||||
case 'ot_price_desc':
|
||||
$order = 'S.ot_price DESC';
|
||||
break;
|
||||
default:
|
||||
$order = 'P.'.$where['order'] . ' DESC';
|
||||
break;
|
||||
}
|
||||
}elseif($where['order'] == 'star'){
|
||||
$order = 'S.star DESC,S.rank DESC';
|
||||
}else{
|
||||
$order = 'S.'. (($where['order'] !== '') ? $where['order']: 'star' ).' DESC';
|
||||
}
|
||||
}
|
||||
|
||||
$order .= ',S.create_time DESC';
|
||||
if(isset($where['order']) && $where['order'] === 'none'){
|
||||
$order = '';
|
||||
}
|
||||
$query = SupplySpu::getDB()->alias('S')->join('StoreProduct P','S.product_id = P.product_id', 'left');
|
||||
$query->when(isset($where['is_del']) && $where['is_del'] !== '',function($query)use($where){
|
||||
$query->where('P.is_del',$where['is_del']);
|
||||
})
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] !== '',function($query)use($where){
|
||||
$query->where('P.mer_id',$where['mer_id']);
|
||||
})
|
||||
->when(isset($where['mer_ids']) && $where['mer_ids'] !== '',function($query)use($where){
|
||||
$query->whereIn('P.mer_id',$where['mer_ids']);
|
||||
})
|
||||
->when(isset($where['product_ids']) && $where['product_ids'] !== '',function($query)use($where){
|
||||
$query->whereIn('P.product_id',$where['product_ids']);
|
||||
})
|
||||
->when(isset($where['keyword']) && $where['keyword'] !== '',function($query)use($where){
|
||||
if (is_numeric($where['keyword'])) {
|
||||
$query->whereLike("S.store_name|S.keyword|S.product_id", "%{$where['keyword']}%");
|
||||
} else {
|
||||
$word = app()->make(VicWordService::class)->getWord($where['keyword']);
|
||||
$query->where(function ($query) use ($word) {
|
||||
foreach ($word as $item) {
|
||||
$query->whereOr('S.store_name|S.keyword', 'LIKE', "%$item%");
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
->when(isset($where['is_trader']) && $where['is_trader'] !== '',function($query)use($where){
|
||||
$merId = app()->make(SupplyRepository::class)->search([
|
||||
'is_trader' => $where['is_trader'],
|
||||
'status' => 1,
|
||||
'mer_state' => 1,
|
||||
'is_del' => 1,
|
||||
])->column('mer_id');
|
||||
|
||||
$query->whereIn('P.mer_id',$merId);
|
||||
})
|
||||
->when(isset($where['mer_type_id']) && $where['mer_type_id'] !== '',function($query)use($where){
|
||||
$merId = app()->make(SupplyRepository::class)->search([
|
||||
'type_id' => $where['mer_type_id'],
|
||||
'status' => 1,
|
||||
'mer_state' => 1,
|
||||
'is_del' => 1,
|
||||
])->column('mer_id');
|
||||
|
||||
$query->whereIn('P.mer_id',$merId);
|
||||
})
|
||||
->when(isset($where['cate_pid']) && $where['cate_pid'], function ($query) use ($where) {
|
||||
$storeCategoryRepository = app()->make(SupplyStoreCategoryRepository::class);
|
||||
if (is_array($where['cate_pid'])) {
|
||||
$cateIds = $storeCategoryRepository->selectChildrenId($where['cate_pid']);
|
||||
} else {
|
||||
$cateIds = $storeCategoryRepository->findChildrenId((int)$where['cate_pid']);
|
||||
$where['cate_pid'] = [$where['cate_pid']];
|
||||
}
|
||||
$cate = array_merge($cateIds, $where['cate_pid']);
|
||||
$query->whereIn('P.cate_id', $cate);
|
||||
})
|
||||
->when(isset($where['cate_id']) && $where['cate_id'] !== '', function ($query) use ($where) {
|
||||
is_array($where['cate_id']) ? $query->whereIn('P.cate_id', $where['cate_id']) : $query->where('P.cate_id', $where['cate_id']);
|
||||
})
|
||||
->when(isset($where['spu_id']) && $where['spu_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('S.spu_id',$where['spu_id']);
|
||||
})
|
||||
->when(isset($where['spu_ids']) && $where['spu_ids'] !== '', function ($query) use ($where) {
|
||||
$query->whereIn('S.spu_id',$where['spu_ids']);
|
||||
})
|
||||
->when(isset($where['product_ids']) && !empty($where['product_ids']), function ($query) use ($where) {
|
||||
$query->whereIn('P.product_id',$where['product_ids']);
|
||||
})
|
||||
->when(isset($where['is_stock']) && !empty($where['is_stock']), function ($query) use ($where) {
|
||||
$query->where('P.stock','>',0);
|
||||
})
|
||||
->when(isset($where['is_coupon']) && !empty($where['is_coupon']), function ($query) use ($where) {
|
||||
$query->whereIn('P.product_type','0,2');
|
||||
})
|
||||
->when(isset($where['common']) && $where['common'] !== '', function ($query) use ($where) {
|
||||
$query->whereIn('S.product_type', [0, 1]);
|
||||
})
|
||||
->when(isset($where['price_on']) && $where['price_on'] !== '',function($query)use($where){
|
||||
$query->where('S.price','>=',$where['price_on']);
|
||||
})
|
||||
->when(isset($where['price_off']) && $where['price_off'] !== '',function($query)use($where){
|
||||
$query->where('S.price','<=',$where['price_off']);
|
||||
})
|
||||
->when(isset($where['brand_id']) && $where['brand_id'] !== '', function ($query) use ($where) {
|
||||
$query->whereIn('P.brand_id', array_map('intval', explode(',', $where['brand_id'])));
|
||||
})
|
||||
->when(isset($where['is_gift_bag']) && $where['is_gift_bag'] !== '',function($query)use($where){
|
||||
$query->where('P.is_gift_bag',$where['is_gift_bag']);
|
||||
})
|
||||
->when(isset($where['product_type']) && $where['product_type'] !== '',function($query)use($where){
|
||||
$query->where('S.product_type',$where['product_type']);
|
||||
})
|
||||
->when(isset($where['not_type']) && $where['not_type'] !== '',function($query)use($where){
|
||||
$query->whereNotIn('S.product_type',$where['not_type']);
|
||||
})
|
||||
->when(isset($where['action']) && $where['action'] !== '',function($query)use($where){
|
||||
$query->where('S.product_type','>',0)->where('S.mer_id','<>',0);
|
||||
})
|
||||
->when(isset($where['mer_cate_id']) && $where['mer_cate_id'] !== '',function($query)use($where){
|
||||
$ids = (SupplyStoreCategory::where('path','like','%/'.$where['mer_cate_id'].'/%'))->column('store_category_id');
|
||||
$ids[] = intval($where['mer_cate_id']);
|
||||
$ids = array_unique($ids);
|
||||
$productId = SupplyProductCate::where('mer_cate_id', 'in', $ids)->column('product_id');
|
||||
$productId = array_unique($productId);
|
||||
$query->where('P.product_id','in',$productId);
|
||||
})
|
||||
->when(isset($where['mer_status']) && $where['mer_status'] !== '',function($query)use($where){
|
||||
$query->where('mer_status',$where['mer_status']);
|
||||
})
|
||||
->when(isset($where['spu_status']) && $where['spu_status'] !== '',function($query)use($where){
|
||||
$query->where('S.status',$where['spu_status']);
|
||||
})
|
||||
->when(isset($where['sys_labels']) && $where['sys_labels'] !== '',function($query)use($where){
|
||||
$query->whereLike('S.sys_labels',"%,{$where['sys_labels']},%");
|
||||
})
|
||||
->when(isset($where['mer_labels']) && $where['mer_labels'] !== '',function($query)use($where){
|
||||
$query->whereLike('S.mer_labels',"%,{$where['mer_labels']},%");
|
||||
})
|
||||
->when(isset($where['pid']) && $where['pid'] !== '', function ($query) use ($where) {
|
||||
$query->join('StoreCategory CT','P.cate_id = CT.store_category_id')->where('CT.pid',$where['pid']);
|
||||
})
|
||||
->when(isset($where['delivery_way']) && $where['delivery_way'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('P.delivery_way',"%{$where['delivery_way']}%");
|
||||
})
|
||||
->when(isset($where['scope']) && $where['scope'] !== '', function ($query) use ($where) {
|
||||
$scope = explode(',', $where['scope']);
|
||||
if ($scope[1] <= 0) {
|
||||
$query->where('S.ot_price','<',$where['scope']);
|
||||
} else {
|
||||
$query->where('S.ot_price','between',$scope);
|
||||
}
|
||||
})
|
||||
->when(isset($where['hot_type']) && $where['hot_type'] !== '', function ($query) use ($where) {
|
||||
if ($where['hot_type'] == 'new') $query->where('P.is_new', 1);
|
||||
else if ($where['hot_type'] == 'hot') $query->where('P.is_hot', 1);
|
||||
else if ($where['hot_type'] == 'best') $query->where('P.is_best', 1);
|
||||
else if ($where['hot_type'] == 'good') $query->where('P.is_benefit', 1);
|
||||
})
|
||||
->when(isset($where['svip']) && $where['svip'] !== '',function($query)use($where){
|
||||
$query->where('svip_price_type','>',0)->where('mer_svip_status',1);
|
||||
})
|
||||
;
|
||||
return $query->order($order);
|
||||
}
|
||||
|
||||
public function findOrCreateAll(array $where)
|
||||
{
|
||||
foreach ($where as $item) {
|
||||
$item['activity_id'] = $item['activity_id'] ?? 0;
|
||||
$data = $this->getModel()::getDB()->where('product_id', $item['product_id'])
|
||||
->where('product_type', $item['product_type'])
|
||||
->where('activity_id', $item['activity_id'])
|
||||
->find();
|
||||
if (!$data) $this->create($item);
|
||||
}
|
||||
}
|
||||
|
||||
public function delProduct($id, $isDel = 1)
|
||||
{
|
||||
$this->getModel()::getDb()->where('product_id', $id)->update(['is_del' => $isDel]);
|
||||
}
|
||||
|
||||
public function getActivecategory($type)
|
||||
{
|
||||
$query = SupplySpu::getDB()->alias('S')->join('StoreProduct P','S.product_id = P.product_id')
|
||||
->join('StoreCategory C','C.store_category_id = P.cate_id');
|
||||
|
||||
$query->where('S.status',1)->where('S.product_type',$type)->where('C.is_show',1);
|
||||
return $query->group('S.product_id')->column('C.path');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 软删除商户的所有商品
|
||||
* @param $merId
|
||||
* @author Qinii
|
||||
* @day 5/15/21
|
||||
*/
|
||||
public function clearProduct($merId)
|
||||
{
|
||||
|
||||
$this->getModel()::getDb()->where('mer_id', $merId)->update(['is_del' => 1]);
|
||||
}
|
||||
|
||||
public function clear(int $id, string $field)
|
||||
{
|
||||
$this->getModel()::getDB()->where($field, $id)->delete();
|
||||
}
|
||||
|
||||
public function updatePrice($mer_id, $product_id, $price)
|
||||
{
|
||||
return $this->getModel()::getDB()->where('mer_id', $mer_id)->where('product_id', $product_id)->where('product_type', 0)->update(['price' => $price]);
|
||||
}
|
||||
}
|
46
app/common/model/store/SupplyStoreBrand.php
Normal file
46
app/common/model/store/SupplyStoreBrand.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?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;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class SupplyStoreBrand extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'brand_id';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_store_brand';
|
||||
}
|
||||
|
||||
public function brandCategory()
|
||||
{
|
||||
return $this->belongsTo(SupplyStoreBrandCategory::class,'brand_category_id','store_brand_category_id');
|
||||
}
|
||||
|
||||
}
|
52
app/common/model/store/SupplyStoreBrandCategory.php
Normal file
52
app/common/model/store/SupplyStoreBrandCategory.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\store;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class SupplyStoreBrandCategory extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'store_brand_category_id';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_store_brand_category';
|
||||
}
|
||||
|
||||
public function getAncestorsAttr($value)
|
||||
{
|
||||
$value = self::whereIn('store_brand_category_id',$this->path_ids)->order('level ASC')->column('cate_name');
|
||||
return implode('/',$value).'/'.$this->cate_name;
|
||||
}
|
||||
|
||||
public function getPathIdsAttr()
|
||||
{
|
||||
return explode('/',$this->path);
|
||||
}
|
||||
|
||||
}
|
104
app/common/model/store/SupplyStoreCategory.php
Normal file
104
app/common/model/store/SupplyStoreCategory.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?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;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\product\SupplyProduct;
|
||||
use think\Model;
|
||||
|
||||
class SupplyStoreCategory extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'store_category_id';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_store_category';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取父级名称
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/22
|
||||
* @param $value
|
||||
* @return string
|
||||
*/
|
||||
public function getAncestorsAttr($value)
|
||||
{
|
||||
$value = self::whereIn('store_category_id',$this->path_ids)->order('level ASC')->column('cate_name');
|
||||
return implode('/',$value).'/'.$this->cate_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取path的id
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/22
|
||||
* @return array
|
||||
*/
|
||||
public function getPathIdsAttr()
|
||||
{
|
||||
return explode('/',$this->path);
|
||||
}
|
||||
public function getHasProductAttr()
|
||||
{
|
||||
return SupplyProduct::where('cate_id',$this->store_category_id)->count() > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取子集id
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/22
|
||||
* @param $value
|
||||
* @return array
|
||||
*/
|
||||
public function getChildIdsAttr($value)
|
||||
{
|
||||
return self::where('path','like','%/'.$this->store_category_id.'/%')->column('store_category_id');
|
||||
}
|
||||
|
||||
public function searchIdAttr($query,$value)
|
||||
{
|
||||
$query->where('store_category_id',$value);
|
||||
}
|
||||
|
||||
public function searchIdsAttr($query,$value)
|
||||
{
|
||||
$query->whereIn('store_category_id',$value);
|
||||
}
|
||||
|
||||
public function searchStatusAttr($query,$value)
|
||||
{
|
||||
$query->where('is_show',$value);
|
||||
}
|
||||
|
||||
public function searchMerIdsAttr($query,$value)
|
||||
{
|
||||
$query->whereIn('mer_id',$value);
|
||||
}
|
||||
|
||||
}
|
334
app/common/model/store/order/SupplyStoreCart.php
Normal file
334
app/common/model/store/order/SupplyStoreCart.php
Normal file
@ -0,0 +1,334 @@
|
||||
<?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\product\SupplyProduct;
|
||||
use app\common\model\store\product\SupplyProductAttr;
|
||||
use app\common\model\store\product\SupplyProductAttrValue;
|
||||
use app\common\model\store\product\SupplySpu;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
|
||||
// use app\common\model\store\product\ProductAssistSet;
|
||||
// use app\common\model\store\product\ProductPresell;
|
||||
|
||||
// use app\common\model\store\product\StoreDiscounts;
|
||||
use app\common\model\system\supply\Supply;
|
||||
// use app\common\repositories\store\product\ProductAssistSkuRepository;
|
||||
use app\common\repositories\store\product\SupplyProductAttrValueRepository;
|
||||
// use app\common\repositories\store\product\ProductGroupSkuRepository;
|
||||
// use app\common\repositories\store\product\ProductPresellSkuRepository;
|
||||
// use app\common\repositories\store\product\ProductSkuRepository;
|
||||
|
||||
class SupplyStoreCart extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'cart_id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_store_cart';
|
||||
}
|
||||
|
||||
public function searchCartIdAttr($query,$value)
|
||||
{
|
||||
$query->where('cart_id',$value);
|
||||
}
|
||||
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->hasOne(SupplyProduct::class, 'product_id', 'product_id');
|
||||
}
|
||||
|
||||
public function productAttr()
|
||||
{
|
||||
return $this->hasOne(SupplyProductAttrValue::class, 'unique', 'product_attr_unique');
|
||||
}
|
||||
|
||||
public function attr()
|
||||
{
|
||||
return $this->hasMany(SupplyProductAttr::class,'product_id','product_id');
|
||||
}
|
||||
|
||||
public function attrValue()
|
||||
{
|
||||
return $this->hasMany(SupplyProductAttrValue::class, 'product_id', 'product_id');
|
||||
}
|
||||
|
||||
public function merchant()
|
||||
{
|
||||
return $this->hasOne(Supply::class, 'mer_id', 'mer_id');
|
||||
}
|
||||
|
||||
|
||||
public function productPresell()
|
||||
{
|
||||
return '';
|
||||
// return $this->hasOne(ProductPresell::class,'product_presell_id','source_id');
|
||||
}
|
||||
|
||||
public function productDiscount()
|
||||
{
|
||||
return '';
|
||||
// return $this->hasOne(StoreDiscounts::class, 'discount_id', 'source_id');
|
||||
}
|
||||
|
||||
public function getProductDiscountAttrAttr()
|
||||
{
|
||||
return '';
|
||||
// return app()->make(ProductSkuRepository::class)->getSearch(['active_id' => $this->source_id, 'unique' => $this->product_attr_unique,'active_type'=> 10])->find();
|
||||
}
|
||||
|
||||
public function productAssistSet()
|
||||
{
|
||||
return '';
|
||||
// return $this->hasOne(ProductAssistSet::class,'product_assist_set_id','source_id');
|
||||
}
|
||||
|
||||
public function getProductPresellAttrAttr()
|
||||
{
|
||||
return '';
|
||||
// return app()->make(ProductPresellSkuRepository::class)->getSearch(['product_presell_id' => $this->source_id, 'unique' => $this->product_attr_unique])->find();
|
||||
}
|
||||
|
||||
public function getProductAssistAttrAttr()
|
||||
{
|
||||
return '';
|
||||
// $make = app()->make(ProductAssistSkuRepository::class);
|
||||
// $where = [
|
||||
// "product_assist_id" => $this->productAssistSet->product_assist_id,
|
||||
// "unique" => $this->product_attr_unique
|
||||
// ];
|
||||
// return $make->getSearch($where)->find();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO 活动商品 SKU
|
||||
* @return array|\think\Model|null
|
||||
* @author Qinii
|
||||
* @day 1/13/21
|
||||
*/
|
||||
public function getActiveSkuAttr()
|
||||
{
|
||||
// switch ($this->product_type)
|
||||
// {
|
||||
// case 2:
|
||||
// $make = app()->make(ProductPresellSkuRepository::class);
|
||||
// $where['product_presell_id'] = $this->source_id;
|
||||
// break;
|
||||
// case 3:
|
||||
// $make = app()->make(ProductAssistSkuRepository::class);
|
||||
// $where['product_assist_id'] = $this->productAssistSet->product_assist_id;
|
||||
// break;
|
||||
// case 4:
|
||||
// $make = app()->make(ProductGroupSkuRepository::class);
|
||||
// $where['product_group_id'] = $this->product->productGroup->product_group_id;
|
||||
// break;
|
||||
// default:
|
||||
$make = app()->make(SupplyProductAttrValueRepository::class);
|
||||
$where['product_id'] = $this->product_id;
|
||||
// break;
|
||||
// }
|
||||
$where['unique'] = $this->product_attr_unique;
|
||||
return $make->getSearch($where)->find();
|
||||
}
|
||||
|
||||
public function getSpuAttr()
|
||||
{
|
||||
if ($this->product_type) {
|
||||
$where = [
|
||||
'activity_id' => $this->source_id,
|
||||
'product_type' => $this->product_type,
|
||||
];
|
||||
} else {
|
||||
$where = [
|
||||
'product_id' => $this->product_id,
|
||||
'product_type' => $this->product_type,
|
||||
];
|
||||
}
|
||||
return SupplySpu::where($where)->field('spu_id,store_name')->find();
|
||||
}
|
||||
/**
|
||||
* TODO 检测商品是否有效
|
||||
* @return bool
|
||||
* @author Qinii
|
||||
* @day 2020-10-29
|
||||
*/
|
||||
public function getCheckCartProductAttr()
|
||||
{
|
||||
if($this->is_fail == 1) return false;
|
||||
|
||||
if(is_null($this->product) || is_null($this->productAttr) || $this->product->status !== 1 || $this->product->mer_status !== 1 || $this->product->is_del !== 0)
|
||||
{$this->is_fail = 1;$this->save();return false;}
|
||||
|
||||
// switch ($this->product_type)
|
||||
// {
|
||||
// case 0: //普通商品
|
||||
if ($this->product->product_type !== 0 || $this->product->is_show !== 1 || $this->productAttr->stock < $this->cart_num || $this->product->is_used !== 1) {
|
||||
return false;
|
||||
}
|
||||
// break;
|
||||
// case 1: //秒杀商品
|
||||
// if ($this->product->product_type !== 1 || $this->product->is_show !== 1) return false;
|
||||
// //结束时间
|
||||
// if ($this->product->end_time < time()) return false;
|
||||
// //限量
|
||||
// $order_make = app()->make(StoreOrderRepository::class);
|
||||
// $count = $order_make->seckillOrderCounut($this->product_id);
|
||||
// if ($this->productAttr->stock <= $count) return false;
|
||||
|
||||
// //原商品sku库存
|
||||
// $value_make = app()->make(ProductAttrValueRepository::class);
|
||||
// $sku = $value_make->getWhere(['sku' => $this->productAttr->sku, 'product_id' => $this->product->old_product_id]);
|
||||
// if (!$sku || $sku['stock'] <= 0) return false;
|
||||
|
||||
// break;
|
||||
|
||||
// case 2: //预售商品
|
||||
// if($this->source !== 2 || $this->product->product_type !== 2) return false;
|
||||
// if($this->productPresell->status !== 1 ||
|
||||
// $this->productPresell->is_show !== 1 ||
|
||||
// $this->productPresell->is_del !== 0 ||
|
||||
// $this->productPresell->presell_status !== 1)
|
||||
// {$this->is_fail = 1;$this->save();return false;}
|
||||
|
||||
// $sku = $this->ActiveSku;
|
||||
// if(!$sku || !$sku->sku()) {$this->is_fail = 1; $this->save(); return false; }
|
||||
|
||||
// //库存不足
|
||||
// if($sku->stock < $this->cart_num || $sku->sku->stock < $this->cart_num) return false;
|
||||
// break;
|
||||
|
||||
// case 3: //助力商品
|
||||
// if($this->source !== 3 || $this->product->product_type !== 3 || ($this->productAssistSet->assist_count !== $this->productAssistSet->yet_assist_count)) return false;
|
||||
// if(
|
||||
// $this->productAssistSet->stop_time < time() ||
|
||||
// $this->productAssistSet->sataus === -1 ||
|
||||
// !$this->productAssistSet->assist->is_show ||
|
||||
// $this->productAssistSet->assist->is_del !== 0 ||
|
||||
// $this->productAssistSet->assist->status !== 1)
|
||||
// {$this->is_fail = 1;$this->save();return false;}
|
||||
// $sku = $this->ActiveSku;
|
||||
// if(!$sku || !$sku->sku()) { $this->is_fail = 1; $this->save(); return false; }
|
||||
// //库存不足
|
||||
// if($sku->stock < $this->cart_num || $sku->sku->stock < $this->cart_num) return false;
|
||||
// break;
|
||||
// case 4:
|
||||
// if($this->source !== 4 || $this->product->product_type !== 4 ) return false;
|
||||
// $sku = $this->ActiveSku;
|
||||
// if(!$sku || !$sku->sku()) { $this->is_fail = 1; $this->save(); return false; }
|
||||
// //库存不足
|
||||
// if($sku->stock < $this->cart_num || $sku->sku->stock < $this->cart_num) return false;
|
||||
// break;
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @return bool
|
||||
* @author Qinii
|
||||
* @day 2020-10-29
|
||||
*/
|
||||
public function getUserPayCountAttr()
|
||||
{
|
||||
// $make = app()->make(StoreOrderRepository::class);
|
||||
// switch ($this->product_type)
|
||||
// {
|
||||
// case 1: //秒杀
|
||||
// if(!$make->getDayPayCount($this->uid,$this->product_id,$this->cart_num) || !$make->getPayCount($this->uid,$this->product_id,$this->cart_num))
|
||||
// return false;
|
||||
// break;
|
||||
// case 2: //预售
|
||||
// $count = $this->productPresell->pay_count;
|
||||
// if($count == 0) return true;
|
||||
// $tattend = [
|
||||
// 'activity_id' => $this->source_id,
|
||||
// 'product_type' => 2,
|
||||
// ];
|
||||
// $pay_count = $make->getTattendCount($tattend,$this->uid)->sum('total_num');
|
||||
// if($pay_count < $count) return false;
|
||||
// if (($count - $pay_count) < $this->cart_num) return false;
|
||||
// break;
|
||||
// case 3: //助力
|
||||
// $tattend = [
|
||||
// 'activity_id' => $this->source_id,
|
||||
// 'product_type' => 3,
|
||||
// ];
|
||||
// $pay_count = $make->getTattendCount($tattend,$this->uid)->count();
|
||||
// if($pay_count) return false;
|
||||
|
||||
// $count = $this->productAssistSet->assist->pay_count;
|
||||
// if($count !== 0){
|
||||
// $_tattend = [
|
||||
// 'exsits_id' => $this->productAssistSet->assist->product_assist_id,
|
||||
// 'product_type' => 3,
|
||||
// ];
|
||||
// $_count = $make->getTattendCount($_tattend,$this->uid)->count();
|
||||
// if($_count >= $count) return false;
|
||||
// }
|
||||
// break;
|
||||
// case 4:
|
||||
// $tattend = [
|
||||
// 'exsits_id' => $this->product_id,
|
||||
// 'product_type' => 4,
|
||||
// ];
|
||||
// $pay_count = $make->getTattendCount($tattend,$this->uid)->count();
|
||||
// if($pay_count) return false;
|
||||
// $count = $this->product->productGroup->pay_count;
|
||||
// if($count !== 0){
|
||||
// $_tattend = [
|
||||
// 'exsits_id' => $this->product_id,
|
||||
// 'product_type' => 34,
|
||||
// ];
|
||||
// $_count = $make->getTattendCount($_tattend,$this->uid)->count();
|
||||
// if($_count >= $count) return false;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
|
||||
public function searchProductIdAttr($query,$value)
|
||||
{
|
||||
$query->where('product_id',$value);
|
||||
}
|
||||
public function searchUidAttr($query,$value)
|
||||
{
|
||||
$query->where('uid',$value);
|
||||
}
|
||||
public function searchIsNewAttr($query,$value)
|
||||
{
|
||||
$query->where('is_new',$value);
|
||||
}
|
||||
public function searchIsPayAttr($query,$value)
|
||||
{
|
||||
$query->where('is_pay',$value);
|
||||
}
|
||||
public function searchIsDelAttr($query,$value)
|
||||
{
|
||||
$query->where('is_del',$value);
|
||||
}
|
||||
public function searchIsFailAttr($query,$value)
|
||||
{
|
||||
$query->where('is_fail',$value);
|
||||
}
|
||||
|
||||
}
|
107
app/common/model/store/order/SupplyStoreGroupOrder.php
Normal file
107
app/common/model/store/order/SupplyStoreGroupOrder.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?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\user\User;
|
||||
// use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||
|
||||
class SupplyStoreGroupOrder extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'group_order_id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_store_group_order';
|
||||
}
|
||||
|
||||
public function orderList()
|
||||
{
|
||||
return $this->hasMany(SupplyStoreOrder::class, 'group_order_id', 'group_order_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne(User::class, 'uid', 'uid');
|
||||
}
|
||||
|
||||
public function getGiveCouponAttr()
|
||||
{
|
||||
// if (count($this->give_coupon_ids))
|
||||
// return app()->make(StoreCouponRepository::class)->getGiveCoupon($this->give_coupon_ids);
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getCancelTimeAttr()
|
||||
{
|
||||
$timer = ((int)systemConfig('auto_close_order_timer')) ?: 15;
|
||||
return date('m-d H:i', strtotime("+ $timer minutes", strtotime($this->create_time)));
|
||||
}
|
||||
|
||||
public function getCancelUnixAttr()
|
||||
{
|
||||
$timer = ((int)systemConfig('auto_close_order_timer')) ?: 15;
|
||||
return strtotime("+ $timer minutes", strtotime($this->create_time));
|
||||
}
|
||||
|
||||
public function getGiveCouponIdsAttr($value)
|
||||
{
|
||||
return $value ? explode(',', $value) : [];
|
||||
}
|
||||
|
||||
public function setGiveCouponIdsAttr($value)
|
||||
{
|
||||
return $value ? implode(',', $value) : '';
|
||||
}
|
||||
|
||||
public function getCombinePayParams()
|
||||
{
|
||||
$params = [
|
||||
'order_sn' => $this->group_order_sn,
|
||||
'sub_orders' => [],
|
||||
'attach' => 'order',
|
||||
'body' => '订单支付',
|
||||
];
|
||||
foreach ($this->orderList as $order) {
|
||||
if ($order->pay_price > 0) {
|
||||
$subOrder = [
|
||||
'pay_price' => $order->pay_price,
|
||||
'order_sn' => $order->order_sn,
|
||||
'sub_mchid' => $order->merchant->sub_mchid,
|
||||
];
|
||||
$params['sub_orders'][] = $subOrder;
|
||||
}
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function getPayParams($return_url = '')
|
||||
{
|
||||
$params = [
|
||||
'order_sn' => $this->group_order_sn,
|
||||
'pay_price' => $this->pay_price,
|
||||
'attach' => 'order',
|
||||
'body' => '订单支付'
|
||||
];
|
||||
if ($return_url) {
|
||||
$params['return_url'] = $return_url;
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
}
|
208
app/common/model/store/order/SupplyStoreOrder.php
Normal file
208
app/common/model/store/order/SupplyStoreOrder.php
Normal file
@ -0,0 +1,208 @@
|
||||
<?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\community\Community;
|
||||
// use app\common\model\store\product\ProductGroupUser;
|
||||
// use app\common\model\store\service\StoreService;
|
||||
use app\common\model\store\shipping\Express;
|
||||
use app\common\model\system\supply\Supply;
|
||||
use app\common\model\user\User;
|
||||
// use app\common\repositories\store\MerchantTakeRepository;
|
||||
|
||||
class SupplyStoreOrder extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'order_id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_store_order';
|
||||
}
|
||||
|
||||
public function orderProduct()
|
||||
{
|
||||
return $this->hasMany(StoreOrderProduct::class, 'order_id', 'order_id');
|
||||
}
|
||||
|
||||
public function refundProduct()
|
||||
{
|
||||
return $this->orderProduct()->where('refund_num', '>', 0);
|
||||
}
|
||||
|
||||
public function refundOrder()
|
||||
{
|
||||
return $this->hasMany(StoreRefundOrder::class,'order_id','order_id');
|
||||
}
|
||||
|
||||
public function orderStatus()
|
||||
{
|
||||
return $this->hasMany(StoreOrderStatus::class,'order_id','order_id')->order('change_time DESC');
|
||||
}
|
||||
|
||||
public function merchant()
|
||||
{
|
||||
return $this->hasOne(Supply::class, 'mer_id', 'mer_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne(User::class, 'uid', 'uid');
|
||||
}
|
||||
public function receipt()
|
||||
{
|
||||
return $this->hasOne(StoreOrderReceipt::class, 'order_id', 'order_id');
|
||||
}
|
||||
|
||||
public function spread()
|
||||
{
|
||||
return $this->hasOne(User::class, 'uid', 'spread_uid');
|
||||
}
|
||||
|
||||
public function TopSpread()
|
||||
{
|
||||
return $this->hasOne(User::class, 'uid', 'top_uid');
|
||||
}
|
||||
|
||||
public function getUserPhoneAttr($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 groupOrder()
|
||||
{
|
||||
return $this->hasOne(StoreGroupOrder::class, 'group_order_id', 'group_order_id');
|
||||
}
|
||||
|
||||
public function verifyService()
|
||||
{
|
||||
return '';
|
||||
// return $this->hasOne(StoreService::class, 'service_id', 'verify_service_id');
|
||||
}
|
||||
|
||||
public function getTakeAttr()
|
||||
{
|
||||
return 1;
|
||||
// return app()->make(MerchantTakeRepository::class)->get($this->mer_id);
|
||||
}
|
||||
|
||||
public function searchDataAttr($query, $value)
|
||||
{
|
||||
return getModelTime($query, $value);
|
||||
}
|
||||
|
||||
public function presellOrder()
|
||||
{
|
||||
return $this->hasOne(PresellOrder::class, 'order_id', 'order_id');
|
||||
}
|
||||
|
||||
public function finalOrder()
|
||||
{
|
||||
return $this->hasOne(PresellOrder::class,'order_id','order_id');
|
||||
}
|
||||
|
||||
public function groupUser()
|
||||
{
|
||||
return '';
|
||||
// return $this->hasOne(ProductGroupUser::class,'order_id','order_id');
|
||||
}
|
||||
|
||||
public function profitsharing()
|
||||
{
|
||||
return $this->hasMany(StoreOrderProfitsharing::class, 'order_id', 'order_id');
|
||||
}
|
||||
|
||||
public function firstProfitsharing()
|
||||
{
|
||||
return $this->hasOne(StoreOrderProfitsharing::class, 'order_id', 'order_id')->where('type', 'order');
|
||||
}
|
||||
|
||||
public function presellProfitsharing()
|
||||
{
|
||||
return $this->hasOne(StoreOrderProfitsharing::class, 'order_id', 'order_id')->where('type', 'presell');
|
||||
}
|
||||
|
||||
// 核销订单的自订单列表
|
||||
public function takeOrderList()
|
||||
{
|
||||
return $this->hasMany(self::class,'main_id','order_id')->order('verify_time DESC');
|
||||
}
|
||||
|
||||
public function searchMerIdAttr($query, $value)
|
||||
{
|
||||
return $query->where('mer_id', $value);
|
||||
}
|
||||
|
||||
public function getRefundStatusAttr()
|
||||
{
|
||||
$day = (int)systemConfig('sys_refund_timer') ?: 15;
|
||||
return ($this->verify_time ? strtotime($this->verify_time) > strtotime('-' . $day . ' day') : true);
|
||||
}
|
||||
|
||||
public function getCancelTimeAttr()
|
||||
{
|
||||
if (!$this->apid) {
|
||||
$timer = ((int)systemConfig('auto_close_order_timer')) ?: 15;
|
||||
return date('m-d H:i', strtotime("+ $timer minutes", strtotime($this->groupOrder->create_time)));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getOpenReceiptAttr()
|
||||
{
|
||||
return merchantConfig($this->mer_id,'mer_open_receipt') ?: 0;
|
||||
}
|
||||
|
||||
public function getOrderExtendAttr($val)
|
||||
{
|
||||
return $val ? json_decode($val, true) : null;
|
||||
}
|
||||
|
||||
public function getRefundExtensionOneAttr()
|
||||
{
|
||||
if ( $this->refundOrder ){
|
||||
return $this->refundOrder()->where('status',3)->sum('extension_one');
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getRefundExtensionTwoAttr()
|
||||
{
|
||||
if ( $this->refundOrder ){
|
||||
return $this->refundOrder()->where('status',3)->sum('extension_two');
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function community()
|
||||
{
|
||||
return '';
|
||||
// return $this->hasOne(Community::class, 'order_id', 'order_id')->bind(['community_id']);
|
||||
}
|
||||
|
||||
public function getRefundPriceAttr()
|
||||
{
|
||||
return StoreRefundOrder::where('order_id',$this->order_id)->where('status',3)->sum('refund_price');
|
||||
}
|
||||
}
|
88
app/common/model/store/order/SupplyStoreOrderProduct.php
Normal file
88
app/common/model/store/order/SupplyStoreOrderProduct.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?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\product\SupplyProduct;
|
||||
use app\common\model\store\product\SupplySpu;
|
||||
use app\common\model\user\User;
|
||||
|
||||
class SupplyStoreOrderProduct extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'order_product_id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_store_order_product';
|
||||
}
|
||||
|
||||
public function getCartInfoAttr($value)
|
||||
{
|
||||
return json_decode($value, true);
|
||||
}
|
||||
|
||||
public function orderInfo()
|
||||
{
|
||||
return $this->hasOne(StoreOrder::class, 'order_id', 'order_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne(User::class,'uid','uid');
|
||||
}
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->hasOne(SupplyProduct::class,'product_id','product_id');
|
||||
}
|
||||
|
||||
public function spu()
|
||||
{
|
||||
return $this->hasOne(SupplySpu::class,'product_id','product_id');
|
||||
}
|
||||
|
||||
public function searchUidAttr($query ,$value)
|
||||
{
|
||||
$query->where('uid',$value);
|
||||
}
|
||||
public function searchActivitIidAttr($query,$value)
|
||||
{
|
||||
$query->where('activity_id',$value);
|
||||
}
|
||||
public function searchProductTypeAttr($query,$value)
|
||||
{
|
||||
$query->where('product_type',$value);
|
||||
}
|
||||
public function searchOrderIdAttr($query,$value)
|
||||
{
|
||||
$query->where('order_id',$value);
|
||||
}
|
||||
public function searchProductIdAttr($query,$value)
|
||||
{
|
||||
$query->where('product_id',$value);
|
||||
}
|
||||
public function searchRefundSwitchAttr($query,$value)
|
||||
{
|
||||
$query->where('refund_switch',$value);
|
||||
}
|
||||
public function searchRefundNumAttr($query,$value)
|
||||
{
|
||||
$query->where('refund_num', '>' ,$value);
|
||||
}
|
||||
}
|
47
app/common/model/store/order/SupplyStoreOrderStatus.php
Normal file
47
app/common/model/store/order/SupplyStoreOrderStatus.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?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 SupplyStoreOrderStatus
|
||||
* @package app\common\model\store\order
|
||||
* @author xaboy
|
||||
* @day 2020/6/12
|
||||
*/
|
||||
class SupplyStoreOrderStatus extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
* @author xaboy
|
||||
* @day 2020/6/12
|
||||
*/
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020/6/12
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_store_order_status';
|
||||
}
|
||||
}
|
41
app/common/model/store/parameter/SupplyParameterValue.php
Normal file
41
app/common/model/store/parameter/SupplyParameterValue.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\parameter;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class SupplyParameterValue extends BaseModel
|
||||
{
|
||||
|
||||
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'parameter_attr_id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_parameter_value';
|
||||
}
|
||||
|
||||
public function parameter()
|
||||
{
|
||||
return $this->hasOne(Parameter::class,'parameter_id','parameter_id');
|
||||
}
|
||||
|
||||
public function searchParameterIdAttr($query, $value)
|
||||
{
|
||||
if (!is_array($value)) $value = [$value];
|
||||
$query->whereIn('parameter_id', $value);
|
||||
}
|
||||
}
|
675
app/common/model/store/product/SupplyProduct.php
Normal file
675
app/common/model/store/product/SupplyProduct.php
Normal file
@ -0,0 +1,675 @@
|
||||
<?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\product;
|
||||
|
||||
use app\common\dao\store\StoreSeckillActiveDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\coupon\StoreCouponProduct;
|
||||
use app\common\model\store\Guarantee;
|
||||
use app\common\model\store\GuaranteeTemplate;
|
||||
use app\common\model\store\GuaranteeValue;
|
||||
use app\common\model\store\parameter\ParameterValue;
|
||||
// use app\common\model\store\shipping\ShippingTemplate;
|
||||
use app\common\model\store\StoreBrand;
|
||||
use app\common\model\store\StoreCategory;
|
||||
use app\common\model\store\StoreSeckillActive;
|
||||
use app\common\model\system\form\Form;
|
||||
use app\common\model\system\supply\Supply;
|
||||
use app\common\repositories\store\StoreCategoryRepository;
|
||||
use crmeb\services\VicWordService;
|
||||
use think\db\BaseQuery;
|
||||
use think\facade\Db;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
class SupplyProduct extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
|
||||
protected $deleteTime = 'is_del';
|
||||
protected $defaultSoftDelete = 0;
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/8
|
||||
* @return string
|
||||
*/
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'product_id';
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/8
|
||||
* @return string
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_store_product';
|
||||
}
|
||||
|
||||
/*
|
||||
* -----------------------------------------------------------------------------------------------------------------
|
||||
* 属性
|
||||
* -----------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
public function getSliderImageAttr($value)
|
||||
{
|
||||
return $value ? explode(',', $value) : [];
|
||||
}
|
||||
|
||||
public function getGiveCouponIdsAttr($value)
|
||||
{
|
||||
return $value ? explode(',', $value) : [];
|
||||
}
|
||||
|
||||
public function getMaxExtensionAttr($value)
|
||||
{
|
||||
if ($this->extension_type) {
|
||||
$org_extension = ($this->attrValue()->order('extension_one DESC')->value('extension_one'));
|
||||
} else {
|
||||
$org_extension = bcmul(($this->attrValue()->order('price DESC')->value('price')), systemConfig('extension_one_rate'), 2);
|
||||
}
|
||||
$spreadUser = (request()->hasMacro('isLogin') && request()->isLogin() && request()->userType() == 1) ? request()->userInfo() : null;
|
||||
if ($spreadUser && $spreadUser->brokerage_level > 0 && $spreadUser->brokerage && $spreadUser->brokerage->extension_one_rate > 0) {
|
||||
$org_extension = bcmul($org_extension, 1 + $spreadUser->brokerage->extension_one_rate, 2);
|
||||
}
|
||||
return $org_extension;
|
||||
}
|
||||
|
||||
public function getMinExtensionAttr($value)
|
||||
{
|
||||
if ($this->extension_type) {
|
||||
$org_extension = ($this->attrValue()->order('extension_two ASC')->value('extension_two'));
|
||||
} else {
|
||||
$org_extension = bcmul(($this->attrValue()->order('price ASC')->value('price')), systemConfig('extension_two_rate'), 2);
|
||||
}
|
||||
$spreadUser = (request()->hasMacro('isLogin') && request()->isLogin() && request()->userType() == 1) ? request()->userInfo() : null;
|
||||
if ($spreadUser && $spreadUser->brokerage_level > 0 && $spreadUser->brokerage && $spreadUser->brokerage->extension_one_rate > 0) {
|
||||
$org_extension = bcmul($org_extension, 1 + $spreadUser->brokerage->extension_one_rate, 2);
|
||||
}
|
||||
return $org_extension;
|
||||
}
|
||||
|
||||
public function check()
|
||||
{
|
||||
if (!$this || !$this->is_show || !$this->is_used || !$this->status || $this->is_del || !$this->mer_status) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 秒杀商品结束时间
|
||||
* @return false|int
|
||||
* @author Qinii
|
||||
* @day 2020-08-15
|
||||
*/
|
||||
public function getEndTimeAttr()
|
||||
{
|
||||
if ($this->product_type !== 1) return true;
|
||||
$day = date('Y-m-d', time());
|
||||
$_day = strtotime($day);
|
||||
$end_day = strtotime($this->seckillActive['end_day']);
|
||||
if ($end_day >= $_day)
|
||||
return strtotime($day . $this->seckillActive['end_time'] . ':00:00');
|
||||
if ($end_day < strtotime($day))
|
||||
return strtotime(date('Y-m-d', $end_day) . $this->seckillActive['end_time'] . ':00:00');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 秒杀商品状态
|
||||
* @return array|int
|
||||
* @author Qinii
|
||||
* @day 2020-08-19
|
||||
*/
|
||||
public function getSeckillStatusAttr()
|
||||
{
|
||||
if ($this->product_type !== 1) return true;
|
||||
$day = strtotime(date('Y-m-d', time()));
|
||||
$_h = date('H', time());
|
||||
if (!$this->seckillActive) return -1;
|
||||
$start_day = strtotime($this->seckillActive['start_day']);
|
||||
$end_day = strtotime($this->seckillActive['end_day']);
|
||||
if ($this->seckillActive['status'] !== -1) {
|
||||
//还未开始
|
||||
if ($start_day > time() || $this->is_show !== 1) return 0;
|
||||
//已结束
|
||||
if ($end_day < $day) return -1;
|
||||
//开始 - 结束
|
||||
if ($start_day <= $day && $day <= $end_day) {
|
||||
//未开始
|
||||
if ($this->seckillActive['start_time'] > $_h) return 0;
|
||||
//已结束
|
||||
if ($this->seckillActive['end_time'] <= $_h) return -1;
|
||||
//进行中
|
||||
if ($this->seckillActive['start_time'] <= $_h && $this->seckillActive['end_time'] > $_h) return 1;
|
||||
}
|
||||
}
|
||||
//已结束
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function getImageAttr($value)
|
||||
{
|
||||
if (is_int(strpos($value, 'http'))) {
|
||||
return $value;
|
||||
} else {
|
||||
return rtrim(systemConfig('site_url'), '/') . $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTopReplyAttr()
|
||||
{
|
||||
$res = [];
|
||||
if (systemConfig('sys_reply_status')) {
|
||||
$res = ProductReply::where('product_id', $this->product_id)->where('is_del', 0)->with(['orderProduct'])->field('reply_id,uid,nickname,merchant_reply_content,avatar,order_product_id,product_id,product_score,service_score,postage_score,comment,pics,rate,create_time')
|
||||
->order('sort DESC,create_time DESC')->limit(1)->find();
|
||||
if (!$res) return null;
|
||||
if ($res['orderProduct'])
|
||||
$res['sku'] = $res['orderProduct']['cart_info']['productAttr']['sku'];
|
||||
unset($res['orderProduct']);
|
||||
if (strlen($res['nickname']) > 1) {
|
||||
$str = mb_substr($res['nickname'], 0, 1) . '*';
|
||||
if (strlen($res['nickname']) > 2) {
|
||||
$str .= mb_substr($res['nickname'], -1, 1);
|
||||
}
|
||||
$res['nickname'] = $str;
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function getUsStatusAttr()
|
||||
{
|
||||
return ($this->status == 1) ? ($this->is_used == 1 ? ($this->mer_status == 1 && $this->is_show ? 1 : 0) : -1) : -1;
|
||||
}
|
||||
|
||||
public function getGuaranteeTemplateAttr()
|
||||
{
|
||||
$gua = GuaranteeTemplate::where('guarantee_template_id', $this->guarantee_template_id)->where('status', 1)->where('is_del', 0)->find();
|
||||
if (!$gua) return [];
|
||||
$guarantee_id = GuaranteeValue::where('guarantee_template_id', $this->guarantee_template_id)->column('guarantee_id');
|
||||
return Guarantee::where('guarantee_id', 'in', $guarantee_id)->where('status', 1)->where('is_del', 0)->select();
|
||||
}
|
||||
|
||||
public function getMaxIntegralAttr()
|
||||
{
|
||||
if (systemConfig('integral_status') && merchantConfig($this->mer_id, 'mer_integral_status')) {
|
||||
$price = ($this->attrValue()->order('price DESC')->value('price'));
|
||||
$rate = ($this->integral_rate < 0) ? merchantConfig($this->mer_id, 'mer_integral_rate') : $this->integral_rate;
|
||||
$rate = $rate > 0 ? $rate / 100 : 0;
|
||||
return bcmul($price, $rate, 2);
|
||||
}
|
||||
return '0';
|
||||
}
|
||||
|
||||
public function getHotRankingAttr()
|
||||
{
|
||||
if ($this->product_type == 0) {
|
||||
$where = [
|
||||
'is_show' => 1,
|
||||
'status' => 1,
|
||||
'is_used' => 1,
|
||||
'product_type' => 0,
|
||||
'mer_status' => 1,
|
||||
'is_gift_bag' => 0,
|
||||
'cate_id' => $this->cate_id
|
||||
];
|
||||
self::where($where)->order('sales DESC');
|
||||
}
|
||||
}
|
||||
|
||||
public function getOtPriceAttr($value)
|
||||
{
|
||||
if ($this->product_type == 20) {
|
||||
return (int)$value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 商品参数
|
||||
* @author Qinii
|
||||
* @day 2022/11/24
|
||||
*/
|
||||
public function getParamsAttr()
|
||||
{
|
||||
if (in_array($this->product_type, [0, 2])) {
|
||||
$product_id = $this->product_id;
|
||||
} else {
|
||||
$product_id = $this->old_product_id;
|
||||
}
|
||||
return ParameterValue::where('product_id', $product_id)->order('parameter_value_id ASC')->select();
|
||||
}
|
||||
|
||||
public function getParamTempIdAttr($value)
|
||||
{
|
||||
return $value ? explode(',', $value) : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 是否是会员
|
||||
* @return bool
|
||||
* @author Qinii
|
||||
* @day 2023/1/4
|
||||
*/
|
||||
public function getIsVipAttr()
|
||||
{
|
||||
if (request()->hasMacro('isLogin') && request()->isLogin()) {
|
||||
if (request()->userType() == 1) {
|
||||
$userInfo = request()->userInfo();
|
||||
return $userInfo->is_svip > 0 ? true : false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 是否展示会员价
|
||||
* @return bool
|
||||
* @author Qinii
|
||||
* @day 2023/1/4
|
||||
*/
|
||||
public function getShowSvipPriceAttr()
|
||||
{
|
||||
if ($this->mer_svip_status != 0 && (systemConfig('svip_show_price') != 1 || $this->is_vip) && $this->svip_price_type > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO 是否显示会员价等信息
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 2022/11/24
|
||||
*/
|
||||
public function getShowSvipInfoAttr()
|
||||
{
|
||||
$res = [
|
||||
'show_svip' => true, //是否展示会员入口
|
||||
'is_svip' => false, //当前用户是否是会员
|
||||
'show_svip_price' => false, //是否展示会员价
|
||||
'save_money' => 0, //当前商品会员优化多少钱
|
||||
];
|
||||
if ($this->product_type == 0) {
|
||||
if (!systemConfig('svip_switch_status')) {
|
||||
$res['show_svip'] = false;
|
||||
} else {
|
||||
$res['is_svip'] = $this->is_vip;
|
||||
if ($this->show_svip_price) {
|
||||
$res['show_svip_price'] = true;
|
||||
$res['save_money'] = bcsub($this->price, $this->svip_price, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 获取会员价
|
||||
* @return int|string
|
||||
* @author Qinii
|
||||
* @day 2023/1/4
|
||||
*/
|
||||
public function getSvipPriceAttr()
|
||||
{
|
||||
if ($this->product_type == 0 && $this->mer_svip_status != 0 && $this->show_svip_price) {
|
||||
//默认比例
|
||||
if ($this->svip_price_type == 1) {
|
||||
$rate = merchantConfig($this->mer_id, 'svip_store_rate');
|
||||
$svip_store_rate = $rate > 0 ? bcdiv($rate, 100, 2) : 0;
|
||||
$price = $this->attrValue()->order('price ASC')->value('price');
|
||||
return bcmul($price, $svip_store_rate, 2);
|
||||
}
|
||||
//自定义
|
||||
if ($this->svip_price_type == 2) {
|
||||
return $this->getData('svip_price');
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getIsSvipPriceAttr()
|
||||
{
|
||||
if ($this->product_type == 0 && $this->mer_svip_status != 0) {
|
||||
//默认比例
|
||||
if ($this->svip_price_type == 1) {
|
||||
$rate = merchantConfig($this->mer_id, 'svip_store_rate');
|
||||
$svip_store_rate = $rate > 0 ? bcdiv($rate, 100, 2) : 0;
|
||||
$price = $this->attrValue()->order('price ASC')->value('price');
|
||||
return bcmul($price, $svip_store_rate, 2);
|
||||
}
|
||||
//自定义
|
||||
if ($this->svip_price_type == 2) {
|
||||
return $this->getData('svip_price');
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getGoodIdsAttr($value, $data)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return explode(',', $value);
|
||||
}
|
||||
|
||||
/*
|
||||
* -----------------------------------------------------------------------------------------------------------------
|
||||
* 关联模型
|
||||
* -----------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
public function merCateId()
|
||||
{
|
||||
return $this->hasMany(ProductCate::class, 'product_id', 'product_id')->field('product_id,mer_cate_id');
|
||||
}
|
||||
|
||||
public function attr()
|
||||
{
|
||||
return $this->hasMany(ProductAttr::class, 'product_id', 'product_id');
|
||||
}
|
||||
|
||||
public function attrValue()
|
||||
{
|
||||
return $this->hasMany(ProductAttrValue::class, 'product_id', 'product_id');
|
||||
}
|
||||
|
||||
public function oldAttrValue()
|
||||
{
|
||||
return $this->hasMany(ProductAttrValue::class, 'product_id', 'old_product_id');
|
||||
}
|
||||
|
||||
public function content()
|
||||
{
|
||||
return $this->hasOne(ProductContent::class, 'product_id', 'product_id');
|
||||
}
|
||||
|
||||
protected function temp()
|
||||
{
|
||||
return '';//$this->hasOne(ShippingTemplate::class, 'shipping_template_id', 'temp_id');
|
||||
}
|
||||
|
||||
public function storeCategory()
|
||||
{
|
||||
return $this->hasOne(StoreCategory::class, 'store_category_id', 'cate_id')->field('store_category_id,cate_name');
|
||||
}
|
||||
|
||||
public function merchant()
|
||||
{
|
||||
return $this->hasOne(Supply::class, 'mer_id', 'mer_id')->field('is_trader,type_id,mer_id,mer_name,mer_avatar,product_score,service_score,postage_score,service_phone,care_count,is_margin');
|
||||
}
|
||||
|
||||
public function reply()
|
||||
{
|
||||
return $this->hasMany(ProductReply::class, 'product_id', 'product_id')->order('create_time DESC');
|
||||
}
|
||||
|
||||
public function brand()
|
||||
{
|
||||
return $this->hasOne(StoreBrand::class, 'brand_id', 'brand_id')->field('brand_id,brand_name');
|
||||
}
|
||||
|
||||
public function seckillActive()
|
||||
{
|
||||
return $this->hasOne(StoreSeckillActive::class, 'product_id', 'product_id');
|
||||
}
|
||||
|
||||
public function issetCoupon()
|
||||
{
|
||||
return $this->hasOne(StoreCouponProduct::class, 'product_id', 'product_id')->alias('A')
|
||||
->rightJoin('StoreCoupon B', 'A.coupon_id = B.coupon_id')->where(function (BaseQuery $query) {
|
||||
$query->where('B.is_limited', 0)->whereOr(function (BaseQuery $query) {
|
||||
$query->where('B.is_limited', 1)->where('B.remain_count', '>', 0);
|
||||
});
|
||||
})->where(function (BaseQuery $query) {
|
||||
$query->where('B.is_timeout', 0)->whereOr(function (BaseQuery $query) {
|
||||
$time = date('Y-m-d H:i:s');
|
||||
$query->where('B.is_timeout', 1)->where('B.start_time', '<', $time)->where('B.end_time', '>', $time);
|
||||
});
|
||||
})->field('A.product_id,B.*')->where('status', 1)->where('type', 1)->where('send_type', 0)->where('is_del', 0)
|
||||
->order('sort DESC,coupon_id DESC')->hidden(['is_del', 'status']);
|
||||
}
|
||||
|
||||
public function assist()
|
||||
{
|
||||
return $this->hasOne(ProductAssist::class, 'product_id', 'product_id');
|
||||
}
|
||||
|
||||
public function productGroup()
|
||||
{
|
||||
return $this->hasOne(ProductGroup::class, 'product_id', 'product_id');
|
||||
}
|
||||
|
||||
public function guarantee()
|
||||
{
|
||||
return $this->hasOne(GuaranteeTemplate::class, 'guarantee_template_id', 'guarantee_template_id')->where('status', 1)->where('is_del', 0);
|
||||
}
|
||||
|
||||
public function getForm()
|
||||
{
|
||||
return $this->hasOne(Form::class, 'form_id', 'mer_form_id');
|
||||
}
|
||||
|
||||
public function getFormName()
|
||||
{
|
||||
return $this->hasOne(Form::class, 'form_id', 'mer_form_id')->bind(['mer_form_name' => 'name']);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* -----------------------------------------------------------------------------------------------------------------
|
||||
* 搜索器
|
||||
* -----------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
public function searchMerCateIdAttr($query, $value)
|
||||
{
|
||||
$cate_ids = (StoreCategory::where('path', 'like', '%/' . $value . '/%'))->column('store_category_id');
|
||||
$cate_ids[] = intval($value);
|
||||
$product_id = ProductCate::whereIn('mer_cate_id', $cate_ids)->column('product_id');
|
||||
$query->whereIn('Product.product_id', $product_id);
|
||||
}
|
||||
|
||||
public function searchKeywordAttr($query, $value)
|
||||
{
|
||||
if (!$value) return;
|
||||
if (is_numeric($value)) {
|
||||
$query->whereLike("Product.store_name|Product.keyword|bar_code|Product.product_id", "%{$value}%");
|
||||
} else if (is_array($value)) {
|
||||
$query->where(function ($query) use ($value) {
|
||||
foreach ($value as $item) {
|
||||
$query->whereOr('Product.store_name|Product.keyword', 'LIKE', "%$item%");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$word = app()->make(VicWordService::class)->getWord($value);
|
||||
$query->where(function ($query) use ($word, $value) {
|
||||
foreach ($word as $item) {
|
||||
$query->whereOr('Product.store_name|Product.keyword', 'LIKE', "%$item%");
|
||||
}
|
||||
$query->order(Db::raw('REPLACE(Product.store_name,\'' . $value . '\',\'\')'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function searchStatusAttr($query, $value)
|
||||
{
|
||||
if ($value === -1) {
|
||||
$query->where('Product.status', 'in', [-1, -2]);
|
||||
} else {
|
||||
$query->where('Product.status', $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function searchCatePidAttr($query, $value)
|
||||
{
|
||||
$query->when($value, function ($query) use ($value) {
|
||||
$storeCategoryRepository = app()->make(StoreCategoryRepository::class);
|
||||
if (is_array($value)) {
|
||||
$cateIds = $storeCategoryRepository->selectChildrenId($value);
|
||||
} else {
|
||||
$cateIds = $storeCategoryRepository->findChildrenId((int)$value);
|
||||
$cateIds[] = $value;
|
||||
}
|
||||
$query->whereIn('cate_id', $cateIds);
|
||||
});
|
||||
}
|
||||
|
||||
public function searchCateIdAttr($query, $value)
|
||||
{
|
||||
$query->where('cate_id', $value);
|
||||
}
|
||||
|
||||
public function searchCateIdsAttr($query, $value)
|
||||
{
|
||||
$query->whereIn('cate_id', $value);
|
||||
}
|
||||
|
||||
public function searchIsShowAttr($query, $value)
|
||||
{
|
||||
$query->where('is_show', $value);
|
||||
}
|
||||
|
||||
public function searchPidAttr($query, $value)
|
||||
{
|
||||
$childrenId = app()->make(StoreCategoryRepository::class)->findChildrenId((int)$value);
|
||||
$ids = array_merge($childrenId, [(int)$value]);
|
||||
$query->whereIn('cate_id', $ids);
|
||||
}
|
||||
|
||||
public function searchStockAttr($query, $value)
|
||||
{
|
||||
$value ? $query->where('stock', '<=', $value) : $query->where('stock', $value);
|
||||
}
|
||||
|
||||
public function searchIsNewAttr($query, $value)
|
||||
{
|
||||
$query->where('is_new', $value);
|
||||
}
|
||||
|
||||
public function searchPriceAttr($query, $value)
|
||||
{
|
||||
if (empty($value[0]) && !empty($value[1]))
|
||||
$query->where('price', '<', $value[1]);
|
||||
if (!empty($value[0]) && empty($value[1]))
|
||||
$query->where('price', '>', $value[0]);
|
||||
if (!empty($value[0]) && !empty($value[1]))
|
||||
$query->whereBetween('price', [$value[0], $value[1]]);
|
||||
}
|
||||
|
||||
public function searchBrandIdAttr($query, $value)
|
||||
{
|
||||
$query->whereIn('brand_id', $value);
|
||||
}
|
||||
|
||||
public function searchIsGiftBagAttr($query, $value)
|
||||
{
|
||||
$query->where('is_gift_bag', $value);
|
||||
}
|
||||
|
||||
public function searchIsGoodAttr($query, $value)
|
||||
{
|
||||
$query->where('is_good', $value);
|
||||
}
|
||||
|
||||
public function searchIsUsedAttr($query, $value)
|
||||
{
|
||||
$query->where('is_used', $value);
|
||||
}
|
||||
|
||||
public function searchProductTypeAttr($query, $value)
|
||||
{
|
||||
$query->where('Product.product_type', $value);
|
||||
}
|
||||
|
||||
public function searchSeckillStatusAttr($query, $value)
|
||||
{
|
||||
$product_id = (new StoreSeckillActiveDao())->getStatus($value)->column('product_id');
|
||||
$query->whereIn('Product.product_id', $product_id);
|
||||
}
|
||||
|
||||
public function searchStoreNameAttr($query, $value)
|
||||
{
|
||||
$query->where('Product.store_name', 'like', '%' . $value . '%');
|
||||
}
|
||||
|
||||
public function searchMerStatusAttr($query, $value)
|
||||
{
|
||||
$query->where('mer_status', $value);
|
||||
}
|
||||
|
||||
public function searchProductIdAttr($query, $value)
|
||||
{
|
||||
$query->where('Product.product_id', $value);
|
||||
}
|
||||
|
||||
public function searchProductIdsAttr($query, $value)
|
||||
{
|
||||
$query->whereIn('Product.product_id', $value);
|
||||
}
|
||||
|
||||
public function searchNotProductIdAttr($query, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
if (is_array($value)) {
|
||||
$query->whereNotIn('Product.product_id', $value);
|
||||
} else {
|
||||
$query->where('Product.product_id', '<>', $value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function searchPriceOnAttr($query, $value)
|
||||
{
|
||||
$query->where('price', '>=', $value);
|
||||
}
|
||||
|
||||
public function searchPriceOffAttr($query, $value)
|
||||
{
|
||||
$query->where('price', '<=', $value);
|
||||
}
|
||||
|
||||
public function searchisFictiAttr($query, $value)
|
||||
{
|
||||
$query->where('type', $value);
|
||||
}
|
||||
|
||||
public function searchGuaranteeTemplateIdAttr($query, $value)
|
||||
{
|
||||
$query->whereIn('guarantee_template_id', $value);
|
||||
}
|
||||
|
||||
public function searchTempIdAttr($query, $value)
|
||||
{
|
||||
$query->whereIn('Product.temp_id', $value);
|
||||
}
|
||||
|
||||
public function searchDateAttr($query, $value)
|
||||
{
|
||||
getModelTime($query, $value, 'Product.create_time');
|
||||
}
|
||||
|
||||
public function searchFormIdAttr($query, $value)
|
||||
{
|
||||
if ($value !== '') {
|
||||
$query->whereIn('Product.mer_form_id', $value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
63
app/common/model/store/product/SupplyProductAttr.php
Normal file
63
app/common/model/store/product/SupplyProductAttr.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?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\product;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class SupplyProductAttr extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/8
|
||||
* @return string
|
||||
*/
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/8
|
||||
* @return string
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_store_product_attr';
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param $value
|
||||
* @return array
|
||||
*/
|
||||
public function getAttrValuesAttr($value)
|
||||
{
|
||||
return explode('-!-',$value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param $value
|
||||
* @return string
|
||||
*/
|
||||
public function setAttrValuesAttr($value)
|
||||
{
|
||||
return implode('-!-',$value);
|
||||
}
|
||||
|
||||
}
|
112
app/common/model/store/product/SupplyProductAttrValue.php
Normal file
112
app/common/model/store/product/SupplyProductAttrValue.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?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\product;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class SupplyProductAttrValue extends BaseModel
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/8
|
||||
* @return string
|
||||
*/
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'value_id';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/8
|
||||
* @return string
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_store_product_attr_value';
|
||||
}
|
||||
|
||||
public function getDetailAttr($value)
|
||||
{
|
||||
return json_decode($value);
|
||||
}
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->hasOne(Product::class, 'product_id','product_id');
|
||||
}
|
||||
|
||||
public function getSvipPriceAttr()
|
||||
{
|
||||
if (isset($this->product->product_type) && $this->product->product_type == 0 && $this->product->show_svip_price && $this->product->svip_price_type == 1) {
|
||||
$rate = merchantConfig($this->product->mer_id,'svip_store_rate');
|
||||
$svip_store_rate = $rate > 0 ? bcdiv($rate,100,2) : 0;
|
||||
return bcmul($this->price, $svip_store_rate,2);
|
||||
}
|
||||
return $this->getData('svip_price');
|
||||
}
|
||||
|
||||
public function getIsSvipPriceAttr()
|
||||
{
|
||||
if (isset($this->product->product_type) && $this->product->product_type == 0 && $this->product->svip_price_type == 1) {
|
||||
$rate = merchantConfig($this->product->mer_id, 'svip_store_rate');
|
||||
$svip_store_rate = $rate > 0 ? bcdiv($rate, 100, 2) : 0;
|
||||
return bcmul($this->price, $svip_store_rate, 2);
|
||||
}
|
||||
return '未设置';
|
||||
}
|
||||
|
||||
public function getBcExtensionOneAttr()
|
||||
{
|
||||
if(!intval(systemConfig('extension_status'))) return 0;
|
||||
if($this->product->extension_type == 1) return $this->extension_one;
|
||||
return floatval(round(bcmul(systemConfig('extension_one_rate'), isset($this->org_price) ? $this->org_price : $this->price, 3),2));
|
||||
}
|
||||
|
||||
public function getBcExtensionTwoAttr()
|
||||
{
|
||||
if(!intval(systemConfig('extension_status'))) return 0;
|
||||
if($this->product->extension_type == 1) return $this->extension_two;
|
||||
return floatval(round(bcmul(systemConfig('extension_two_rate'), isset($this->org_price) ? $this->org_price : $this->price, 3),2));
|
||||
}
|
||||
|
||||
public function productSku()
|
||||
{
|
||||
return $this->hasOne(ProductSku::class, 'unique', 'unique');
|
||||
}
|
||||
public function productCdkey()
|
||||
{
|
||||
return $this->hasMany(ProductCdkey::class,'value_id','value_id');
|
||||
}
|
||||
|
||||
public function searchUniqueAttr($query,$value)
|
||||
{
|
||||
$query->where('unique',$value);
|
||||
}
|
||||
|
||||
public function searchSkuAttr($query,$value)
|
||||
{
|
||||
$query->where('sku',$value);
|
||||
}
|
||||
|
||||
public function searchProductIdAttr($query,$value)
|
||||
{
|
||||
$query->where('product_id',$value);
|
||||
}
|
||||
|
||||
|
||||
}
|
51
app/common/model/store/product/SupplyProductCate.php
Normal file
51
app/common/model/store/product/SupplyProductCate.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?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\product;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\SupplyStoreCategory;
|
||||
|
||||
class SupplyProductCate extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/8
|
||||
* @return string
|
||||
*/
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/8
|
||||
* @return string
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_store_product_cate';
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->hasOne(SupplyStoreCategory::class,'store_category_id','mer_cate_id')->field('store_category_id,cate_name');
|
||||
}
|
||||
|
||||
public function searchProductIdAttr($query, $value)
|
||||
{
|
||||
$query->where('product_id',$value);
|
||||
}
|
||||
}
|
240
app/common/model/store/product/SupplySpu.php
Normal file
240
app/common/model/store/product/SupplySpu.php
Normal file
@ -0,0 +1,240 @@
|
||||
<?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\product;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
// use app\common\model\store\coupon\StoreCouponProduct;
|
||||
// use app\common\model\store\StoreSeckillActive;
|
||||
use app\common\model\system\supply\Supply;
|
||||
// use think\db\BaseQuery;
|
||||
|
||||
class SupplySpu extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @return string
|
||||
* @author Qinii
|
||||
* @day 12/18/20
|
||||
*/
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'spu_id';
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @return string
|
||||
* @author Qinii
|
||||
* @day 12/18/20
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'supply_store_spu';
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* -----------------------------------------------------------------------------------------------------------------
|
||||
* 属性
|
||||
* -----------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
public function getMinExtensionAttr($value)
|
||||
{
|
||||
return isset($this->product) ? $this->product->min_extension : 0;
|
||||
}
|
||||
|
||||
public function getMaxExtensionAttr()
|
||||
{
|
||||
return isset($this->product) ? $this->product->max_extension : 0;
|
||||
}
|
||||
|
||||
public function getStopTimeAttr()
|
||||
{
|
||||
if($this->product_type == 1){
|
||||
if (is_null($this->seckillActive)) {
|
||||
return date('Y-m-d H:i:s',strtotime("-1 day"));
|
||||
}
|
||||
$day = date('Y-m-d',time());
|
||||
$_day = strtotime($day);
|
||||
$end_day = strtotime($this->seckillActive['end_day']);
|
||||
if($end_day >= $_day)
|
||||
return strtotime($day.$this->seckillActive['end_time'].':00:00');
|
||||
if($end_day < strtotime($day))
|
||||
return strtotime(date('Y-m-d',$end_day).$this->seckillActive['end_time'].':00:00');
|
||||
}
|
||||
}
|
||||
|
||||
public function setMerLabelsAttr($value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
if (!is_array($value))
|
||||
return ','. $value .',';
|
||||
return ','. implode(',', $value) .',';
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getMerLabelsAttr($value)
|
||||
{
|
||||
if (!$value) return [];
|
||||
return explode(',',rtrim(ltrim($value,','),','));
|
||||
}
|
||||
|
||||
|
||||
public function setSysLabelsAttr($value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
if (!is_array($value))
|
||||
return ','. $value .',';
|
||||
return ','. implode(',', $value) .',';
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getSysLabelsAttr($value)
|
||||
{
|
||||
if (!$value) return [];
|
||||
return explode(',',rtrim(ltrim($value,','),','));
|
||||
}
|
||||
|
||||
public function getImageAttr($value)
|
||||
{
|
||||
if (is_int(strpos($value, 'http'))) {
|
||||
return $value;
|
||||
} else {
|
||||
return rtrim(systemConfig('site_url'), '/') . $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getOtPriceAttr($value)
|
||||
{
|
||||
return (int)$value;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 是否展示会员价
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 2023/1/4
|
||||
*/
|
||||
public function getShowSvipInfoAttr($value, $data)
|
||||
{
|
||||
if ($this->product_type == 0) return $this->product->show_svip_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 获取会员价
|
||||
* @return int|string
|
||||
* @author Qinii
|
||||
* @day 2023/1/4
|
||||
*/
|
||||
public function getSvipPriceAttr()
|
||||
{
|
||||
if ($this->product_type == 0) return $this->product->svip_price;
|
||||
}
|
||||
|
||||
public function getIsSvipPriceAttr()
|
||||
{
|
||||
if ($this->product_type == 0) return $this->product->is_svip_price;
|
||||
}
|
||||
|
||||
public function getMerLabelsDataAttr()
|
||||
{
|
||||
return ProductLabel::whereIn('product_label_id',$this->mer_labels)->column('label_name');
|
||||
}
|
||||
|
||||
public function getSysLabelsDataAttr()
|
||||
{
|
||||
return ProductLabel::whereIn('product_label_id',$this->sys_labels)->column('label_name');
|
||||
}
|
||||
|
||||
/*
|
||||
* -----------------------------------------------------------------------------------------------------------------
|
||||
* 关联表
|
||||
* -----------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
public function product()
|
||||
{
|
||||
return $this->hasOne(Product::class,'product_id','product_id');
|
||||
}
|
||||
public function merchant()
|
||||
{
|
||||
return $this->hasOne(Supply::class,'mer_id','mer_id');
|
||||
}
|
||||
public function issetCoupon()
|
||||
{
|
||||
return '';
|
||||
// return $this->hasOne(StoreCouponProduct::class, 'product_id', 'product_id')->alias('A')
|
||||
// ->rightJoin('StoreCoupon B', 'A.coupon_id = B.coupon_id')
|
||||
// ->where(function (BaseQuery $query) {
|
||||
// $query->where('B.is_limited', 0)->whereOr(function (BaseQuery $query) {
|
||||
// $query->where('B.is_limited', 1)->where('B.remain_count', '>', 0);
|
||||
// });
|
||||
// })->where(function (BaseQuery $query) {
|
||||
// $query->where('B.is_timeout', 0)->whereOr(function (BaseQuery $query) {
|
||||
// $time = date('Y-m-d H:i:s');
|
||||
// $query->where('B.is_timeout', 1)->where('B.start_time', '<', $time)->where('B.end_time', '>', $time);
|
||||
// });
|
||||
// })->field('A.product_id,B.*')->where('status', 1)->where('type', 1)->where('send_type', 0)->where('is_del', 0)
|
||||
// ->order('sort DESC,coupon_id DESC')->hidden(['is_del', 'status']);
|
||||
}
|
||||
public function merCateId()
|
||||
{
|
||||
return $this->hasMany(ProductCate::class,'product_id','product_id')->field('product_id,mer_cate_id');
|
||||
}
|
||||
public function seckillActive()
|
||||
{
|
||||
return '';
|
||||
// return $this->hasOne(StoreSeckillActive::class,'seckill_active_id','activity_id');
|
||||
}
|
||||
|
||||
/*
|
||||
* -----------------------------------------------------------------------------------------------------------------
|
||||
* 搜索器
|
||||
* -----------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
public function searchMerIdAttr($query,$value)
|
||||
{
|
||||
$query->where('mer_id',$value);
|
||||
}
|
||||
public function searchProductIdAttr($query,$value)
|
||||
{
|
||||
$query->where('product_id',$value);
|
||||
}
|
||||
public function searchProductTypeAttr($query,$value)
|
||||
{
|
||||
$query->where('product_type',$value);
|
||||
}
|
||||
public function searchActivityIdAttr($query,$value)
|
||||
{
|
||||
$query->where('activity_id',$value);
|
||||
}
|
||||
public function searchKeyworkAttr($query,$value)
|
||||
{
|
||||
$query->whereLike('store_name|keyword',$value);
|
||||
}
|
||||
public function searchPriceOnAttr($query, $value)
|
||||
{
|
||||
$query->where('price','>=',$value);
|
||||
}
|
||||
public function searchPriceOffAttr($query, $value)
|
||||
{
|
||||
$query->where('price','<=',$value);
|
||||
}
|
||||
public function searchSpuIdsAttr($query, $value)
|
||||
{
|
||||
$query->whereIn('spu_id',$value);
|
||||
}
|
||||
}
|
128
app/common/repositories/store/SupplyStoreBrandRepository.php
Normal file
128
app/common/repositories/store/SupplyStoreBrandRepository.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\repositories\store;
|
||||
|
||||
use app\common\repositories\BaseRepository;
|
||||
use app\common\dao\store\SupplyStoreBrandDao as dao;
|
||||
use app\common\repositories\store\product\SupplyProductRepository;
|
||||
use FormBuilder\Factory\Elm;
|
||||
use FormBuilder\Form;
|
||||
use think\facade\Route;
|
||||
|
||||
class SupplyStoreBrandRepository extends BaseRepository
|
||||
{
|
||||
|
||||
public function __construct(dao $dao)
|
||||
{
|
||||
$this->dao = $dao;
|
||||
}
|
||||
|
||||
public function parentExists(int $id)
|
||||
{
|
||||
$make = app()->make(StoreBrandCategoryRepository::class);
|
||||
return ($make->get($id)) ?? false;
|
||||
}
|
||||
|
||||
public function meExists($id)
|
||||
{
|
||||
return $this->dao->merFieldExists($this->dao->getPk(), $id);
|
||||
}
|
||||
|
||||
public function merExistsBrand(string $value)
|
||||
{
|
||||
return $this->dao->merFieldExists('brand_name', $value);
|
||||
}
|
||||
|
||||
public function getCategorySearch($where)
|
||||
{
|
||||
$make = app()->make(SupplyProductRepository::class);
|
||||
$where = array_merge($where, $make->productShow());
|
||||
$brandIds = app()->make(SupplyProductRepository::class)->getBrandByCategory($where);
|
||||
$count = 0;
|
||||
$list = [];
|
||||
if ($brandIds) {
|
||||
$query = $this->dao->search(['ids' => $brandIds]);
|
||||
$count = $query->count();
|
||||
$list = $query->select()->toArray();
|
||||
array_push($list, [
|
||||
"brand_id" => 0,
|
||||
"brand_category_id" => 0,
|
||||
"brand_name" => "其他",
|
||||
"sort" => 999,
|
||||
"pic" => "",
|
||||
"is_show" => 1,
|
||||
"create_time" => "",
|
||||
]);
|
||||
}
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
public function getList(array $where, $page, $limit)
|
||||
{
|
||||
$query = $this->dao->search($where)
|
||||
->with('brandCategory', function ($query) {
|
||||
$query->field('store_brand_category_id,cate_name,path');
|
||||
});
|
||||
$count = $query->count();
|
||||
$list = $query->page($page, $limit)->select();
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/27
|
||||
* @param $id
|
||||
* @return Form
|
||||
*/
|
||||
public function updateForm($id)
|
||||
{
|
||||
return $this->form($id, $this->dao->get($id)->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/27
|
||||
* @param int|null $id
|
||||
* @param array $formData
|
||||
* @return Form
|
||||
*/
|
||||
public function form(?int $id = null, array $formData = [])
|
||||
{
|
||||
$form = Elm::createForm(is_null($id) ? Route::buildUrl('systemStoreBrandCreate')->build() : Route::buildUrl('systemStoreBrandUpdate', ['id' => $id])->build());
|
||||
$form->setRule([
|
||||
Elm::cascader('brand_category_id', '上级分类:')->options(function () use ($id) {
|
||||
$menus = app()->make(StoreBrandCategoryRepository::class)->getAncestorsChildList();
|
||||
return $menus;
|
||||
})->placeholder('请选择上级分类')->props(['props' => ['emitPath' => false]])->appendValidate(Elm::validateInt()->required()->message('请选择上级分类')),
|
||||
Elm::input('brand_name', '品牌名称:')->placeholder('请输入品牌名称')->required(),
|
||||
Elm::switches('is_show', '是否显示:', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
|
||||
Elm::number('sort', '排序:', 0)->precision(0)->max(99999),
|
||||
]);
|
||||
return $form->setTitle(is_null($id) ? '添加品牌' : '编辑品牌')->formData($formData);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 品牌下是否存在商品
|
||||
* @param int $id
|
||||
* @return bool
|
||||
* @author Qinii
|
||||
* @day 12/15/20
|
||||
*/
|
||||
public function getBrandHasProduct(int $id)
|
||||
{
|
||||
$make = app()->make(SupplyProductRepository::class);
|
||||
$count = $make->getSearch(['brand_id' => [$id]])->where('is_del', 0)->count();
|
||||
return $count ? true : false;
|
||||
}
|
||||
}
|
188
app/common/repositories/store/SupplyStoreCategoryRepository.php
Normal file
188
app/common/repositories/store/SupplyStoreCategoryRepository.php
Normal file
@ -0,0 +1,188 @@
|
||||
<?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\store;
|
||||
|
||||
use app\common\dao\store\SupplyStoreCategoryDao as dao;
|
||||
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;
|
||||
use crmeb\traits\CategoresRepository;
|
||||
|
||||
/**
|
||||
* @mixin dao
|
||||
*/
|
||||
class SupplyStoreCategoryRepository extends BaseRepository
|
||||
{
|
||||
|
||||
use CategoresRepository;
|
||||
|
||||
public function __construct(dao $dao)
|
||||
{
|
||||
$this->dao = $dao;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $merId
|
||||
* @param int|null $id
|
||||
* @param array $formData
|
||||
* @return Form
|
||||
* @throws FormBuilderException
|
||||
* @author xaboy
|
||||
* @day 2020-04-20
|
||||
*/
|
||||
public function form(int $merId, ?int $id = null, array $formData = [])
|
||||
{
|
||||
if ($merId) {
|
||||
$form = Elm::createForm(is_null($id) ? Route::buildUrl('merchantStoreCategoryCreate')->build() : Route::buildUrl('merchantStoreCategoryUpdate', ['id' => $id])->build());
|
||||
$msg = '';
|
||||
} else {
|
||||
$form = Elm::createForm(is_null($id) ? Route::buildUrl('systemStoreCategoryCreate')->build() : Route::buildUrl('systemStoreCategoryUpdate', ['id' => $id])->build());
|
||||
$msg = '注:平台商品分类请添加至三级分类,商户后台添加商品时才会展示该分类';
|
||||
}
|
||||
//注:平台商品分类请添加至三级分类,商户后台添加商品时才会展示该分类。
|
||||
$form->setRule([
|
||||
Elm::cascader('pid', '上级分类:')->options(function () use ($id, $merId) {
|
||||
$menus = $this->dao->getAllOptions($merId, 1, $this->dao->getMaxLevel($merId) - 1, 0);
|
||||
if ($id && isset($menus[$id])) unset($menus[$id]);
|
||||
$menus = formatCascaderData($menus, 'cate_name');
|
||||
array_unshift($menus, ['label' => '顶级分类', 'value' => 0]);
|
||||
return $menus;
|
||||
})->placeholder('请选择上级分类')->props(['props' => ['checkStrictly' => true, 'emitPath' => false]])->filterable(true)->appendValidate(Elm::validateInt()->required()->message('请选择上级分类'))->appendRule('suffix', [
|
||||
'type' => 'div',
|
||||
'style' => ['color' => '#999999'],
|
||||
'domProps' => [
|
||||
'innerHTML' => $msg,
|
||||
]
|
||||
]),
|
||||
Elm::input('cate_name', '分类名称:')->placeholder('请输入分类名称')->required(),
|
||||
Elm::frameImage('pic', '分类图片(110*110px):', '/' . config('admin.' . ($merId ? 'merchant' : 'admin') . '_prefix') . '/setting/uploadPicture?field=pic&type=1')->width('1000px')->height('600px')->icon('el-icon-camera')->props(['footer' => false])->modal(['modal' => false, 'custom-class' => 'suibian-modal']),
|
||||
Elm::switches('is_show', '是否显示:', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
|
||||
Elm::number('sort', '排序:', 0)->precision(0)->max(99999),
|
||||
]);
|
||||
|
||||
return $form->setTitle(is_null($id) ? '添加分类' : '编辑分类')->formData($formData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $merId
|
||||
* @param $id
|
||||
* @return Form
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws FormBuilderException
|
||||
* @author xaboy
|
||||
* @day 2020-04-20
|
||||
*/
|
||||
public function updateForm(int $merId, $id)
|
||||
{
|
||||
return $this->form($merId, $id, $this->dao->get($id, $merId)->toArray());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/16
|
||||
* @return mixed
|
||||
*/
|
||||
public function getList($status = null, $lv = null)
|
||||
{
|
||||
$menus = $this->dao->getAllOptions(0, $status, $lv, 0);
|
||||
$menus = formatCascaderData($menus, 'cate_name', $lv ?: 3);
|
||||
return $menus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/18
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBrandList()
|
||||
{
|
||||
return app()->make(StoreBrandRepository::class)->getAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测是否超过最低等级限制
|
||||
* @param int $id
|
||||
* @param int $level
|
||||
* @return bool
|
||||
* @author Qinii
|
||||
*/
|
||||
public function checkLevel(int $id, int $level = 0, $merId = null)
|
||||
{
|
||||
$check = $this->getLevelById($id);
|
||||
if ($level)
|
||||
$check = $level;
|
||||
return ($check < $this->dao->getMaxLevel($merId)) ? true : false;
|
||||
}
|
||||
|
||||
public function updateStatus($id, $data)
|
||||
{
|
||||
return $this->dao->update($id, $data);
|
||||
}
|
||||
|
||||
public function getHot($merId)
|
||||
{
|
||||
$hot = $this->dao->getSearch(['is_hot' => 1, 'mer_id' => $merId])->hidden(['path', 'level', 'mer_id', 'create_time'])->select();
|
||||
if ($hot) $hot->toArray();
|
||||
return compact('hot');
|
||||
}
|
||||
|
||||
|
||||
public function pointsForm(?int $id)
|
||||
{
|
||||
$formData = [];
|
||||
if ($id) {
|
||||
$formData = $this->dao->get($id)->toArray();
|
||||
$form = Elm::createForm(Route::buildUrl('pointsCateUpdate', ['id' => $id])->build());
|
||||
} else {
|
||||
$form = Elm::createForm(Route::buildUrl('pointsCateCreate')->build());
|
||||
}
|
||||
$form->setRule([
|
||||
Elm::input('cate_name', '分类名称:')->required(),
|
||||
Elm::switches('is_show', '是否显示:', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
|
||||
Elm::number('sort', '排序:', 0)->precision(0)->max(99999),
|
||||
Elm::number('type', '类型:', 1)->hiddenStatus(true),
|
||||
]);
|
||||
return $form->setTitle(is_null($id) ? '添加分类' : '编辑分类')->formData($formData);
|
||||
}
|
||||
|
||||
public function getAllFatherName($id)
|
||||
{
|
||||
$info = $this->dao->get($id);
|
||||
|
||||
if (empty($info)) {
|
||||
return ' ';
|
||||
}
|
||||
|
||||
if ($info['pid'] > 0) {
|
||||
$parentName = $this->getAllFatherName($info['pid']);
|
||||
return $parentName . '/' . $info['cate_name'];
|
||||
} else {
|
||||
return $info['cate_name'];
|
||||
}
|
||||
}
|
||||
|
||||
public function getCateName($cate_id)
|
||||
{
|
||||
return $this->dao->query([$this->dao->getPk() => $cate_id])->value('cate_name') ?? '';
|
||||
}
|
||||
}
|
@ -0,0 +1,191 @@
|
||||
<?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\store\order;
|
||||
|
||||
|
||||
use app\common\dao\store\order\SupplyStoreCartDao;
|
||||
// use app\common\model\store\product\Product;
|
||||
use app\common\repositories\BaseRepository;
|
||||
// use app\common\repositories\store\coupon\StoreCouponProductRepository;
|
||||
// use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||
use app\common\repositories\store\product\SupplyProductRepository;
|
||||
// use app\common\repositories\user\MemberinterestsRepository;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* Class SupplyStoreCartRepository
|
||||
* @package app\common\repositories\store\order
|
||||
* @author xaboy
|
||||
* @day 2020/5/30
|
||||
* @mixin SupplyStoreCartDao
|
||||
*/
|
||||
class SupplyStoreCartRepository extends BaseRepository
|
||||
{
|
||||
//购物车最大条数
|
||||
const CART_LIMIT_COUNT = 99;
|
||||
|
||||
/**
|
||||
* SupplyStoreCartRepository constructor.
|
||||
* @param SupplyStoreCartDao $dao
|
||||
*/
|
||||
public function __construct(SupplyStoreCartDao $dao)
|
||||
{
|
||||
$this->dao = $dao;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uid
|
||||
* @return array
|
||||
* @author Qinii
|
||||
*/
|
||||
public function getList($user)
|
||||
{
|
||||
$res = $this->dao->getAll($user->uid)->append(['checkCartProduct', 'UserPayCount', 'ActiveSku','spu']);
|
||||
return $this->checkCartList($res, $user->uid, $user);
|
||||
}
|
||||
|
||||
public function checkCartList($res, $hasCoupon = 0, $user = null)
|
||||
{
|
||||
$arr = $fail = [];
|
||||
$product_make = app()->make(SupplyProductRepository::class);
|
||||
$svip_status = ($user && $user->is_svip > 0 && systemConfig('svip_switch_status')) ? true : false;
|
||||
foreach ($res as $item) {
|
||||
if (!$item['checkCartProduct']) {
|
||||
$item['product'] = $product_make->getFailProduct($item['product_id']);
|
||||
$fail[] = $item;
|
||||
} else {
|
||||
//商户信息
|
||||
if ($item['merchant']){
|
||||
$merchantData = $item['merchant']->append(['openReceipt'])->toArray();
|
||||
} else {
|
||||
$merchantData = ['mer_id' => 0];
|
||||
}
|
||||
unset($item['merchant']);
|
||||
// $coupon_make = app()->make(StoreCouponRepository::class);
|
||||
// if (!isset($arr[$item['mer_id']])) {
|
||||
// if ($hasCoupon)
|
||||
// $merchantData['hasCoupon'] = $coupon_make->validMerCouponExists($item['mer_id'], $hasCoupon);
|
||||
// $merchantData['hasCoupon']=0;
|
||||
// $arr[$item['mer_id']] = $merchantData;
|
||||
// }
|
||||
// if ($hasCoupon && !$arr[$item['mer_id']]['hasCoupon']) {
|
||||
// $couponIds = app()->make(StoreCouponProductRepository::class)->productByCouponId([$item['product']['product_id']]);
|
||||
// $arr[$item['mer_id']]['hasCoupon'] = count($couponIds) ? $coupon_make->validProductCouponExists([$item['product']['product_id']], $hasCoupon) : 0;
|
||||
// }
|
||||
$arr[$item['mer_id']]['hasCoupon']=0;
|
||||
if ($svip_status && $item['product']['show_svip_price']) {
|
||||
$item['productAttr']['show_svip_price'] = true;
|
||||
$item['productAttr']['org_price'] = $item['productAttr']['price'];
|
||||
$item['productAttr']['price'] = $item['productAttr']['svip_price'];
|
||||
} else {
|
||||
$item['productAttr']['show_svip_price'] = false;
|
||||
}
|
||||
$arr[$item['mer_id']]['list'][] = $item;
|
||||
}
|
||||
}
|
||||
$list = array_values($arr);
|
||||
return compact('list', 'fail');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条购物车信息
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/30
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOne(int $id,int $uid)
|
||||
{
|
||||
$where = [$this->dao->getPk() => $id,'is_del'=>0,'is_fail'=>0,'is_new'=>0,'is_pay'=>0,'uid' => $uid];
|
||||
return ($this->dao->getWhere($where));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看相同商品的sku是存在
|
||||
* @param $sku
|
||||
* @param $uid
|
||||
* @author Qinii
|
||||
*/
|
||||
public function getCartByProductSku($sku,$uid)
|
||||
{
|
||||
$where = ['is_del'=>0,'is_fail'=>0,'is_new'=>0,'is_pay'=>0,'uid' => $uid,'product_type' => 0,'product_attr_unique' => $sku];
|
||||
return ($this->dao->getWhere($where));
|
||||
}
|
||||
|
||||
|
||||
public function getProductById($productId)
|
||||
{
|
||||
$where = [
|
||||
'is_del' =>0,
|
||||
'is_new'=>0,
|
||||
'is_pay'=>0,
|
||||
'product_id'=>$productId
|
||||
];
|
||||
return $this->dao->getWhereCount($where);
|
||||
}
|
||||
|
||||
public function checkPayCountByUser($ids,$uid,$productType,$cart_num)
|
||||
{
|
||||
$storeOrderRepository = app()->make(StoreOrderRepository::class);
|
||||
$productRepository = app()->make(SupplyProductRepository::class);
|
||||
switch ($productType) {
|
||||
//普通商品
|
||||
case 0:
|
||||
$products = $productRepository->getSearch([])->where('product_id',$ids)->select();
|
||||
foreach ($products as $product) {
|
||||
if ($product['once_min_count'] > 0 && $product['once_min_count'] > $cart_num)
|
||||
throw new ValidateException('[低于起购数:'.$product['once_min_count'].']'.mb_substr($product['store_name'],0,10).'...');
|
||||
if ($product['pay_limit'] == 1 && $product['once_max_count'] < $cart_num)
|
||||
throw new ValidateException('[超出单次限购数:'.$product['once_max_count'].']'.mb_substr($product['store_name'],0,10).'...');
|
||||
if ($product['pay_limit'] == 2){
|
||||
//如果长期限购
|
||||
//已购买数量
|
||||
$count = $storeOrderRepository->getMaxCountNumber($uid,$product['product_id']);
|
||||
if (($cart_num + $count) > $product['once_max_count'])
|
||||
throw new ValidateException('[超出限购总数:'. $product['once_max_count'].']'.mb_substr($product['store_name'],0,10).'...');
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
$products = $productRepository->getSearch([])->where('product_id',$ids)->select();
|
||||
foreach ($products as $product) {
|
||||
if (!$storeOrderRepository->getDayPayCount($uid, $product['product_id'],$cart_num))
|
||||
throw new ValidateException('本次活动您购买数量已达到上限');
|
||||
if (!$storeOrderRepository->getPayCount($uid, $product['product_id'],$cart_num))
|
||||
throw new ValidateException('本次活动您该商品购买数量已达到上限');
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function create(array $data)
|
||||
{
|
||||
return Db::transaction(function() use($data) {
|
||||
if (!$data['is_new']) {
|
||||
// 查询现有多少条数据
|
||||
$query = $this->dao->getSearch(['uid' => $data['uid'],'is_new' => 0,'is_pay' => 0,'is_fail' => 0 ])->order('create_time DESC');
|
||||
$count = $query->count();
|
||||
$limit = self::CART_LIMIT_COUNT;
|
||||
//超过总限制的条数全部删除
|
||||
if ($count >= $limit) {
|
||||
$cartId = $query->limit($limit,$count)->column('cart_id');
|
||||
$this->dao->updates($cartId,['is_del' => 1]);
|
||||
}
|
||||
}
|
||||
return $this->dao->create($data);
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
<?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\store\order;
|
||||
|
||||
|
||||
use app\common\dao\store\order\SupplyStoreOrderProductDao;
|
||||
use app\common\repositories\BaseRepository;
|
||||
|
||||
/**
|
||||
* Class SupplyStoreOrderProductRepository
|
||||
* @package app\common\repositories\store\order
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
* @mixin StoreOrderProductDao
|
||||
*/
|
||||
class SupplyStoreOrderProductRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* SupplyStoreOrderProductRepository constructor.
|
||||
* @param StoreOrderProductDao $dao
|
||||
*/
|
||||
public function __construct(SupplyStoreOrderProductDao $dao)
|
||||
{
|
||||
$this->dao = $dao;
|
||||
}
|
||||
|
||||
public function getUserPayProduct(?string $keyword, int $uid, int $page, int $limit)
|
||||
{
|
||||
$query = $this->dao->getUserPayProduct($keyword, $uid)->group('product_id');
|
||||
$count = $query->count();
|
||||
$list = $query->setOption('field',[])->field('SupplyStoreOrderProduct.uid,StoreOrderProduct.product_id,StoreOrderProduct.product_type,spu_id,image,store_name,price')
|
||||
->page($page, $limit)->select()->toArray();
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
}
|
2456
app/common/repositories/store/order/SupplyStoreOrderRepository.php
Normal file
2456
app/common/repositories/store/order/SupplyStoreOrderRepository.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,105 @@
|
||||
<?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\store\parameter;
|
||||
|
||||
use app\common\dao\store\parameter\SupplyParameterValueDao;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use think\facade\Db;
|
||||
|
||||
class SupplyParameterValueRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* @var ParameterValueDao
|
||||
*/
|
||||
protected $dao;
|
||||
|
||||
|
||||
/**
|
||||
* ParameterRepository constructor.
|
||||
* @param ParameterValueDao $dao
|
||||
*/
|
||||
public function __construct(SupplyParameterValueDao $dao)
|
||||
{
|
||||
$this->dao = $dao;
|
||||
}
|
||||
|
||||
public function create($id, $data,$merId)
|
||||
{
|
||||
if (empty($data)) return ;
|
||||
foreach ($data as $datum) {
|
||||
if ($datum['name'] && $datum['value']) {
|
||||
$create[] = [
|
||||
'product_id' => $id,
|
||||
'name' => $datum['name'] ,
|
||||
'value' => $datum['value'],
|
||||
'sort' => $datum['sort'],
|
||||
'parameter_id' => $datum['parameter_id'] ?? 0,
|
||||
'mer_id' => $datum['mer_id'] ?? $merId,
|
||||
'create_time' => date('Y-m-d H:i:s',time())
|
||||
];
|
||||
}
|
||||
}
|
||||
if ($create) $this->dao->insertAll($create);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有参数的值,并合并所关联的商品ID
|
||||
* @param $where
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 2023/10/21
|
||||
*/
|
||||
public function getOptions($where)
|
||||
{
|
||||
$data = $this->dao->getSearch($where)->column('parameter_id,name','value');
|
||||
return array_values($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据筛选的参数,查询出商品ID
|
||||
* @param $filter_params
|
||||
* @param $page
|
||||
* @param $limit
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 2023/11/14
|
||||
*/
|
||||
public function filter_params($filter_params)
|
||||
{
|
||||
$productId = [];
|
||||
if (!empty($filter_params)) {
|
||||
if (!is_array($filter_params)) $filter_params = json_decode($filter_params,true);
|
||||
$value = [];
|
||||
foreach ($filter_params as $k => $v) {
|
||||
$id[] = $k;
|
||||
$value = array_merge($value,$v);
|
||||
}
|
||||
if (empty($id) || empty($value)) return false;
|
||||
$productData = $this->dao->getSearch([])->alias('P')
|
||||
->join('SupplyParameterValue V','P.product_id = V.product_id')
|
||||
->whereIn('P.parameter_id',$id)->whereIn('P.value',$value)
|
||||
->whereIn('V.parameter_id',$id)->whereIn('V.value',$value)
|
||||
->group('P.product_id')
|
||||
->field('P.product_id')
|
||||
->select();
|
||||
if ($productData) {
|
||||
$productData = $productData->toArray();
|
||||
$productId = array_column($productData,'product_id');
|
||||
}
|
||||
}
|
||||
return $productId;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,85 @@
|
||||
<?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\store\product;
|
||||
|
||||
use app\common\repositories\BaseRepository;
|
||||
use app\common\dao\store\product\SupplyProductAttrValueDao as dao;
|
||||
|
||||
/**
|
||||
* Class SupplyProductAttrValueRepository
|
||||
* @package app\common\repositories\store\product
|
||||
* @mixin dao
|
||||
*/
|
||||
class SupplyProductAttrValueRepository extends BaseRepository
|
||||
{
|
||||
|
||||
protected $dao;
|
||||
|
||||
/**
|
||||
* ProductRepository constructor.
|
||||
* @param dao $dao
|
||||
*/
|
||||
public function __construct(dao $dao)
|
||||
{
|
||||
$this->dao = $dao;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/30
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function priceCount(int $id)
|
||||
{
|
||||
return min($this->dao->getFieldColumnt('product_id',$id,'price'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/30
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function stockCount(int $id)
|
||||
{
|
||||
return $this->dao->getFieldSum('product_id',$id,'stock');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/30
|
||||
* @param int|null $merId
|
||||
* @param string $value
|
||||
* @return bool
|
||||
*/
|
||||
public function merUniqueExists(?int $merId,string $value)
|
||||
{
|
||||
return $this->dao->merFieldExists($merId,'unique',$value);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param $unique
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2020-08-05
|
||||
*/
|
||||
public function getOptionByUnique($unique)
|
||||
{
|
||||
return $this->dao->getFieldExists(null,'unique',$unique)->find();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
2587
app/common/repositories/store/product/SupplyProductRepository.php
Normal file
2587
app/common/repositories/store/product/SupplyProductRepository.php
Normal file
File diff suppressed because it is too large
Load Diff
582
app/common/repositories/store/product/SupplySpuRepository.php
Normal file
582
app/common/repositories/store/product/SupplySpuRepository.php
Normal file
@ -0,0 +1,582 @@
|
||||
<?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\store\product;
|
||||
|
||||
// use app\common\repositories\store\coupon\StoreCouponProductRepository;
|
||||
// use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||
use app\common\repositories\store\parameter\SupplyParameterValueRepository;
|
||||
// use app\common\repositories\store\pionts\PointsProductRepository;
|
||||
// use app\common\repositories\store\StoreActivityRepository;
|
||||
use app\common\repositories\user\UserRepository;
|
||||
use crmeb\jobs\SendSmsJob;
|
||||
use crmeb\jobs\SyncSupplyProductTopJob;
|
||||
use crmeb\services\CopyCommand;
|
||||
use crmeb\services\RedisCacheService;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Log;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use app\common\dao\store\product\SupplySpuDao;
|
||||
use app\common\repositories\store\SupplyStoreCategoryRepository;
|
||||
// use app\common\repositories\store\StoreSeckillActiveRepository;
|
||||
use app\common\repositories\user\UserVisitRepository;
|
||||
use think\facade\Queue;
|
||||
|
||||
class SupplySpuRepository extends BaseRepository
|
||||
{
|
||||
public $dao;
|
||||
public $merchantFiled = 'mer_id,mer_name,mer_avatar,is_trader,mer_info,mer_keyword,type_id';
|
||||
public $productFiled = 'S.product_id,S.store_name,S.image,activity_id,S.keyword,S.price,S.mer_id,spu_id,S.status,store_info,brand_id,cate_id,unit_name,S.star,S.rank,S.sort,sales,S.product_type,rate,reply_count,extension_type,S.sys_labels,S.mer_labels,P.delivery_way,P.delivery_free,S.ot_price,svip_price_type,stock,mer_svip_status';
|
||||
public function __construct(SupplySpuDao $dao)
|
||||
{
|
||||
$this->dao = $dao;
|
||||
}
|
||||
|
||||
public function create(array $param, int $productId, int $activityId, $productType = 0)
|
||||
{
|
||||
$data = $this->setparam($param, $productId, $activityId, $productType);
|
||||
return $this->dao->create($data);
|
||||
}
|
||||
|
||||
public function baseUpdate(array $param, int $productId, int $activityId, $productType = 0)
|
||||
{
|
||||
// if ($productType == 1) {
|
||||
// $make = app()->make(StoreSeckillActiveRepository::class);
|
||||
// $activityId = $make->getSearch(['product_id' => $productId])->value('seckill_active_id');
|
||||
// }
|
||||
$where = [
|
||||
'product_id' => $productId,
|
||||
'activity_id' => $activityId,
|
||||
'product_type' => $productType,
|
||||
];
|
||||
$ret = $this->dao->getSearch($where)->find();
|
||||
if (!$ret) {
|
||||
return $this->create($param, $productId, $activityId, $productType);
|
||||
} else {
|
||||
$data = $this->setparam($param, $productId, $activityId, $productType);
|
||||
|
||||
$value = $data['mer_labels'];
|
||||
if (!empty($value)) {
|
||||
if (!is_array($value)) {
|
||||
$data['mer_labels'] = ',' . $value . ',';
|
||||
} else {
|
||||
$data['mer_labels'] = ',' . implode(',', $value) . ',';
|
||||
}
|
||||
}
|
||||
return $this->dao->update($ret->spu_id, $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function setparam(array $param, $productId, $activityId, $productType)
|
||||
{
|
||||
$data = [
|
||||
'product_id' => $productId,
|
||||
'product_type' => $productType ?? 0,
|
||||
'activity_id' => $activityId,
|
||||
'store_name' => $param['store_name'],
|
||||
'keyword' => $param['keyword'] ?? '',
|
||||
'image' => $param['image'],
|
||||
'ot_price' => $param['ot_price'] ?? 0,
|
||||
'price' => $param['price'],
|
||||
'status' => 0,//$productType == PointsProductRepository::PRODUCT_TYPE_POINTS ? 1 : 0,
|
||||
'rank' => $param['rank'] ?? 0,
|
||||
'temp_id' => $param['temp_id'],
|
||||
'sort' => $param['sort'] ?? 0,
|
||||
'mer_labels' => $param['mer_labels'] ?? '',
|
||||
];
|
||||
if (isset($param['mer_id'])) $data['mer_id'] = $param['mer_id'];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 修改排序
|
||||
* @param $productId
|
||||
* @param $activityId
|
||||
* @param $productType
|
||||
* @param $data
|
||||
* @author Qinii
|
||||
* @day 1/19/21
|
||||
*/
|
||||
public function updateSort($productId, $activityId, $productType, $data)
|
||||
{
|
||||
$where = [
|
||||
'product_id' => $productId,
|
||||
'activity_id' => $activityId,
|
||||
'product_type' => $productType,
|
||||
];
|
||||
$ret = $this->dao->getSearch($where)->find();
|
||||
if ($ret) $this->dao->update($ret['spu_id'], $data);
|
||||
}
|
||||
/**
|
||||
* TODO 移动端列表
|
||||
* @param $where
|
||||
* @param $page
|
||||
* @param $limit
|
||||
* @param $userInfo
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 12/18/20
|
||||
*/
|
||||
public function getApiSearch($where, $page, $limit, $userInfo = null)
|
||||
{
|
||||
if (isset($where['keyword']) && !empty($where['keyword'])) {
|
||||
if (preg_match('/^(\/@[1-9]{1}).*\*\//', $where['keyword'])) {
|
||||
$command = app()->make(CopyCommand::class)->getMassage($where['keyword']);
|
||||
if (!$command || in_array($command['type'], [30, 40])) return ['count' => 0, 'list' => []];
|
||||
if ($userInfo && $command['uid']) app()->make(UserRepository::class)->bindSpread($userInfo, $command['uid']);
|
||||
$where['spu_id'] = $command['id'];
|
||||
unset($where['keyword']);
|
||||
} else {
|
||||
app()->make(UserVisitRepository::class)->searchProduct($userInfo ? $userInfo['uid'] : 0, $where['keyword'], (int)($where['mer_id'] ?? 0));
|
||||
}
|
||||
}
|
||||
$count = 0;
|
||||
$list = [];
|
||||
if (isset($where['filter_params']) && $where['filter_params']){
|
||||
$productIds = app()->make(SupplyParameterValueRepository::class)->filter_params($where['filter_params']);
|
||||
if (is_array($productIds)) {
|
||||
if (empty($productIds)) return compact('count', 'list');
|
||||
$where['product_ids'] = $productIds;
|
||||
}
|
||||
}
|
||||
|
||||
$where['spu_status'] = 1;
|
||||
$where['mer_status'] = 1;
|
||||
$where['not_type'] = [20];
|
||||
$query = $this->dao->search($where);
|
||||
$query->with([
|
||||
'merchant' => function ($query) {
|
||||
$query->field($this->merchantFiled)->with(['type_name']);
|
||||
},
|
||||
'issetCoupon',
|
||||
]);
|
||||
$productMake = app()->make(ProductRepository::class);
|
||||
$count = $query->count();
|
||||
|
||||
$list = $query->page($page, $limit)->setOption('field', [])->field($this->productFiled)->select();
|
||||
$append = ['stop_time','svip_price','show_svip_info','is_svip_price'];
|
||||
if ($productMake->getUserIsPromoter($userInfo))
|
||||
$append[] = 'max_extension';
|
||||
$list->append($append);
|
||||
$list = $this->getBorderList($list);
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getBorderList($list)
|
||||
{
|
||||
// $make = app()->make(StoreActivityRepository::class);
|
||||
// foreach ($list as $item) {
|
||||
// $act = $make->getActivityBySpu(StoreActivityRepository::ACTIVITY_TYPE_BORDER,$item['spu_id'],$item['cate_id'],$item['mer_id'],$item['sys_labels']);
|
||||
// $item['border_pic'] = $act['pic'] ?? '';
|
||||
// }
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO 修改状态
|
||||
* @param array $data
|
||||
* @author Qinii
|
||||
* @day 12/18/20
|
||||
*/
|
||||
public function changeStatus(int $id, int $productType, array $operate_data = [])
|
||||
{
|
||||
$make = app()->make(ProductRepository::class);
|
||||
$status = 1;
|
||||
try {
|
||||
// switch ($productType) {
|
||||
// case 0:
|
||||
// $where = [
|
||||
// 'activity_id' => 0,
|
||||
// 'product_id' => $id,
|
||||
// 'product_type' => $productType,
|
||||
// ];
|
||||
// break;
|
||||
// case 1:
|
||||
// $_make = app()->make(StoreSeckillActiveRepository::class);
|
||||
// $res = $_make->getSearch(['product_id' => $id])->find();
|
||||
// $endday = strtotime($res['end_day']);
|
||||
// if ($res['status'] == -1 || $endday < time()) $status = 0;
|
||||
// $where = [
|
||||
// 'activity_id' => $res['seckill_active_id'],
|
||||
// 'product_id' => $id,
|
||||
// 'product_type' => $productType,
|
||||
// ];
|
||||
// break;
|
||||
// case 2:
|
||||
// $_make = app()->make(ProductPresellRepository::class);
|
||||
// $res = $_make->getWhere([$_make->getPk() => $id]);
|
||||
|
||||
// $endttime = strtotime($res['end_time']);
|
||||
// if ($endttime <= time()) {
|
||||
// $status = 0;
|
||||
// } else {
|
||||
// if (
|
||||
// $res['product_status'] !== 1 ||
|
||||
// $res['status'] !== 1 ||
|
||||
// $res['action_status'] !== 1 ||
|
||||
// $res['is_del'] !== 0 ||
|
||||
// $res['is_show'] !== 1
|
||||
// ) {
|
||||
// $status = 0;
|
||||
// }
|
||||
// }
|
||||
// $where = [
|
||||
// 'activity_id' => $id,
|
||||
// 'product_id' => $res['product_id'],
|
||||
// 'product_type' => $productType,
|
||||
// ];
|
||||
// break;
|
||||
// case 3:
|
||||
// $_make = app()->make(ProductAssistRepository::class);
|
||||
// $res = $_make->getWhere([$_make->getPk() => $id]);
|
||||
|
||||
// $endttime = strtotime($res['end_time']);
|
||||
// if ($endttime <= time()) {
|
||||
// $status = 0;
|
||||
// } else {
|
||||
// if (
|
||||
// $res['product_status'] !== 1 ||
|
||||
// $res['status'] !== 1 ||
|
||||
// $res['is_show'] !== 1 ||
|
||||
// $res['action_status'] !== 1 ||
|
||||
// $res['is_del'] !== 0
|
||||
// ) {
|
||||
// $status = 0;
|
||||
// }
|
||||
// }
|
||||
|
||||
// $where = [
|
||||
// 'activity_id' => $id,
|
||||
// 'product_id' => $res['product_id'],
|
||||
// 'product_type' => $productType,
|
||||
// ];
|
||||
// break;
|
||||
// case 4:
|
||||
// $_make = app()->make(ProductGroupRepository::class);
|
||||
// $wher = $_make->actionShow();
|
||||
// $wher[$_make->getPk()] = $id;
|
||||
|
||||
// $res = $_make->getWhere([$_make->getPk() => $id]);
|
||||
// $endttime = strtotime($res['end_time']);
|
||||
// if ($endttime <= time()) {
|
||||
// $status = 0;
|
||||
// } else {
|
||||
// if (
|
||||
// $res['product_status'] !== 1 ||
|
||||
// $res['status'] !== 1 ||
|
||||
// $res['is_show'] !== 1 ||
|
||||
// $res['action_status'] !== 1 ||
|
||||
// $res['is_del'] !== 0
|
||||
// ) {
|
||||
// $status = 0;
|
||||
// }
|
||||
// }
|
||||
|
||||
// $where = [
|
||||
// 'activity_id' => $id,
|
||||
// 'product_id' => $res['product_id'],
|
||||
// 'product_type' => $productType,
|
||||
// ];
|
||||
// break;
|
||||
// default:
|
||||
// $where = [
|
||||
// 'activity_id' => 0,
|
||||
// 'product_id' => $id,
|
||||
// 'product_type' => $productType,
|
||||
// ];
|
||||
// break;
|
||||
// }
|
||||
$where = [
|
||||
'activity_id' => 0,
|
||||
'product_id' => $id,
|
||||
'product_type' => $productType,
|
||||
];
|
||||
if (empty($where)) return ;
|
||||
$ret = $make->getWhere(['product_id' => $where['product_id'],'product_type' => $productType]);
|
||||
if (
|
||||
!$ret ||
|
||||
$ret['status'] !== 1 ||
|
||||
$ret['mer_status'] !== 1 ||
|
||||
$ret['is_del'] ||
|
||||
(in_array($productType, [0, 1,20]) && ($ret['is_show'] !== 1 || $ret['is_used'] !== 1))
|
||||
) {
|
||||
$status = 0;
|
||||
}
|
||||
$result = $this->dao->getSearch($where)->find();
|
||||
if (!$result && $ret){
|
||||
$result = $this->create($ret->toArray(), $where['product_id'], $where['activity_id'], $productType);
|
||||
}
|
||||
if ($result) $this->dao->update($result['spu_id'], ['status' => $status]);
|
||||
if ($productType == 0) {
|
||||
Queue::push(SyncSupplyProductTopJob::class,[]);
|
||||
if ($status == 1) Queue(SendSmsJob::class, ['tempId' => 'PRODUCT_INCREASE', 'id' => $id]);
|
||||
// 记录操作日志
|
||||
if (!empty($operate_data)) {
|
||||
$make->addChangeStatusLog($operate_data['field'], $operate_data['status'], $operate_data['admin_info'], $ret);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
Log::info($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 平台编辑商品同步修改
|
||||
* @param int $id
|
||||
* @param int $productId
|
||||
* @param int $productType
|
||||
* @param array $data
|
||||
* @author Qinii
|
||||
* @day 12/18/20
|
||||
*/
|
||||
public function changRank(int $id, int $productId, int $productType, array $data)
|
||||
{
|
||||
$where = [
|
||||
'product_id' => $productId,
|
||||
'product_type' => $productType,
|
||||
'activity_id' => $id,
|
||||
];
|
||||
$res = $this->dao->getWhere($where);
|
||||
if (!$res && $id) $this->changeStatus($id, $productType);
|
||||
$res = $this->dao->getWhere($where);
|
||||
if ($res) {
|
||||
$res->store_name = $data['store_name'];
|
||||
$res->rank = $data['rank'];
|
||||
$res->star = $data['star'] ?? 1;
|
||||
$res->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 同步各类商品到spu表
|
||||
* @param array|null $productType
|
||||
* @author Qinii
|
||||
* @day 12/25/20
|
||||
*/
|
||||
public function updateSpu(?array $productType)
|
||||
{
|
||||
if (!$productType) $productType = [0, 1, 2, 3, 4, 20];
|
||||
$_product_make = app()->make(ProductRepository::class);
|
||||
foreach ($productType as $value) {
|
||||
$_product_make->activitSearch($value)->chunk(100, function ($product) use ($_product_make) {
|
||||
$data = $_product_make->commandChangeProductStatus($product->toArray());
|
||||
$this->dao->findOrCreateAll($data);
|
||||
echo count($data) . '条数据处理成功' . PHP_EOL;
|
||||
}, 'P.product_id');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 获取活动商品的一级分类
|
||||
* @param $type
|
||||
* @return mixed
|
||||
* @author Qinii +0
|
||||
* @day 1/12/21
|
||||
*/
|
||||
public function getActiveCategory($type)
|
||||
{
|
||||
$pathArr = $this->dao->getActivecategory($type);
|
||||
$path = [];
|
||||
foreach ($pathArr as $item) {
|
||||
$path[] = explode('/', $item)[1];
|
||||
}
|
||||
$path = array_unique($path);
|
||||
$cat = app()->make(SupplyStoreCategoryRepository::class)->getSearch(['ids' => $path])->field('store_category_id,cate_name')->select();
|
||||
return $cat;
|
||||
}
|
||||
|
||||
public function getSpuData($id, $productType, $merId)
|
||||
{
|
||||
// try {
|
||||
// switch ($productType) {
|
||||
// case 0:
|
||||
// $where = [
|
||||
// 'activity_id' => 0,
|
||||
// 'product_id' => $id,
|
||||
// 'product_type' => $productType,
|
||||
// ];
|
||||
// break;
|
||||
// case 1:
|
||||
// $_make = app()->make(StoreSeckillActiveRepository::class);
|
||||
// $res = $_make->getSearch(['product_id' => $id])->find();
|
||||
// $where = [
|
||||
// 'activity_id' => $res['seckill_active_id'],
|
||||
// 'product_id' => $id,
|
||||
// 'product_type' => $productType,
|
||||
// ];
|
||||
// break;
|
||||
// case 2:
|
||||
// $_make = app()->make(ProductPresellRepository::class);
|
||||
// $res = $_make->getWhere([$_make->getPk() => $id]);
|
||||
// $where = [
|
||||
// 'activity_id' => $id,
|
||||
// 'product_id' => $res['product_id'],
|
||||
// 'product_type' => $productType,
|
||||
// ];
|
||||
// break;
|
||||
// case 3:
|
||||
// $_make = app()->make(ProductAssistRepository::class);
|
||||
// $res = $_make->getWhere([$_make->getPk() => $id]);
|
||||
// $where = [
|
||||
// 'activity_id' => $id,
|
||||
// 'product_id' => $res['product_id'],
|
||||
// 'product_type' => $productType,
|
||||
// ];
|
||||
// break;
|
||||
// case 4:
|
||||
// $_make = app()->make(ProductGroupRepository::class);
|
||||
// $where[$_make->getPk()] = $id;
|
||||
// $res = $_make->getWhere([$_make->getPk() => $id]);
|
||||
// $where = [
|
||||
// 'activity_id' => $id,
|
||||
// 'product_id' => $res['product_id'],
|
||||
// 'product_type' => $productType,
|
||||
// ];
|
||||
// break;
|
||||
// default:
|
||||
// $where = [
|
||||
// 'activity_id' => 0,
|
||||
// 'product_id' => $id,
|
||||
// 'product_type' => 0,
|
||||
// ];
|
||||
// break;
|
||||
// }
|
||||
// } catch (\Exception $e) {
|
||||
// throw new ValidateException('数据不存在');
|
||||
// }
|
||||
$where = [
|
||||
'activity_id' => 0,
|
||||
'product_id' => $id,
|
||||
'product_type' => $productType,
|
||||
];
|
||||
if ($merId) $where['mer_id'] = $merId;
|
||||
$result = $this->dao->getSearch($where)->find();
|
||||
if (!$result) throw new ValidateException('数据不存在');
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setLabels($id, $productType, $data, $merId = 0)
|
||||
{
|
||||
$field = isset($data['sys_labels']) ? 'sys_labels' : 'mer_labels';
|
||||
if ($data[$field]) app()->make(ProductLabelRepository::class)->checkHas($merId, $data[$field]);
|
||||
$ret = $this->getSpuData($id, $productType, $merId);
|
||||
$value = $data[$field] ? $data[$field] : '';
|
||||
$ret->$field = $value;
|
||||
$ret->save();
|
||||
}
|
||||
|
||||
public function batchLabels($ids, $data,$merId)
|
||||
{
|
||||
$ids = is_array($ids) ? $ids : explode(',',$ids);
|
||||
foreach ($ids as $id) {
|
||||
$this->setLabels($id,0,$data,$merId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getApiSearchByCoupon($where, $page, $limit, $userInfo)
|
||||
{
|
||||
// $coupon = app()->make(StoreCouponRepository::class)->search(null, [
|
||||
// 'status' => 1,
|
||||
// 'coupon_id' => $where['coupon_id']
|
||||
// ])->find();
|
||||
// $data['coupon'] = $coupon;
|
||||
// if ($coupon) {
|
||||
// switch ($coupon['type']) {
|
||||
// case 0:
|
||||
// case 2:
|
||||
// $where['mer_id'] = $coupon['mer_id'];
|
||||
// break;
|
||||
// case 1:
|
||||
// $where['product_ids'] = app()->make(StoreCouponProductRepository::class)->search([
|
||||
// 'coupon_id' => $where['coupon_id']
|
||||
// ])->column('product_id');
|
||||
// break;
|
||||
// case 11:
|
||||
// $ids = app()->make(StoreCouponProductRepository::class)->search([
|
||||
// 'coupon_id' => $where['coupon_id']
|
||||
// ])->column('product_id');
|
||||
// $where['cate_pid'] = $ids;
|
||||
// break;
|
||||
// case 10:
|
||||
// case 13:
|
||||
// break;
|
||||
// case 12:
|
||||
// $ids = app()->make(StoreCouponProductRepository::class)->search([
|
||||
// 'coupon_id' => $where['coupon_id']
|
||||
// ])->column('product_id');
|
||||
// $where['mer_ids'] = $ids;
|
||||
// break;
|
||||
// }
|
||||
// $where['is_coupon'] = 1;
|
||||
// $where['order'] = 'star';
|
||||
// $where['common'] = 1;
|
||||
// // $where['svip'] = ($coupon['send_type'] == StoreCouponRepository::GET_COUPON_TYPE_SVIP) ? 1 : '';
|
||||
// $product = $this->getApiSearch($where, $page, $limit, $userInfo);
|
||||
// }
|
||||
|
||||
$data['count'] = 0;//$product['count'] ?? 0;
|
||||
$data['list'] =[];// $product['list'] ?? [];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getHotRanking(int $cateId, $limit = 15)
|
||||
{
|
||||
$RedisCacheService = app()->make(RedisCacheService::class);
|
||||
$prefix = env('queue_name','merchant').'_hot_ranking_';
|
||||
$ids = $RedisCacheService->handler()->get($prefix.'top_' . intval($cateId));
|
||||
$ids = $ids ? explode(',', $ids) : [];
|
||||
if (!count($ids)) {
|
||||
return [];
|
||||
}
|
||||
$ids = array_map('intval', $ids);
|
||||
$where['mer_status'] = 1;
|
||||
$where['status'] = 1;
|
||||
$where['is_del'] = 0;
|
||||
$where['product_type'] = 0;
|
||||
$where['order'] = 'sales';
|
||||
$where['spu_ids'] = $ids;
|
||||
$list = $this->dao->search($where)->setOption('field',[])->field('spu_id,S.image,S.price,S.product_type,P.product_id,P.sales,S.status,S.store_name,P.ot_price,P.cost')->limit($limit)->select();
|
||||
if ($list) $list = $list->toArray();
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param $where
|
||||
* @param $page
|
||||
* @param $limit
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 2022/9/22
|
||||
*/
|
||||
public function makinList($where,$page, $limit)
|
||||
{
|
||||
$where['spu_status'] = 1;
|
||||
$where['mer_status'] = 1;
|
||||
$query = $this->dao->search($where);
|
||||
$query->with([
|
||||
'merchant' ,
|
||||
'issetCoupon',
|
||||
]);
|
||||
$count = $query->count();
|
||||
$list = $query->page($page, $limit)->setOption('field', [])->field($this->productFiled)->select();
|
||||
return compact('count','list');
|
||||
}
|
||||
|
||||
public function updatePrice($mer_id, $product_id, $price)
|
||||
{
|
||||
return $this->dao->updatePrice($mer_id, $product_id, $price);
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@ use crmeb\services\UploadService;
|
||||
use think\App;
|
||||
use crmeb\basic\BaseController;
|
||||
use app\validate\supply\StoreProductValidate as validate;
|
||||
use app\common\repositories\store\product\ProductRepository as repository;
|
||||
use app\common\repositories\store\product\SupplyProductRepository as repository;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Cache;
|
||||
|
||||
|
44
crmeb/jobs/ChangeSupplySpuStatusJob.php
Normal file
44
crmeb/jobs/ChangeSupplySpuStatusJob.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace crmeb\jobs;
|
||||
|
||||
use app\common\repositories\store\product\SupplySpuRepository;
|
||||
use crmeb\interfaces\JobInterface;
|
||||
use think\facade\Log;
|
||||
|
||||
class ChangeSupplySpuStatusJob implements JobInterface
|
||||
{
|
||||
|
||||
public function fire($job, $data)
|
||||
{
|
||||
try{
|
||||
$make = app()->make(SupplySpuRepository::class);
|
||||
if (is_array($data['id'])){
|
||||
foreach ($data['id'] as $i) {
|
||||
$make->changeStatus($i, $data['product_type'], $data['operate_data'] ?? []);
|
||||
}
|
||||
} else if(is_numeric($data['id'])){
|
||||
$make->changeStatus($data['id'], $data['product_type'], $data['operate_data'] ?? []);
|
||||
}
|
||||
}catch (\Exception $exception){
|
||||
Log::info($exception->getMessage());
|
||||
}
|
||||
$job->delete();
|
||||
}
|
||||
|
||||
public function failed($data)
|
||||
{
|
||||
// TODO: Implement failed() method.
|
||||
}
|
||||
}
|
76
crmeb/jobs/SyncSupplyProductTopJob.php
Normal file
76
crmeb/jobs/SyncSupplyProductTopJob.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace crmeb\jobs;
|
||||
|
||||
use app\common\repositories\store\product\SupplySpuRepository;
|
||||
use app\common\repositories\store\SupplyStoreCategoryRepository;
|
||||
use crmeb\interfaces\JobInterface;
|
||||
use crmeb\services\RedisCacheService;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Log;
|
||||
use function app;
|
||||
|
||||
class SyncSupplyProductTopJob implements JobInterface
|
||||
{
|
||||
|
||||
public function fire($job, $data)
|
||||
{
|
||||
try{
|
||||
$hot = systemConfig(['hot_ranking_switch','hot_ranking_lv']);
|
||||
if ($hot['hot_ranking_switch'] != 1) return $job->delete();
|
||||
|
||||
$SpuRepository = app()->make(SupplySpuRepository::class);
|
||||
$RedisCacheService = app()->make(RedisCacheService::class);
|
||||
$prefix = env('queue_name','merchant').'_hot_ranking_';
|
||||
$oldKeys1 = $RedisCacheService->keys($prefix.'top_*') ?: [];
|
||||
$oldKeys1 = array_combine($oldKeys1, $oldKeys1);
|
||||
$mset = [];
|
||||
$where = ['product_type' => 0, 'spu_status' => 1, 'mer_status' => 1, 'order' => 'sales'];
|
||||
$ids = $SpuRepository->search($where)->limit(15)->column('spu_id');
|
||||
$mset[$prefix.'top_0'] = implode(',', $ids);
|
||||
unset($oldKeys1[$prefix.'top_0']);
|
||||
$make = app()->make(SupplyStoreCategoryRepository::class);
|
||||
foreach ([1,2,3] as $level) {
|
||||
$cateList = $make->getSearch(['status' => 1, 'mer_id' => 0, 'type' => 0])
|
||||
->where('level','<',$level)->column('store_category_id,cate_name,pic');
|
||||
foreach ($cateList as $item) {
|
||||
$id = $item['store_category_id'];
|
||||
$ids = $make->findChildrenId($id);
|
||||
$ids[] = $id;
|
||||
$where['cate_id'] = $ids;
|
||||
$spuList = $SpuRepository->search($where)->limit(15)->select();
|
||||
if (count($spuList)) {
|
||||
foreach ($spuList as $i => $spu) {
|
||||
$key = $prefix.'top_item_' . $id . '_' . $spu['spu_id'];
|
||||
$mset[$key] = json_encode([$item['cate_name'], $i + 1, $id], JSON_UNESCAPED_UNICODE);
|
||||
unset($oldKeys1[$key]);
|
||||
}
|
||||
$_key = $prefix.'top_' . $id;
|
||||
$mset[$_key] = implode(',', $spuList->column('spu_id'));
|
||||
unset($oldKeys1[$_key]);
|
||||
}
|
||||
}
|
||||
Cache::set($prefix.'topCate', implode(',', array_column($cateList, 'store_category_id')));
|
||||
}
|
||||
if (count($mset)) {
|
||||
$RedisCacheService->mSet($mset);
|
||||
}
|
||||
if (count($oldKeys1)) {
|
||||
$RedisCacheService->handler()->del(...array_values($oldKeys1));
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
Log::info('热卖排行统计:' . $e->getMessage());
|
||||
}
|
||||
$job->delete();
|
||||
}
|
||||
|
||||
public function failed($data)
|
||||
{
|
||||
// TODO: Implement failed() method.
|
||||
}
|
||||
|
||||
public function work()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -122,7 +122,7 @@ Route::group(function () {
|
||||
//配置
|
||||
Route::group( function () {
|
||||
Route::get('config', 'merchant.Common/config');
|
||||
Route::get('menus', 'admin.system.auth.Menu/merchantMenus')->append(['merchant' => 1]);
|
||||
Route::get('menus', 'admin.system.auth.Menu/merchantMenus')->append(['merchant' => 2]);
|
||||
Route::get('logout', 'merchant.system.admin.Login/logout');
|
||||
//获取版本号
|
||||
Route::get('version', 'admin.Common/version');
|
||||
|
Loading…
x
Reference in New Issue
Block a user