Merge pull request 'dev' (#9) from dev into master

Reviewed-on: http://git.excellentkk.cn/mkm/shop-php/pulls/9
This commit is contained in:
mkm 2023-05-22 11:32:10 +08:00
commit b0e7b1644e
11 changed files with 149 additions and 26 deletions

View File

@ -52,6 +52,9 @@ class SpuDao extends BaseDao
$query->when(isset($where['is_del']) && $where['is_del'] !== '',function($query)use($where){
$query->where('P.is_del',$where['is_del']);
})
->when(isset($where['product_id']) && $where['product_id'] !== '',function($query)use($where){
$query->where('P.product_id','in',$where['product_id']);
})
->when(isset($where['mer_id']) && $where['mer_id'] !== '',function($query)use($where){
$query->where('P.mer_id',$where['mer_id']);
})

View File

@ -20,6 +20,13 @@ use app\common\model\system\merchant\FinancialRecord;
class FinancialRecordDao extends BaseDao
{
const Outlay = 0; //支出
const Income = 1; //收入
const TypeMerchant = 0; //商户
const TypeCommon = 1; //公共
const TypePlatform = 2; //平台
protected function getModel(): string
{
return FinancialRecord::class;

View File

@ -12,8 +12,10 @@
namespace app\common\repositories\store\order;
use app\common\dao\store\order\StoreOrderDao;
use app\common\dao\system\merchant\FinancialRecordDao;
use app\common\model\store\order\StoreGroupOrder;
use app\common\model\store\order\StoreOrder;
use app\common\model\system\merchant\Merchant;
use app\common\model\user\User;
use app\common\repositories\BaseRepository;
use app\common\repositories\delivery\DeliveryOrderRepository;
@ -374,6 +376,10 @@ class StoreOrderRepository extends BaseRepository
$_payPrice = bcadd($_payPrice, $order->platform_coupon_price, 2);
}
if ($_payPrice > 0) {
$this->autoMargin($_payPrice, $order, $finance, $financeSn, $i);
}
if (!$is_combine) {
app()->make(MerchantRepository::class)->addLockMoney($order->mer_id, 'order', $order->order_id, $_payPrice);
}
@ -450,6 +456,39 @@ class StoreOrderRepository extends BaseRepository
}
/**
* 自动扣除保证金
* @param $income
* @param $order
* @param $finance
* @param $financeSn
* @param $index
* @return void
*/
public function autoMargin(&$income, $order, &$finance, $financeSn, $index = 0)
{
$merchant = Merchant::find($order->mer_id);
//商户保证金未完全缴纳且设置了自动扣除比例
if ($merchant['margin'] > $merchant['paid_margin'] && $merchant['auto_margin_rate'] > 0 && $merchant['auto_margin_rate'] <= 100) {
$margin = bcmul($income, $merchant['auto_margin_rate'] / 100, 2);
$margin = min(bcsub($merchant['margin'], $merchant['paid_margin'], 2), $margin);
$income = max(bcsub($income, $margin, 2), 0);
$finance[] = [
'order_id' => $order->order_id,
'order_sn' => $order->order_sn,
'user_info' => $order->user->nickname,
'user_id' => $order->uid,
'financial_type' => 'auto_margin',
'financial_pm' => FinancialRecordDao::Outlay,
'type' => FinancialRecordDao::TypePlatform,
'number' => $margin,
'mer_id' => $order->mer_id,
'financial_record_sn' => $financeSn . $index
];
$merchant->save(['paid_margin' => bcadd($merchant['paid_margin'], $margin, 2)]);
}
}
/**
* 自动打印
* @Author:Qinii

View File

@ -1563,9 +1563,19 @@ class ProductRepository extends BaseRepository
Db::rollback();
throw new ValidateException('商品更新出错');
}
if (app()->make(SpuRepository::class)->changeStatus($id, $product->product_type) === false) {
$changeStatus= app()->make(SpuRepository::class)->changeStatus($id, $product->product_type);
if ($changeStatus=== false) {
Db::rollback();
throw new ValidateException('商品spu更新出错');
}else{
if ($product->product_type==0){
$RedisCacheService = app()->make(RedisCacheService::class);
if ($status==1){
$RedisCacheService->SADD ('CloudMerchanSpu'.$product['mer_id'], $product['product_id']);
}else{
$RedisCacheService->SREM ('CloudMerchanSpu'.$product['mer_id'], $product['product_id']);
}
}
}
Db::commit();
}

View File

@ -161,9 +161,15 @@ class SpuRepository extends BaseRepository
{
$where['spu_status'] = 1;
$where['mer_status'] = 1;
$RedisCacheService = app()->make(RedisCacheService::class);
$exists=$RedisCacheService->exists('CloudMerchanSpu'.$where['mer_id']);
if ($exists){
$Spu_arr=$RedisCacheService->SRANDMEMBER('CloudMerchanSpu'.$where['mer_id'], 10);
$where['product_id'] =$Spu_arr;
}
$query = $this->dao->search($where);
$count = $query->count();
$count = 0;
// $Sql=$query->page($page, $limit)->setOption('field', [])->field($this->productFiled)->fetchSql(true);
$query->with([
'merchant' => function ($query) {
@ -171,7 +177,7 @@ class SpuRepository extends BaseRepository
},
'issetCoupon',
]);
$list = $query->page($page, $limit)->setOption('field', [])->field($this->productFiled)->orderRaw('rand()')->select();
$list = $query->setOption('field', [])->field($this->productFiled)->select();
$append = ['stop_time','svip_price','show_svip_info','is_svip_price'];
$list->append($append);

View File

@ -37,9 +37,9 @@ class FinancialRecord extends BaseController
$merId = $this->request->merId();
if ($merId) {
$where['mer_id'] = $merId;
$where['financial_type'] = ['order', 'mer_accoubts', 'brokerage_one', 'brokerage_two', 'refund_brokerage_one', 'refund_brokerage_two', 'refund_order','order_platform_coupon','order_svip_coupon'];
$where['financial_type'] = ['order', 'mer_accoubts', 'brokerage_one', 'brokerage_two', 'refund_brokerage_one', 'refund_brokerage_two', 'refund_order','order_platform_coupon','order_svip_coupon' ,'auto_margin'];
} else {
$where['financial_type'] = ['order', 'sys_accoubts', 'brokerage_one', 'brokerage_two', 'refund_brokerage_one', 'refund_brokerage_two', 'refund_order','order_platform_coupon','order_svip_coupon'];
$where['financial_type'] = ['order', 'sys_accoubts', 'brokerage_one', 'brokerage_two', 'refund_brokerage_one', 'refund_brokerage_two', 'refund_order','order_platform_coupon','order_svip_coupon', 'auto_margin'];
}
return app('json')->success($this->repository->getList($where, $page, $limit));
}

View File

@ -1,6 +1,6 @@
<?php
namespace app\controller\api\store\product;
use think\exception\ValidateException;
use app\common\repositories\store\product\ProductRepository;
use think\facade\Db;
use crmeb\basic\BaseController;
@ -28,6 +28,7 @@ class StoreMicro extends BaseController
return app('json')->success($store_product);
}
//商品详情
public function ProductDetails($id){
$find=Db::name('store_product')->where('product_id',$id)
->withAttr('attr_value',function ($value,$data){
@ -35,8 +36,47 @@ class StoreMicro extends BaseController
})
->find();
return app('json')->success(['list'=>$find]);
}
//提交导入商品id
public function ProductImport(){
$product_id = $this->request->param('id', 0);
$user = $this->request->userInfo();
$mer_id =Db::name('store_service')->where('uid',$user['uid'])->where('status',1)->value('mer_id');
if ($mer_id==0) return app('json')->fail('商户id不能为空');
$find=Db::name('store_product')->where('product_id',$product_id)->find();
if($find){
if($find['product_type']!=0){
return app('json')->fail('该商品不是普通商品');
}
$find['attrValue']=Db::name('store_product_attr_value')->where('product_id',$find['product_id'])->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume')->select();
$find['content']=Db::name('store_product_content')->where('product_id',$find['product_id'])->value('content');
$find['is_show']=0;
$find['mer_status']=1;
$find['mer_id']=$mer_id;
$find['temp_id']="";
$find['give_coupon_ids']=[];
$find['params']=[];
$find['extend']=[];
$find['param_temp_id']=[];
$find['mer_labels']=[];
$find['attr']=[];
$find['delivery_way']=[ 0 => "2"];
$find["guarantee_template_id"] = "";
$find['product_type']=0;
$find['mer_cate_id']=[0 => 0];
$find['is_used']=1;
$find['status']=1;
$find['mer_status']=1;
unset($find['product_id'],$find['create_time']);
}
$make = app()->make(ProductRepository::class);
$a=$make->create($find,0);
if($a){
return app('json')->success(['data'=>$a,'msg'=>'导入成功']);
}else{
return app('json')->fail('导入失败');
}
}
public function eadtProduct(){

View File

@ -102,7 +102,7 @@ class StoreSpu extends BaseController
]);
if ($where['action']) unset($where['product_type']);
$category_id=Db::name('merchant')->where('mer_id',$id)->value('category_id');
$mer_id=Db::name('merchant')->where('category_id',$category_id)->where('type_id',11)->value('mer_id');
$mer_id=Db::name('merchant')->where('mer_state',1)->where('status',1)->where('category_id',$category_id)->where('type_id',11)->value('mer_id');
if (!$mer_id){
return app('json')->success(['count'=>0,'list'=>[]]);

View File

@ -63,7 +63,7 @@ return [
'pay_success_presell' => [\crmeb\listens\pay\PresellPaySuccessListen::class],
'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::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],
],

View File

@ -3,6 +3,7 @@ declare (strict_types=1);
namespace app\listener;
use crmeb\services\RedisCacheService;
use think\facade\Db;
use think\facade\Log;
@ -11,14 +12,16 @@ class ProductCreate
public function handle($event)
{
$merchant=Db::name('merchant')->where('mer_id',$event['product']['mer_id'])->find();
$merchant=Db::name('merchant')->where('status',1)->where('mer_state',1)->where('mer_id',$event['product']['mer_id'])->find();
if ($merchant['type_id']==11){
$this->CloudMerchanSpu($merchant,$event);
}
if ($merchant['type_id']==13 ||$merchant['type_id']==11){
return false;
}
$product_find=Db::name('store_product')->where('product_id',$event['product']['product_id'])->where('mer_id',$event['product']['mer_id'])->find();
//市级云仓
$cityMerchantId = Db::name('merchant')->where('category_id',$merchant['category_id'])->where('type_id',13)->value('mer_id');
$cityMerchantId = Db::name('merchant')->where('status',1)->where('mer_state',1)->where('category_id',$merchant['category_id'])->where('type_id',13)->value('mer_id');
if ($cityMerchantId) {
$is_product=0;
if ($product_find['bar_code']!='' &&in_array($product_find['product_type'],[0,98]) &&$product_find['spec_type']==0){
@ -38,26 +41,40 @@ class ProductCreate
}
//镇街云仓
$is_product=0;
if ($merchant['type_id']==11){
$townMerchantId = Db::name('merchant')->where('category_id',$merchant['category_id'])->where('type_id',11)->value('mer_id');
if ($product_find['bar_code']!='' &&in_array($product_find['product_type'],[0,98]) &&$product_find['spec_type']==0){
$find=Db::name('store_product')->where('bar_code',$product_find['bar_code'])->where('mer_id',$townMerchantId)->find();
if (!$find){
$is_product=1;
if ($merchant['type_id']==10){
$townMerchantId = Db::name('merchant')->where('status',1)->where('mer_state',1)->where('category_id',$merchant['category_id'])->where('type_id',11)->value('mer_id');
if ($townMerchantId){
if ($product_find['bar_code']!='' &&in_array($product_find['product_type'],[0,98]) &&$product_find['spec_type']==0){
$find=Db::name('store_product')->where('bar_code',$product_find['bar_code'])->where('mer_id',$townMerchantId)->find();
if (!$find){
$is_product=1;
}
}else{
$find=Db::name('store_product')->where('store_name',$product_find['store_name'])->where('mer_id',$townMerchantId)->find();
if (!$find){
$is_product=1;
}
}
}else{
$find=Db::name('store_product')->where('store_name',$product_find['store_name'])->where('mer_id',$townMerchantId)->find();
if (!$find){
$is_product=1;
if ($is_product==1){
$this->AddProduct($townMerchantId,$product_find,$event);
}
}
if ($is_product==1){
$this->AddProduct($townMerchantId,$product_find,$event);
}
}
return false;
}
public function CloudMerchanSpu($data,$event){
$RedisCacheService = app()->make(RedisCacheService::class);
$exists=$RedisCacheService->exists('CloudMerchanSpu'.$data['mer_id']);
if ($exists){
$RedisCacheService->SADD ('CloudMerchanSpu'.$data['mer_id'], $event['product']['product_id']);
}else{
$Spu_arr=Db::name('store_spu')->where('mer_id',$data['mer_id'])->where('status',1)->column('product_id');
foreach ($Spu_arr as $k=>$v){
$RedisCacheService->SADD ('CloudMerchanSpu'.$data['mer_id'], $v);
}
}
}
public function AddProduct($mer_id,$product_find,$event){
$datas=[
'mer_id'=>$mer_id,

View File

@ -28,6 +28,7 @@ Route::group('api/', function () {
Route::get('seach_bar_code', '/seach_bar_code');
Route::get('product_details', '/ProductDetails');
Route::post('eadt_product', '/eadtProduct');
Route::post('product_import', '/ProductImport');
})->prefix('api.store.product.StoreMicro');
Route::group('v2', function () {