增加:共创股东移动端相关接口
This commit is contained in:
parent
b55097f1b8
commit
c8a9c76b22
|
|
@ -0,0 +1,62 @@
|
||||||
|
<?php
|
||||||
|
namespace app\common\dao\system\merchant;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\dao\BaseDao;
|
||||||
|
use app\common\model\system\merchant\MerchantShareholder;
|
||||||
|
use app\common\repositories\user\UserRepository;
|
||||||
|
|
||||||
|
class MerchantShareholderDao extends BaseDao{
|
||||||
|
|
||||||
|
protected function getModel(): string{
|
||||||
|
return MerchantShareholder::class;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 公共查询模型
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/06/13 11:31
|
||||||
|
* @param array $params
|
||||||
|
* @return MerchantShareholder
|
||||||
|
*/
|
||||||
|
public function searchModel(array $params){
|
||||||
|
return (new MerchantShareholder())
|
||||||
|
->when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){
|
||||||
|
$query->where('id', (int)$params['id']);
|
||||||
|
})
|
||||||
|
->when(isset($params['uid']) && $params['uid'] !== '',function($query) use ($params){
|
||||||
|
$query->where('uid', (int)$params['uid']);
|
||||||
|
})
|
||||||
|
->when(isset($params['mer_id']) && $params['mer_id'] !== '',function($query) use ($params){
|
||||||
|
$query->where('mer_id', (int)$params['mer_id']);
|
||||||
|
})
|
||||||
|
->when(isset($params['level_id']) && $params['level_id'] !== '',function($query) use ($params){
|
||||||
|
$query->where('level_id', (int)$params['level_id']);
|
||||||
|
})
|
||||||
|
->when(isset($params['status']) && $params['status'] !== '',function($query) use ($params){
|
||||||
|
$query->where('status', (int)$params['status']);
|
||||||
|
})
|
||||||
|
->when(isset($params['search_text']) && $params['search_text'] !== '',function($query) use ($params){
|
||||||
|
$uids = app()
|
||||||
|
->make(UserRepository::class)
|
||||||
|
->getSearch([])
|
||||||
|
->where('uid|nickname|phone','like',"%{$params['search_text']}%")
|
||||||
|
->column('uid');
|
||||||
|
$query->whereIn('uid', $uids);
|
||||||
|
})
|
||||||
|
->with([
|
||||||
|
'user' => function($query){
|
||||||
|
$query->field('uid,nickname,avatar,phone');
|
||||||
|
}
|
||||||
|
])
|
||||||
|
->order('create_time DESC,id DESC');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
namespace app\common\model\system\merchant;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\BaseModel;
|
||||||
|
use app\common\model\user\User;
|
||||||
|
|
||||||
|
class MerchantShareholder extends BaseModel{
|
||||||
|
|
||||||
|
public static function tablePk(): string{
|
||||||
|
return 'id';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tableName(): string{
|
||||||
|
return 'merchant_shareholder';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function user(){
|
||||||
|
return $this->hasOne(User::class, 'uid', 'uid');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,8 @@ namespace app\common\model\system\merchant;
|
||||||
|
|
||||||
|
|
||||||
use app\common\model\BaseModel;
|
use app\common\model\BaseModel;
|
||||||
|
use app\common\model\store\coupon\StoreCoupon;
|
||||||
|
use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||||
|
|
||||||
class MerchantShareholderLevel extends BaseModel{
|
class MerchantShareholderLevel extends BaseModel{
|
||||||
|
|
||||||
|
|
@ -16,6 +17,29 @@ class MerchantShareholderLevel extends BaseModel{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common: 获取器 —— 获取相关优惠券列表
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/06/13 14:07
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function getCouponListAttr(){
|
||||||
|
$couponIds = $this->coupon_ids ?? '';
|
||||||
|
$couponIds = explode( ',', $couponIds);
|
||||||
|
// 获取所有优惠券信息
|
||||||
|
return StoreCoupon::whereIn('coupon_id', $couponIds)
|
||||||
|
->where('status', 1)
|
||||||
|
->where('is_del', 0)
|
||||||
|
->field('coupon_id,title,coupon_price,coupon_time,type')
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,11 +125,11 @@ class RecordRepository extends BaseRepository{
|
||||||
// 判断:是否赠送酒卡额度
|
// 判断:是否赠送酒卡额度
|
||||||
if($activityInfo['quota'] > 0) $this->giveQuota((float)$activityInfo['quota'], (int)1, (int)$recordInfo['uid'], (int)$recordInfo['order_id']);
|
if($activityInfo['quota'] > 0) $this->giveQuota((float)$activityInfo['quota'], (int)1, (int)$recordInfo['uid'], (int)$recordInfo['order_id']);
|
||||||
// 判断:是否赠送菜卡额度
|
// 判断:是否赠送菜卡额度
|
||||||
if($activityInfo['vegetable_quota'] > 0) $this->giveQuota((float)$activityInfo['quota'], (int)2, (int)$recordInfo['uid'], (int)$recordInfo['order_id']);
|
if($activityInfo['vegetable_quota'] > 0) $this->giveQuota((float)$activityInfo['vegetable_quota'], (int)2, (int)$recordInfo['uid'], (int)$recordInfo['order_id']);
|
||||||
// 判断:是否赠送油卡额度
|
// 判断:是否赠送油卡额度
|
||||||
if($activityInfo['oil_quota'] > 0) $this->giveQuota((float)$activityInfo['quota'], (int)3, (int)$recordInfo['uid'], (int)$recordInfo['order_id']);
|
if($activityInfo['oil_quota'] > 0) $this->giveQuota((float)$activityInfo['oil_quota'], (int)3, (int)$recordInfo['uid'], (int)$recordInfo['order_id']);
|
||||||
// 判断:是否赠送封坛酒卡额度
|
// 判断:是否赠送封坛酒卡额度
|
||||||
if($activityInfo['wine_quota'] > 0) $this->giveQuota((float)$activityInfo['quota'], (int)4, (int)$recordInfo['uid'], (int)$recordInfo['order_id']);
|
if($activityInfo['wine_quota'] > 0) $this->giveQuota((float)$activityInfo['wine_quota'], (int)4, (int)$recordInfo['uid'], (int)$recordInfo['order_id']);
|
||||||
// 是否赠送优惠券
|
// 是否赠送优惠券
|
||||||
if(count($activityInfo['coupon_ids']) > 0){
|
if(count($activityInfo['coupon_ids']) > 0){
|
||||||
$uid = $recordInfo['uid'];
|
$uid = $recordInfo['uid'];
|
||||||
|
|
|
||||||
|
|
@ -3133,7 +3133,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
||||||
// 整理订单数据
|
// 整理订单数据
|
||||||
$orderList[] = [
|
$orderList[] = [
|
||||||
'cartInfo' => [],
|
'cartInfo' => [],
|
||||||
'activity_type' => $activityType,// 30=在线买单;32=代理入驻;33=参加活动支付;34=邀请码支付
|
'activity_type' => $activityType,// 30=在线买单;32=代理入驻;33=参加活动支付;34=邀请码支付;37=共创股东订单
|
||||||
'commission_rate' => 0,
|
'commission_rate' => 0,
|
||||||
'order_type' => 0,
|
'order_type' => 0,
|
||||||
'is_virtual' => 1,
|
'is_virtual' => 1,
|
||||||
|
|
|
||||||
|
|
@ -178,8 +178,12 @@ class StoreOrderRepository extends BaseRepository
|
||||||
$data['mark'] = '余额支付' . floatval($groupOrder['pay_price']) . '元';
|
$data['mark'] = '余额支付' . floatval($groupOrder['pay_price']) . '元';
|
||||||
}else if($groupOrder['activity_type'] == 35){
|
}else if($groupOrder['activity_type'] == 35){
|
||||||
$merName = Merchant::where('mer_id',$groupOrder->with_goods_mer_id)->value('mer_name');
|
$merName = Merchant::where('mer_id',$groupOrder->with_goods_mer_id)->value('mer_name');
|
||||||
$data['title'] = '酒道馆['.$merName.']进货';
|
$data['title'] = '['.$merName.']进货';
|
||||||
$data['mark'] = $user->nickname.'使用商户余额支付' . floatval($groupOrder['pay_price']) . '元';
|
$data['mark'] = $user->nickname.'使用商户余额支付' . floatval($groupOrder['pay_price']) . '元';
|
||||||
|
}else if($groupOrder['activity_type'] == 37){
|
||||||
|
$merName = Merchant::where('mer_id',$groupOrder->with_goods_mer_id)->value('mer_name');
|
||||||
|
$data['title'] = '['.$merName.']共创股东加入';
|
||||||
|
$data['mark'] = $user->nickname.'使用余额支付' . floatval($groupOrder['pay_price']) . '元';
|
||||||
}
|
}
|
||||||
|
|
||||||
$userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', $data);
|
$userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', $data);
|
||||||
|
|
@ -247,6 +251,8 @@ class StoreOrderRepository extends BaseRepository
|
||||||
$svipDiscount = 0;
|
$svipDiscount = 0;
|
||||||
$isPoints = false;
|
$isPoints = false;
|
||||||
foreach ($groupOrder->orderList as $_k => $order) {
|
foreach ($groupOrder->orderList as $_k => $order) {
|
||||||
|
$_payPrice = 0;
|
||||||
|
|
||||||
$order->paid = 1;
|
$order->paid = 1;
|
||||||
$order->pay_time = $time;
|
$order->pay_time = $time;
|
||||||
$svipDiscount = bcadd($order->svip_discount, $svipDiscount, 2);
|
$svipDiscount = bcadd($order->svip_discount, $svipDiscount, 2);
|
||||||
|
|
@ -282,7 +288,7 @@ class StoreOrderRepository extends BaseRepository
|
||||||
app()->make(ProductAssistSetRepository::class)->changStatus($order->orderProduct[0]['activity_id']);
|
app()->make(ProductAssistSetRepository::class)->changStatus($order->orderProduct[0]['activity_id']);
|
||||||
}
|
}
|
||||||
if ($order->order_type == 1 && $order->status != 10) $order->verify_code = $this->verifyCode();
|
if ($order->order_type == 1 && $order->status != 10) $order->verify_code = $this->verifyCode();
|
||||||
if (!in_array($order->activity_type,[30,31,32,33,34]) && $order->orderProduct[0]->product->type == 2) {
|
if (!in_array($order->activity_type,[30,31,32,33,34,37]) && $order->orderProduct[0]->product->type == 2) {
|
||||||
$order->status = 3;//2; todo 订单进入待评价改为已完成
|
$order->status = 3;//2; todo 订单进入待评价改为已完成
|
||||||
$order->delivery_type = 6;
|
$order->delivery_type = 6;
|
||||||
$order->delivery_name = '自动发货';
|
$order->delivery_name = '自动发货';
|
||||||
|
|
@ -290,7 +296,7 @@ class StoreOrderRepository extends BaseRepository
|
||||||
$isPoints = true;
|
$isPoints = true;
|
||||||
}
|
}
|
||||||
// 判断:是否为在线买单、酒道馆补差价 在线买单,订单支付则订单完成
|
// 判断:是否为在线买单、酒道馆补差价 在线买单,订单支付则订单完成
|
||||||
if(in_array($order->activity_type,[30,31,32,33,34])){
|
if(in_array($order->activity_type,[30,31,32,33,34,37])){
|
||||||
$order->status = 3;
|
$order->status = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -525,7 +531,7 @@ class StoreOrderRepository extends BaseRepository
|
||||||
'financial_type' => $order['activity_type'] ==20 ? 'points_order_true' : 'order_true',
|
'financial_type' => $order['activity_type'] ==20 ? 'points_order_true' : 'order_true',
|
||||||
'financial_pm' => 0,
|
'financial_pm' => 0,
|
||||||
'type' => 2,
|
'type' => 2,
|
||||||
'number' => $_payPrice,
|
'number' => $_payPrice ?? 0,
|
||||||
'mer_id' => $order->mer_id,
|
'mer_id' => $order->mer_id,
|
||||||
'financial_record_sn' => $financeSn . ($i++),
|
'financial_record_sn' => $financeSn . ($i++),
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
|
|
@ -544,10 +550,10 @@ class StoreOrderRepository extends BaseRepository
|
||||||
'financial_record_sn' => $financeSn . ($i++),
|
'financial_record_sn' => $financeSn . ($i++),
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
];
|
];
|
||||||
$_payPrice = bcadd($_payPrice, $order->platform_coupon_price, 2);
|
$_payPrice = bcadd($_payPrice ?? 0, $order->platform_coupon_price, 2);
|
||||||
}
|
}
|
||||||
if (!$is_combine) {
|
if (!$is_combine) {
|
||||||
app()->make(MerchantRepository::class)->addLockMoney($order->mer_id, 'order', $order->order_id, $_payPrice);
|
app()->make(MerchantRepository::class)->addLockMoney($order->mer_id, 'order', $order->order_id, $_payPrice ?? 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($is_combine) {
|
if ($is_combine) {
|
||||||
|
|
@ -557,7 +563,7 @@ class StoreOrderRepository extends BaseRepository
|
||||||
'transaction_id' => $order->transaction_id ?? '',
|
'transaction_id' => $order->transaction_id ?? '',
|
||||||
'mer_id' => $order->mer_id,
|
'mer_id' => $order->mer_id,
|
||||||
'profitsharing_price' => $order->pay_price,
|
'profitsharing_price' => $order->pay_price,
|
||||||
'profitsharing_mer_price' => $_payPrice,
|
'profitsharing_mer_price' => $_payPrice ?? 0,
|
||||||
'type' => $storeOrderProfitsharingRepository::PROFITSHARING_TYPE_ORDER,
|
'type' => $storeOrderProfitsharingRepository::PROFITSHARING_TYPE_ORDER,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
@ -658,7 +664,7 @@ class StoreOrderRepository extends BaseRepository
|
||||||
Log::info('自动打印小票报错:' . $exception);
|
Log::info('自动打印小票报错:' . $exception);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log::info('自动打印小票验证:商户ID【' . $merId . '】,自动打印状态未开启');
|
// Log::info('自动打印小票验证:商户ID【' . $merId . '】,自动打印状态未开启');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,269 @@
|
||||||
|
<?php
|
||||||
|
namespace app\common\repositories\system\merchant;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\dao\system\merchant\MerchantShareholderDao;
|
||||||
|
use app\common\model\marketing\activity\Activity;
|
||||||
|
use app\common\model\system\merchant\MerchantShareholder;
|
||||||
|
use app\common\model\user\ExchangeQuotaRecord;
|
||||||
|
use app\common\repositories\BaseRepository;
|
||||||
|
use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||||
|
use app\common\repositories\store\coupon\StoreCouponUserRepository;
|
||||||
|
use app\common\repositories\store\order\StoreGroupOrderRepository;
|
||||||
|
use app\common\repositories\store\order\StoreOrderCreateRepository;
|
||||||
|
use app\common\repositories\store\order\StoreOrderRepository;
|
||||||
|
use app\common\repositories\user\ExchangeQuotaRepository;
|
||||||
|
use crmeb\services\LockService;
|
||||||
|
use think\exception\ValidateException;
|
||||||
|
use think\facade\Db;
|
||||||
|
use think\facade\Log;
|
||||||
|
|
||||||
|
class MerchantShareholderRepository extends BaseRepository{
|
||||||
|
|
||||||
|
public function __construct(MerchantShareholderDao $dao){
|
||||||
|
$this->dao = $dao;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common: 公共查询模型
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/06/13 11:30
|
||||||
|
* @param $search
|
||||||
|
* @return \app\common\model\system\merchant\MerchantShareholder
|
||||||
|
*/
|
||||||
|
public function getSearchModel($search){
|
||||||
|
return $this->dao->searchModel($search);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common: 列表信息获取
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/06/14 16:00
|
||||||
|
* @param array $params
|
||||||
|
* @param int $page
|
||||||
|
* @param int $limit
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function getList(array $params,int $page,int $limit):array{
|
||||||
|
$query = $this->getSearchModel($params);
|
||||||
|
$count = $query->count();
|
||||||
|
$list = $query->page($page,$limit)->select();
|
||||||
|
|
||||||
|
return compact('count','list');
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 处理加入信息(同步生成订单)
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/06/14 15:17
|
||||||
|
* @param $params
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handleJoinInfo($params){
|
||||||
|
return Db::transaction(function() use ($params){
|
||||||
|
// 等级信息
|
||||||
|
$levelInfo = app()->make(MerchantShareholderLevelRepository::class)->getSearchModel(['id' => $params['level_id']])->findOrEmpty()->toArray();
|
||||||
|
$payMoney = $levelInfo['price'] ?? 0;
|
||||||
|
// 是否已经存在加入信息
|
||||||
|
$joinInfo = $this->getSearchModel([
|
||||||
|
'mer_id' => $params['mer_id'],
|
||||||
|
'level_id' => $params['level_id'],
|
||||||
|
'uid' => $params['uid'],
|
||||||
|
])->findOrEmpty()->toArray();
|
||||||
|
// 支付信息
|
||||||
|
$payInfo = array_intersect_key($params,array_flip((array)["pay_type","return_url"]));
|
||||||
|
$payInfo['money'] = (float)$payMoney;
|
||||||
|
$payResult = [];// 支付信息
|
||||||
|
$userInfo = $params['user_info'] ?? [];
|
||||||
|
// 判断: 信息是否已经存在
|
||||||
|
if($joinInfo){
|
||||||
|
// 信息已经存在
|
||||||
|
if((float)$payMoney > 0 && $joinInfo['status'] == 0){
|
||||||
|
// 需要支付 且未支付
|
||||||
|
$group_order_id = app()->make(StoreOrderRepository::class)->getSearch(['order_id'=>$joinInfo['order_id']])->value('group_order_id');
|
||||||
|
$groupOrder = app()->make(StoreGroupOrderRepository::class)->getSearch(['group_order_id'=>$group_order_id])->findOrEmpty();
|
||||||
|
$payResult = app()
|
||||||
|
->make(StoreOrderRepository::class)
|
||||||
|
->pay($payInfo['pay_type'],$userInfo,$groupOrder,$payInfo['return_url'],$params['is_app']);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// 无需支付
|
||||||
|
$this->joinSuccess($joinInfo['id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// 基本信息增加
|
||||||
|
$merchantShareholderId = $this->createJoinInfo($params);
|
||||||
|
// 判断:是否需要支付 需要支付生成订单并且获取支付信息
|
||||||
|
if((float)$payMoney > 0){
|
||||||
|
// 需要支付 发起支付
|
||||||
|
$groupOrder = app()
|
||||||
|
->make(LockService::class)
|
||||||
|
->exec('online_order.create',function() use ($payInfo,$userInfo){
|
||||||
|
$payType = array_search($payInfo['pay_type'],StoreOrderRepository::PAY_TYPE);
|
||||||
|
return app()
|
||||||
|
->make(StoreOrderCreateRepository::class)
|
||||||
|
->onlinePayment($payType,$payInfo,$userInfo, 37);
|
||||||
|
});
|
||||||
|
// 子订单只存在一个 直接查询即可
|
||||||
|
$orderId = app()->make(StoreOrderRepository::class)
|
||||||
|
->getSearch([])
|
||||||
|
->where('group_order_id',$groupOrder->group_order_id)
|
||||||
|
->value('order_id');
|
||||||
|
MerchantShareholder::update(['order_id'=>$orderId],['id'=>$merchantShareholderId]);
|
||||||
|
// 获取支付信息
|
||||||
|
$payResult = app()
|
||||||
|
->make(StoreOrderRepository::class)
|
||||||
|
->pay($payInfo['pay_type'],$userInfo,$groupOrder,$payInfo['return_url'],$params['is_app']);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// 无需支付
|
||||||
|
$this->joinSuccess($merchantShareholderId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $payResult;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 增加加入信息
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/06/14 13:55
|
||||||
|
* @param $params
|
||||||
|
* @return int|string
|
||||||
|
*/
|
||||||
|
public function createJoinInfo($params){
|
||||||
|
// 判断:是否已经存在
|
||||||
|
$hasId = (int)$this->getSearchModel([
|
||||||
|
'mer_id' => $params['mer_id'],
|
||||||
|
'uid' => $params['uid'],
|
||||||
|
])->value('id');
|
||||||
|
if($hasId > 0) throw new ValidateException('股东信息已经存在,请勿重复加入!');
|
||||||
|
// 判断:当前等级是否存在邀请名额限制 存在则判断是否到达限制
|
||||||
|
$levelQuotaLimit = (int)app()->make(MerchantShareholderLevelRepository::class)->getSearch(['id'=>$params['level_id']])->value('mer_quota');
|
||||||
|
if($levelQuotaLimit > 0){
|
||||||
|
$quotaUsed = (int)$this->getSearchModel(['mer_id' => $params['mer_id'],'level_id' => $params['level_id']])->count();
|
||||||
|
// 等级名额限制 小于等于 已邀请名额;禁止加入
|
||||||
|
if($levelQuotaLimit <= $quotaUsed) throw new ValidateException('本商户共创股东人数已达到上限,加入失败!');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 不存在 增加
|
||||||
|
return MerchantShareholder::insertGetId([
|
||||||
|
'uid' => $params['uid'],
|
||||||
|
'mer_id' => $params['mer_id'],
|
||||||
|
'level_id' => $params['level_id'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 加入成功后处理
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/06/14 15:17
|
||||||
|
* @param $id
|
||||||
|
*/
|
||||||
|
public function joinSuccess($id){
|
||||||
|
Db::startTrans();
|
||||||
|
try{
|
||||||
|
// 获取记录id
|
||||||
|
$info = $this->getSearchModel(['id'=>$id])->findOrEmpty()->toArray();
|
||||||
|
// 等级信息
|
||||||
|
$levelInfo = app()->make(MerchantShareholderLevelRepository::class)->getSearch(['id'=>$info['level_id']])->findOrEmpty()->toArray();
|
||||||
|
// 获取活动信息
|
||||||
|
$couponIds = $levelInfo['coupon_ids'] ? explode(',', $levelInfo['coupon_ids']) : [];
|
||||||
|
// 判断:是否赠送酒卡额度
|
||||||
|
if($levelInfo['quota'] > 0) $this->giveQuota((float)$levelInfo['quota'], (int)1, (int)$info['uid'], (int)$info['order_id']);
|
||||||
|
// 判断:是否赠送菜卡额度
|
||||||
|
if($levelInfo['vegetable_quota'] > 0) $this->giveQuota((float)$levelInfo['vegetable_quota'], (int)2, (int)$info['uid'], (int)$info['order_id']);
|
||||||
|
// 判断:是否赠送油卡额度
|
||||||
|
if($levelInfo['oil_quota'] > 0) $this->giveQuota((float)$levelInfo['oil_quota'], (int)3, (int)$info['uid'], (int)$info['order_id']);
|
||||||
|
// 判断:是否赠送封坛酒卡额度
|
||||||
|
if($levelInfo['wine_quota'] > 0) $this->giveQuota((float)$levelInfo['wine_quota'], (int)4, (int)$info['uid'], (int)$info['order_id']);
|
||||||
|
// 是否赠送优惠券
|
||||||
|
if(count($couponIds) > 0){
|
||||||
|
$uid = $info['uid'];
|
||||||
|
foreach($couponIds as $coupon_id){
|
||||||
|
$coupon = app()->make(StoreCouponRepository::class)->validSvipCouponTwo($coupon_id,$uid);
|
||||||
|
if (!$coupon) continue;//throw new ValidateException('优惠券失效');
|
||||||
|
// 获取商户id 和关联的品牌ID
|
||||||
|
$bindShop = [];
|
||||||
|
if((int)$info['mer_id'] > 0){
|
||||||
|
$bindShop = app()->make(MerchantRepository::class)->getSearch([])
|
||||||
|
->where('mer_id', $info['mer_id'])
|
||||||
|
->where('is_del', 0)
|
||||||
|
->findOrEmpty()
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
$params = [
|
||||||
|
'shop_mer_id' => $bindShop['mer_id'] ?? 0,
|
||||||
|
'brand_id' => $bindShop['brand_id'] ?? 0,
|
||||||
|
'user_order_id' => $info['order_id'] ?? 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
app()->make(StoreCouponRepository::class)->sendCoupon($coupon, $uid,StoreCouponUserRepository::SEND_TYPE_BUY, $params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 修改信息
|
||||||
|
MerchantShareholder::update([
|
||||||
|
'price' => $levelInfo['price'],
|
||||||
|
'quota' => $levelInfo['quota'],
|
||||||
|
'vegetable_quota' => $levelInfo['vegetable_quota'],
|
||||||
|
'oil_quota' => $levelInfo['oil_quota'],
|
||||||
|
'wine_quota' => $levelInfo['wine_quota'],
|
||||||
|
'coupon_ids' => $levelInfo['coupon_ids'],
|
||||||
|
'status' => 1,
|
||||||
|
],['id' => $id]);
|
||||||
|
|
||||||
|
|
||||||
|
Db::commit();
|
||||||
|
}catch(\Exception $e){
|
||||||
|
Db::rollback();
|
||||||
|
Log::info('支付成功处理加入成功后的信息 - 错误: '.var_export([
|
||||||
|
'id' => $id,
|
||||||
|
'msg' => $e->getMessage()
|
||||||
|
],1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 各种额度变更(赠送变更)
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/06/14 15:07
|
||||||
|
* @param float $num 变更数量
|
||||||
|
* @param int $quotaType 1=酒卡额度,2=菜卡额度,3=封坛酒额度,4=加油卡额度
|
||||||
|
* @param int $uid 用户id
|
||||||
|
* @param int $orderId 订单id
|
||||||
|
*/
|
||||||
|
public function giveQuota(float $num,int $quotaType,int $uid,int $orderId){
|
||||||
|
$holdInfo = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$uid,'quota_type'=>$quotaType])->findOrEmpty();
|
||||||
|
if((int)$holdInfo->uid <= 0) {
|
||||||
|
$holdInfo->uid = $uid;
|
||||||
|
$holdInfo->quota_type = $quotaType;
|
||||||
|
}
|
||||||
|
// 赠送
|
||||||
|
$changeFront = (float)$holdInfo->surplus_quota;
|
||||||
|
$holdInfo->total_quota += (float)$num;// 总额度
|
||||||
|
$holdInfo->surplus_quota += (float)$num;// 剩余额度
|
||||||
|
$holdInfo->save();
|
||||||
|
// 记录
|
||||||
|
ExchangeQuotaRecord::insert([
|
||||||
|
'uid' => $uid,
|
||||||
|
'product_id' => 0,
|
||||||
|
'order_id' => $orderId,
|
||||||
|
'order_product_id' => 0,
|
||||||
|
'change_type' => 1,
|
||||||
|
'change_quantity' => (float)$num,
|
||||||
|
'change_front' => $changeFront,
|
||||||
|
'change_after' => (float)$holdInfo->surplus_quota,
|
||||||
|
'remark' => "参加活动赠送",
|
||||||
|
'source' => 5,
|
||||||
|
'quota_type' => $quotaType,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,152 @@
|
||||||
|
<?php
|
||||||
|
namespace app\controller\api\store\merchant;
|
||||||
|
|
||||||
|
use app\common\repositories\system\merchant\MerchantRepository;
|
||||||
|
use app\common\repositories\system\merchant\MerchantShareholderLevelRepository;
|
||||||
|
use app\common\repositories\system\merchant\MerchantShareholderRepository;
|
||||||
|
use think\App;
|
||||||
|
use crmeb\basic\BaseController;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Shareholder extends BaseController{
|
||||||
|
protected $shareholderRepository;
|
||||||
|
protected $shareholderLevelRepository;
|
||||||
|
protected $userInfo;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct(App $app,MerchantShareholderRepository $shareholderRepository,MerchantShareholderLevelRepository $shareholderLevelRepository){
|
||||||
|
parent::__construct($app);
|
||||||
|
$this->shareholderRepository = $shareholderRepository;
|
||||||
|
$this->shareholderLevelRepository = $shareholderLevelRepository;
|
||||||
|
$this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : NULL;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 获取商户基本信息
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/06/13 15:12
|
||||||
|
* @param $merId
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function merInfo($merId){
|
||||||
|
// 商户信息
|
||||||
|
$info = app()->make(MerchantRepository::class)
|
||||||
|
->getSearch(['mer_id'=>$merId])
|
||||||
|
->field('mer_id,mer_name,mer_avatar,merchant_type')
|
||||||
|
->findOrEmpty()
|
||||||
|
->toArray();
|
||||||
|
// 总共创股东
|
||||||
|
$info['total_shareholder'] = $this->shareholderRepository->getSearchModel([
|
||||||
|
'mer_id' => $info['mer_id']
|
||||||
|
])->count();
|
||||||
|
|
||||||
|
return app('json')->success($info);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 获取等级列表(全部)
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/06/13 13:47
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function levelList(){
|
||||||
|
// 参数获取
|
||||||
|
$merId = (int)$this->request->param('mer_id', 0);
|
||||||
|
$merchantType = $this->request->param('merchant_type');
|
||||||
|
// 等级列表
|
||||||
|
$list = $this->shareholderLevelRepository->getSearchModel([
|
||||||
|
'merchant_type' => $merchantType
|
||||||
|
])->append(['coupon_list'])->select()->toArray();
|
||||||
|
// 循环处理
|
||||||
|
if($merId > 0){
|
||||||
|
foreach($list as &$item){
|
||||||
|
// 获取本商户已邀请名额
|
||||||
|
$item['quota_used'] = $this->shareholderRepository->getSearchModel(['mer_id'=>$merId,'level_id'=>$item['id']])->count();
|
||||||
|
// 获取本商户剩余可用名额
|
||||||
|
$item['quota_surplus'] = (int)sprintf("%.2f",$item['mer_quota'] - $item['quota_used']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return app('json')->success($list);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 获取等级信息
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/06/14 11:11
|
||||||
|
* @param $id
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function levelInfo($id){
|
||||||
|
// 等级信息获取
|
||||||
|
$info = $this->shareholderLevelRepository->getSearchModel([
|
||||||
|
'id' => $id
|
||||||
|
])
|
||||||
|
->append(['coupon_list'])
|
||||||
|
->findOrEmpty()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
return app('json')->success($info);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 申请加入成为共创股东
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/06/14 15:22
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function applyJoin(){
|
||||||
|
// 参数获取
|
||||||
|
$params = $this->request->params([
|
||||||
|
['mer_id', 0],
|
||||||
|
['level_id', 0],
|
||||||
|
// 支付相关
|
||||||
|
'pay_type',
|
||||||
|
'return_url'
|
||||||
|
]);
|
||||||
|
$params['uid'] = $this->request->uid();
|
||||||
|
$params['user_info'] = $this->request->userInfo();
|
||||||
|
$params['is_app'] = $this->request->isApp();
|
||||||
|
$res = $this->shareholderRepository->handleJoinInfo($params);
|
||||||
|
|
||||||
|
if($res) return $res;
|
||||||
|
else return app('json')->success("操作成功");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 获取加入信息
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/06/14 15:27
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function applyJoinInfo(){
|
||||||
|
// 参数获取
|
||||||
|
$uid = $this->request->uid();
|
||||||
|
$merId = $this->request->param('mer_id',0);
|
||||||
|
$levelId = $this->request->param('level_id',0);
|
||||||
|
$info = $this->shareholderRepository->getSearchModel([
|
||||||
|
'mer_id' => $merId,
|
||||||
|
'uid' => $uid,
|
||||||
|
])->findOrEmpty()->toArray();
|
||||||
|
|
||||||
|
|
||||||
|
return app('json')->success($info);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 获取股东列表
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/06/14 16:00
|
||||||
|
* @return mixed
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function getList(){
|
||||||
|
// 参数处理
|
||||||
|
[$page, $limit] = $this->getPage();
|
||||||
|
$params = $this->request->params(['level_id','mer_id','uid','search_text']);
|
||||||
|
// 信息列表获取
|
||||||
|
$data = $this->shareholderRepository->getList((array)$params,(int)$page,(int)$limit);
|
||||||
|
|
||||||
|
return app('json')->success($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -12,6 +12,7 @@ use app\common\repositories\marketing\activity\RecordRepository;
|
||||||
use app\common\repositories\marketing\AgentBrokerageRepository;
|
use app\common\repositories\marketing\AgentBrokerageRepository;
|
||||||
use app\common\repositories\system\merchant\MerchantQuotaRecordRepository;
|
use app\common\repositories\system\merchant\MerchantQuotaRecordRepository;
|
||||||
use app\common\repositories\system\merchant\MerchantRepository;
|
use app\common\repositories\system\merchant\MerchantRepository;
|
||||||
|
use app\common\repositories\system\merchant\MerchantShareholderRepository;
|
||||||
use app\common\repositories\user\ExchangePickupPointRepository;
|
use app\common\repositories\user\ExchangePickupPointRepository;
|
||||||
use app\common\repositories\user\ExchangeQuotaRepository;
|
use app\common\repositories\user\ExchangeQuotaRepository;
|
||||||
use app\common\repositories\user\UserInviteCodeRepository;
|
use app\common\repositories\user\UserInviteCodeRepository;
|
||||||
|
|
@ -53,7 +54,15 @@ class OrderPaySuccessEvent{
|
||||||
else if($groupOrder->activity_type == 35){
|
else if($groupOrder->activity_type == 35){
|
||||||
// 进货订单
|
// 进货订单
|
||||||
|
|
||||||
}else{
|
}
|
||||||
|
else if($groupOrder->activity_type == 37){
|
||||||
|
// 共创股东加入
|
||||||
|
foreach($groupOrder->orderList as $orderInfo){
|
||||||
|
$id = app()->make(MerchantShareholderRepository::class)->getSearch(['order_id'=>(int)$orderInfo->order_id])->value('id');
|
||||||
|
if($id > 0) app()->make(MerchantShareholderRepository::class)->joinSuccess($id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
// 其他订单
|
// 其他订单
|
||||||
$this->orderPaySuccessHandle($groupOrder);
|
$this->orderPaySuccessHandle($groupOrder);
|
||||||
// 订单支付成功 触发购买商品升级
|
// 订单支付成功 触发购买商品升级
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,14 @@ class SendSmsJob implements JobInterface
|
||||||
try {
|
try {
|
||||||
app()->make(WechatTemplateMessageService::class)->sendTemplate($data);
|
app()->make(WechatTemplateMessageService::class)->sendTemplate($data);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::info('模板消息发送失败' . var_export($data, 1) . $e->getMessage());
|
// Log::info('模板消息发送失败' . var_export($data, 1) . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($status['notice_routine'] == 1) {
|
if ($status['notice_routine'] == 1) {
|
||||||
try {
|
try {
|
||||||
app()->make(WechatTemplateMessageService::class)->subscribeSendTemplate($data);
|
app()->make(WechatTemplateMessageService::class)->subscribeSendTemplate($data);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::info('订阅消息发送失败' . var_export($data, 1) . $e->getMessage());
|
// Log::info('订阅消息发送失败' . var_export($data, 1) . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$job->delete();
|
$job->delete();
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ class WechatTemplateMessageService
|
||||||
{
|
{
|
||||||
event('wechat.subscribeTemplate.before',compact('data'));
|
event('wechat.subscribeTemplate.before',compact('data'));
|
||||||
$res = $this->subscribeTemplateMessage($data);
|
$res = $this->subscribeTemplateMessage($data);
|
||||||
Log::info('订阅消息发送Data' . var_export($data, 1));
|
// Log::info('订阅消息发送Data' . var_export($data, 1));
|
||||||
if(!$res || !is_array($res))return true;
|
if(!$res || !is_array($res))return true;
|
||||||
|
|
||||||
foreach($res as $item){
|
foreach($res as $item){
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ Route::group('api/', function () {
|
||||||
Route::post('create', '/v2CreateOrder');
|
Route::post('create', '/v2CreateOrder');
|
||||||
})->prefix('api.store.order.StoreOrder');
|
})->prefix('api.store.order.StoreOrder');
|
||||||
});
|
});
|
||||||
|
// 生成小程序码
|
||||||
|
Route::get('create_qr_code', 'api.Common/getQrCode');
|
||||||
//退出登录
|
//退出登录
|
||||||
Route::post('logout', 'api.Auth/logout');
|
Route::post('logout', 'api.Auth/logout');
|
||||||
//用户信息
|
//用户信息
|
||||||
|
|
@ -455,6 +457,18 @@ Route::group('api/', function () {
|
||||||
Route::post('edit', 'editInfo');// 提交编辑
|
Route::post('edit', 'editInfo');// 提交编辑
|
||||||
Route::post('del/:id', 'delInfo');// 删除
|
Route::post('del/:id', 'delInfo');// 删除
|
||||||
})->prefix('api.user.WithdrawalAccount/');
|
})->prefix('api.user.WithdrawalAccount/');
|
||||||
|
// 共创股东相关接口
|
||||||
|
Route::group('mer/shareholder', function () {
|
||||||
|
Route::get('mer_info/:merId', 'merInfo');
|
||||||
|
Route::get('level_list', 'levelList');
|
||||||
|
Route::get('level_info/:id', 'levelInfo');
|
||||||
|
Route::post('apply_join', 'applyJoin');
|
||||||
|
Route::post('apply_join_info', 'applyJoinInfo');
|
||||||
|
Route::post('list', 'getList');
|
||||||
|
|
||||||
|
|
||||||
|
})->prefix('api.store.merchant.Shareholder/');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue