Merge branch 'profit_sharing' into dev
This commit is contained in:
commit
f530fe181f
@ -307,4 +307,16 @@ abstract class BaseDao
|
|||||||
$query->where('is_del', $isDel);
|
$query->where('is_del', $isDel);
|
||||||
})->count($this->getPk()) > 0;
|
})->count($this->getPk()) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量新增或更新
|
||||||
|
* @param $list
|
||||||
|
* @return Collection
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function saveAll($list)
|
||||||
|
{
|
||||||
|
return ($this->getModel()::getInstance())->saveAll($list);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
30
app/common/dao/store/product/CloudProductDao.php
Normal file
30
app/common/dao/store/product/CloudProductDao.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?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\CloudProduct;
|
||||||
|
|
||||||
|
class CloudProductDao extends BaseDao
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function getModel(): string
|
||||||
|
{
|
||||||
|
return CloudProduct::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function search(array $where)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
30
app/common/model/store/product/CloudProduct.php
Normal file
30
app/common/model/store/product/CloudProduct.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?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 CloudProduct extends BaseModel
|
||||||
|
{
|
||||||
|
|
||||||
|
public static function tablePk(): string
|
||||||
|
{
|
||||||
|
return 'product_id';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tableName(): string
|
||||||
|
{
|
||||||
|
return 'cloud_product';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -28,6 +28,11 @@ use app\common\repositories\store\StoreActivityRepository;
|
|||||||
class Merchant extends BaseModel
|
class Merchant extends BaseModel
|
||||||
{
|
{
|
||||||
|
|
||||||
|
const TypeStore = 10; //镇街店铺
|
||||||
|
const TypeCloudWarehouse = 11; //里海云仓
|
||||||
|
const TypeSupplyChain = 12; //市级供应链
|
||||||
|
const TypePlatform = 13; //供销平台
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
* @author xaboy
|
* @author xaboy
|
||||||
|
@ -241,8 +241,8 @@ class ProductRepository extends BaseRepository
|
|||||||
$product['mer_labels'] = $data['mer_labels'];
|
$product['mer_labels'] = $data['mer_labels'];
|
||||||
app()->make(SpuRepository::class)->create($product, $result->product_id, $activity_id, $productType);
|
app()->make(SpuRepository::class)->create($product, $result->product_id, $activity_id, $productType);
|
||||||
}
|
}
|
||||||
$product = $result;
|
// $product = $result;
|
||||||
event('product.create',compact('product'));
|
// event('product.create',compact('product'));
|
||||||
return $result->product_id;
|
return $result->product_id;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -284,6 +284,9 @@ class ProductRepository extends BaseRepository
|
|||||||
}
|
}
|
||||||
app()->make(SpuRepository::class)->baseUpdate($spuData, $id, 0, $productType);
|
app()->make(SpuRepository::class)->baseUpdate($spuData, $id, 0, $productType);
|
||||||
event('product.update',compact('id'));
|
event('product.update',compact('id'));
|
||||||
|
if ($data['status'] == 0) {
|
||||||
|
event('product.sell', ['source_mer_id' => $merId, 'product_id' => [$id], 'status' => $data['status']]);
|
||||||
|
}
|
||||||
app()->make(SpuRepository::class)->changeStatus($id, $productType);
|
app()->make(SpuRepository::class)->changeStatus($id, $productType);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1569,12 +1572,7 @@ class ProductRepository extends BaseRepository
|
|||||||
throw new ValidateException('商品spu更新出错');
|
throw new ValidateException('商品spu更新出错');
|
||||||
}else{
|
}else{
|
||||||
if ($product->product_type==0){
|
if ($product->product_type==0){
|
||||||
$RedisCacheService = app()->make(RedisCacheService::class);
|
event('product.sell', ['source_mer_id' => $merId, 'product_id' => [$id], 'status' => $status]);
|
||||||
if ($status==1){
|
|
||||||
$RedisCacheService->SADD ('CloudMerchanSpu'.$product['mer_id'], $product['product_id']);
|
|
||||||
}else{
|
|
||||||
$RedisCacheService->SREM ('CloudMerchanSpu'.$product['mer_id'], $product['product_id']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
@ -1596,20 +1594,20 @@ class ProductRepository extends BaseRepository
|
|||||||
if ($status == 1 && $product['product_type'] == 3)
|
if ($status == 1 && $product['product_type'] == 3)
|
||||||
throw new ValidateException('ID:'.$product->product_id . ' 商品正在参与助力活动');
|
throw new ValidateException('ID:'.$product->product_id . ' 商品正在参与助力活动');
|
||||||
}
|
}
|
||||||
$this->dao->updates($id,[$field => $status]);
|
Db::startTrans();
|
||||||
if ($product->product_type==0){
|
try {
|
||||||
$RedisCacheService = app()->make(RedisCacheService::class);
|
if ($this->dao->updates($id,[$field => $status]) === false) {
|
||||||
if ($status==1){
|
throw new \Exception('商品操作出错');
|
||||||
foreach ($id as $k=>$v){
|
|
||||||
$RedisCacheService->SADD ('CloudMerchanSpu'.$product['mer_id'], $v);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
foreach ($id as $k=>$v){
|
|
||||||
$RedisCacheService->SREM ('CloudMerchanSpu'.$product['mer_id'], $v);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if ($product->product_type==0){
|
||||||
|
event('product.sell', ['source_mer_id' => $merId, 'product_id' => $id, 'status' => $status]);
|
||||||
|
}
|
||||||
|
Db::commit();
|
||||||
|
Queue::push(ChangeSpuStatusJob::class,['id' => $id,'product_type'=> $product_type]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Db::rollback();
|
||||||
|
throw new ValidateException($e->getMessage());
|
||||||
}
|
}
|
||||||
Queue::push(ChangeSpuStatusJob::class,['id' => $id,'product_type'=> $product_type]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,6 +19,7 @@ use crmeb\jobs\SyncProductTopJob;
|
|||||||
use crmeb\services\CopyCommand;
|
use crmeb\services\CopyCommand;
|
||||||
use crmeb\services\RedisCacheService;
|
use crmeb\services\RedisCacheService;
|
||||||
use think\exception\ValidateException;
|
use think\exception\ValidateException;
|
||||||
|
use think\facade\Db;
|
||||||
use think\facade\Log;
|
use think\facade\Log;
|
||||||
use app\common\repositories\BaseRepository;
|
use app\common\repositories\BaseRepository;
|
||||||
use app\common\dao\store\product\SpuDao;
|
use app\common\dao\store\product\SpuDao;
|
||||||
@ -157,27 +158,32 @@ class SpuRepository extends BaseRepository
|
|||||||
return compact('count', 'list');
|
return compact('count', 'list');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getApiCloudSearch($where, $page, $limit)
|
public function getApiCloudSearch($where, $page, $limit, $rand = true)
|
||||||
{
|
{
|
||||||
$where['spu_status'] = 1;
|
$where['spu_status'] = 1;
|
||||||
$where['mer_status'] = 1;
|
$where['mer_status'] = 1;
|
||||||
$RedisCacheService = app()->make(RedisCacheService::class);
|
if ($rand) {
|
||||||
$exists=$RedisCacheService->exists('CloudMerchanSpu'.$where['mer_id']);
|
$RedisCacheService = app()->make(RedisCacheService::class);
|
||||||
if ($exists){
|
$exists=$RedisCacheService->exists('CloudMerchantSpu'.$where['mer_id']);
|
||||||
$Spu_arr=$RedisCacheService->SRANDMEMBER('CloudMerchanSpu'.$where['mer_id'], 10);
|
if ($exists){
|
||||||
$where['product_id'] =$Spu_arr;
|
$Spu_arr=$RedisCacheService->SRANDMEMBER('CloudMerchantSpu'.$where['mer_id'], 10);
|
||||||
|
$where['product_id'] =$Spu_arr;
|
||||||
|
} else {
|
||||||
|
//TODO 后期优化随机查询
|
||||||
|
$where['product_id'] = Db::name('cloud_product')->where('mer_id', $where['mer_id'])->where('status', 1)->orderRand()->limit(10)->column('product_id');
|
||||||
|
}
|
||||||
|
unset($where['mer_id']);
|
||||||
}
|
}
|
||||||
$query = $this->dao->search($where);
|
$query = $this->dao->search($where);
|
||||||
|
|
||||||
$count = 0;
|
$count = $query->count();
|
||||||
// $Sql=$query->page($page, $limit)->setOption('field', [])->field($this->productFiled)->fetchSql(true);
|
|
||||||
$query->with([
|
$query->with([
|
||||||
'merchant' => function ($query) {
|
'merchant' => function ($query) {
|
||||||
$query->field($this->merchantFiled)->with(['type_name']);
|
$query->field($this->merchantFiled)->with(['type_name']);
|
||||||
},
|
},
|
||||||
'issetCoupon',
|
'issetCoupon',
|
||||||
]);
|
]);
|
||||||
$list = $query->setOption('field', [])->field($this->productFiled)->select();
|
$list = $query->setOption('field', [])->field($this->productFiled)->page($page)->limit($limit)->select();
|
||||||
$append = ['stop_time','svip_price','show_svip_info','is_svip_price'];
|
$append = ['stop_time','svip_price','show_svip_info','is_svip_price'];
|
||||||
|
|
||||||
$list->append($append);
|
$list->append($append);
|
||||||
|
@ -496,7 +496,8 @@ class Common extends BaseController
|
|||||||
public function get_cloud_shop($street_code){
|
public function get_cloud_shop($street_code){
|
||||||
$find=DB::name('merchant')->alias('m')->where('m.type_id',11)->where('m.is_del',0)->where('m.status',1)
|
$find=DB::name('merchant')->alias('m')->where('m.type_id',11)->where('m.is_del',0)->where('m.status',1)
|
||||||
->join('merchant_address a','a.mer_id=m.mer_id and a.street_id='.$street_code)
|
->join('merchant_address a','a.mer_id=m.mer_id and a.street_id='.$street_code)
|
||||||
->field('m.mer_id')->find();
|
->join('merchant_category c','m.category_id=c.merchant_category_id')
|
||||||
|
->field('m.mer_id,category_id,category_name')->select();
|
||||||
return app('json')->success($find??[]);
|
return app('json')->success($find??[]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
66
app/controller/api/store/product/CloudWarehouse.php
Normal file
66
app/controller/api/store/product/CloudWarehouse.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\controller\api\store\product;
|
||||||
|
|
||||||
|
use app\common\dao\system\merchant\MerchantDao;
|
||||||
|
use app\common\model\system\merchant\Merchant;
|
||||||
|
use app\common\repositories\store\product\SpuRepository;
|
||||||
|
use think\App;
|
||||||
|
use crmeb\basic\BaseController;
|
||||||
|
|
||||||
|
class CloudWarehouse extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SpuRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
/**
|
||||||
|
* @var MerchantDao
|
||||||
|
*/
|
||||||
|
protected $merchantDao;
|
||||||
|
/**
|
||||||
|
* @var SpuRepository
|
||||||
|
*/
|
||||||
|
protected $spuRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StoreProduct constructor.
|
||||||
|
* @param App $app
|
||||||
|
* @param SpuRepository $repository
|
||||||
|
* @param MerchantDao $merchantDao
|
||||||
|
*/
|
||||||
|
public function __construct(App $app, SpuRepository $repository, MerchantDao $merchantDao, SpuRepository $spuRepository)
|
||||||
|
{
|
||||||
|
parent::__construct($app);
|
||||||
|
$this->repository = $repository;
|
||||||
|
$this->merchantDao = $merchantDao;
|
||||||
|
$this->spuRepository = $spuRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定类型的云仓商品列表
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$params = $this->request->params(['category_id', 'street_code', 'order', ['product_type', 0]]);
|
||||||
|
$search = [
|
||||||
|
'street_id' => $params['street_code'],
|
||||||
|
'type_id' => Merchant::TypeStore,
|
||||||
|
'category_id' => $params['category_id'],
|
||||||
|
];
|
||||||
|
$merchantIds = $this->merchantDao->search($search)->column('mer_id');
|
||||||
|
[$page, $limit] = $this->getPage();
|
||||||
|
if (empty($merchantIds)) {
|
||||||
|
return app('json')->success(['count' => 0, 'list' => []]);
|
||||||
|
}
|
||||||
|
$where['mer_ids'] = $merchantIds;
|
||||||
|
$where['product_type'] = $params['product_type'];
|
||||||
|
$where['is_gift_bag'] = 0;
|
||||||
|
$where['order'] = $params['order'] ?: 'sort';
|
||||||
|
$products = $this->spuRepository->getApiCloudSearch($where, $page, $limit, false);
|
||||||
|
return app('json')->success($products);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -65,6 +65,7 @@ return [
|
|||||||
'community_address'=>[\app\listener\CommunityAddress::class],
|
'community_address'=>[\app\listener\CommunityAddress::class],
|
||||||
// 'order.paySuccess'=>[\app\listener\OrderPaySuccess::class],
|
// 'order.paySuccess'=>[\app\listener\OrderPaySuccess::class],
|
||||||
'product.create'=>[\app\listener\ProductCreate::class],
|
'product.create'=>[\app\listener\ProductCreate::class],
|
||||||
|
'product.sell'=>[\app\listener\CloudProduct::class], //商品上下架
|
||||||
],
|
],
|
||||||
|
|
||||||
'subscribe' => [],
|
'subscribe' => [],
|
||||||
|
40
app/listener/CloudProduct.php
Normal file
40
app/listener/CloudProduct.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare (strict_types=1);
|
||||||
|
|
||||||
|
namespace app\listener;
|
||||||
|
|
||||||
|
use app\common\dao\store\product\CloudProductDao;
|
||||||
|
use app\common\model\system\merchant\Merchant;
|
||||||
|
use crmeb\services\RedisCacheService;
|
||||||
|
|
||||||
|
class CloudProduct
|
||||||
|
{
|
||||||
|
|
||||||
|
public function handle($event)
|
||||||
|
{
|
||||||
|
$categoryId = Merchant::getDB()->where('mer_id', $event['source_mer_id'])->value('category_id');
|
||||||
|
$cloudMerchant = Merchant::getDB()->where(['type_id' => Merchant::TypeCloudWarehouse, 'category_id' => $categoryId, 'status' => 1, 'mer_state' => 1])->value('mer_id');
|
||||||
|
if ($cloudMerchant) {
|
||||||
|
$list = [];
|
||||||
|
foreach ($event['product_id'] as $productId) {
|
||||||
|
$list[] = [
|
||||||
|
'mer_id' => $cloudMerchant,
|
||||||
|
'source_mer_id' => $event['source_mer_id'],
|
||||||
|
'product_id' => $productId,
|
||||||
|
'status' => $event['status'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
app()->make(CloudProductDao::class)->saveAll($list);
|
||||||
|
$RedisCacheService = app()->make(RedisCacheService::class);
|
||||||
|
foreach ($event['product_id'] as $productId) {
|
||||||
|
if ($event['status'] == 1) {
|
||||||
|
$RedisCacheService->SADD('CloudMerchantSpu' . $cloudMerchant, $productId);
|
||||||
|
} else {
|
||||||
|
$RedisCacheService->SREM('CloudMerchantSpu' . $cloudMerchant, $productId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -532,6 +532,7 @@ Route::group('api/', function () {
|
|||||||
//test
|
//test
|
||||||
Route::any('store/test', 'api.Test/test');
|
Route::any('store/test', 'api.Test/test');
|
||||||
Route::get('subscribe', 'api.Common/subscribe');
|
Route::get('subscribe', 'api.Common/subscribe');
|
||||||
|
Route::resource('store/product/cloudWarehouse', 'api.store.product.CloudWarehouse');
|
||||||
|
|
||||||
})->middleware(UserTokenMiddleware::class, false);
|
})->middleware(UserTokenMiddleware::class, false);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user