商城更新2.1

This commit is contained in:
mkm 2023-01-16 14:16:38 +08:00
parent 66ac64a05a
commit 3b432de324
622 changed files with 7153 additions and 3249 deletions

4
.gitignore vendored
View File

@ -9,3 +9,7 @@ public/static/download/*
public/phpExcel/*
app/controller/api/Test.php
public/protocol.html
app/controller/Install.php
cert_crmeb.key.rej
cert_crmeb.key
/runtime

View File

@ -33,7 +33,25 @@ class ClearMerchantData extends Command
if (!$flag) return;
$tables = Db::query('SHOW TABLES FROM ' . env('database.database', ''));
$pre = env('database.prefix', '');
$bakTables = [$pre . 'page_link', $pre . 'page_category', $pre . 'diy', $pre . 'city_area', $pre . 'express', $pre . 'system_admin', $pre . 'system_city', $pre . 'system_config', $pre . 'system_config_classify', $pre . 'system_config_value', $pre . 'system_group', $pre . 'system_group_data', $pre . 'system_menu', $pre . 'system_role', $pre . 'template_message', $pre . 'system_notice_config'];
$bakTables = [
$pre . 'page_link',
$pre . 'page_category',
$pre . 'diy',
$pre . 'city_area',
$pre . 'express',
$pre . 'system_admin',
$pre . 'system_city',
$pre . 'system_config',
$pre . 'system_config_classify',
$pre . 'system_config_value',
$pre . 'system_group',
$pre . 'system_group_data',
$pre . 'system_menu',
$pre . 'system_role',
$pre . 'template_message',
$pre . 'system_notice_config',
$pre . 'cache',
];
foreach ($tables as $table) {
$name = array_values($table)[0];
@ -41,7 +59,7 @@ class ClearMerchantData extends Command
Db::table($name)->delete(true);
}
}
Db::table( $pre . 'cache')->whereNotIn('key','copyright_context,copyright_image,copyright_status')->delete(true);
$output->info('删除成功');
}

View File

@ -38,7 +38,7 @@ class resetPassword extends Command
$this->setName('reset:password')
->addArgument('root', Argument::OPTIONAL, 'root : admin')
->addOption('pwd', null, Option::VALUE_REQUIRED, 'pwd : 123456')
->setDescription('the update resetPwd command');
->setDescription('php think admin --pwd 123');
}
/**

View File

@ -15,6 +15,7 @@ namespace app\common\dao\community;
use app\common\dao\BaseDao;
use app\common\model\community\Community;
use app\common\repositories\system\RelevanceRepository;
class CommunityDao extends BaseDao
{
@ -37,9 +38,27 @@ class CommunityDao extends BaseDao
->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use($where) {
$query->whereLike('Community.title',"%{$where['keyword']}%");
})
->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use($where) {
$query->where('Community.uid',$where['uid']);
})
->when(isset($where['uids']) && $where['uids'] !== '', function ($query) use($where) {
$query->whereIn('Community.uid',$where['uids']);
})
->when(isset($where['topic_id']) && $where['topic_id'] !== '', function ($query) use($where) {
$query->where('Community.topic_id',$where['topic_id']);
})
->when(isset($where['community_id']) && $where['community_id'] !== '', function ($query) use($where) {
$query->where('Community.community_id',$where['community_id']);
})
->when(isset($where['not_id']) && $where['not_id'] !== '', function ($query) use($where) {
$query->whereNotIn('Community.community_id',$where['not_id']);
})
->when(isset($where['community_ids']) && $where['community_ids'] !== '', function ($query) use($where) {
$query->whereIn('Community.community_id',$where['community_ids']);
})
->when(isset($where['is_type']) && $where['is_type'] !== '', function ($query) use($where) {
$query->whereIn('Community.is_type',$where['is_type']);
})
->when(isset($where['is_show']) && $where['is_show'] !== '', function ($query) use($where) {
$query->where('Community.is_show',$where['is_show']);
})
@ -80,4 +99,23 @@ class CommunityDao extends BaseDao
{
return $this->getModel()::getDb()->where('uid' ,$uid)->update(['is_del' => 1]);
}
public function joinUser($where)
{
return Community::hasWhere('relevanceRight',function($query) use($where){
$query->where('type',RelevanceRepository::TYPE_COMMUNITY_START)->where('left_id',$where['uid']);
})
->when(isset($where['is_type']) && $where['is_type'] !== '', function ($query) use($where) {
$query->whereIn('Community.is_type',$where['is_type']);
})
->when(isset($where['is_show']) && $where['is_show'] !== '', function ($query) use($where) {
$query->where('Community.is_show',$where['is_show']);
})
->when(isset($where['status']) && $where['status'] !== '', function ($query) use($where) {
$query->where('Community.status',$where['status']);
})
->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use($where) {
$query->where('Community.is_del',$where['is_del']);
});
}
}

View File

@ -0,0 +1,50 @@
<?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\PriceRule;
use app\common\repositories\system\RelevanceRepository;
class PriceRuleDao extends BaseDao
{
protected function getModel(): string
{
return PriceRule::class;
}
public function search(array $where)
{
return PriceRule::getDB()->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
$query->whereLike('rule_name', "%{$where['keyword']}%");
})->when(isset($where['is_show']) && $where['is_show'] !== '', function ($query) use ($where) {
$query->where('is_show', $where['is_show']);
})->when(isset($where['cate_id']) && $where['cate_id'] !== '', function ($query) use ($where) {
$ids = app()->make(RelevanceRepository::class)->query([
'type' => RelevanceRepository::PRICE_RULE_CATEGORY
])->where(function ($query) use ($where) {
if (is_array($where['cate_id'])) {
$query->whereIn('right_id', $where['cate_id']);
} else {
$query->where('right_id', (int)$where['cate_id']);
}
})->group('left_id')->column('left_id');
$ids[] = -1;
$query->where(function ($query) use ($ids) {
$query->whereIn('rule_id', $ids)->whereOr('is_default', 1);
});
});
}
}

View File

@ -18,6 +18,7 @@ use app\common\dao\BaseDao;
use app\common\model\BaseModel;
use app\common\model\store\coupon\StoreCoupon;
use app\common\model\store\coupon\StoreCouponUser;
use app\common\repositories\store\coupon\StoreCouponRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use think\Collection;
use think\db\BaseQuery;
@ -115,11 +116,10 @@ class StoreCouponDao extends BaseDao
return $query;
}
public function validCouponQueryWithMerchant($where,$uid = null,$send_type = 0)
public function validCouponQueryWithMerchant($where,$uid = null)
{
$query = StoreCoupon::alias('C')->leftJoin('Merchant M','C.mer_id = M.mer_id')
->where('C.status', 1)
->where('C.send_type', $send_type)
->where('C.is_del', 0)
->when(isset($where['type']) && !is_null($where['type']), function ($query) use ($where) {
if ($where['type'] == '') {
@ -128,6 +128,12 @@ class StoreCouponDao extends BaseDao
$query->where('C.type', $where['type']);
}
})
->when(isset($where['send_type']) && $where['send_type'] != '', function($query) use($where){
$query->where('C.send_type', $where['send_type']);
})
->when(isset($where['not_svip']) && $where['not_svip'] != '', function($query) use($where){
$query->where('C.send_type', '<>',StoreCouponRepository::GET_COUPON_TYPE_SVIP);
})
->when($uid, function($query) use($uid){
$couponId = StoreCouponUser::where('uid',$uid)->whereIn('status',[1,2])->column('coupon_id');
$query->whereNotIn('C.coupon_id', $couponId);
@ -179,6 +185,15 @@ class StoreCouponDao extends BaseDao
})->where('coupon_id', $id)->find();
}
public function validSvipCoupon($id, $uid)
{
return $this->validCouponQuery(null,StoreCouponRepository::GET_COUPON_TYPE_SVIP)->when($uid, function (BaseQuery $query, $uid) {
$query->with(['svipIssue' => function (BaseQuery $query) use ($uid) {
$query->where('uid', $uid);
}]);
})->where('coupon_id', $id)->find();
}
/**
* @param $merId
* @param null $uid

View File

@ -118,7 +118,7 @@ class StoreCouponUserDao extends BaseDao
->with(['product' => function ($query) {
$query->field('coupon_id,product_id');
}, 'coupon' => function ($query) {
$query->field('coupon_id,type');
$query->field('coupon_id,type,send_type');
}])->order('coupon_price DESC, coupon_user_id ASC')->select();
}
}

View File

@ -67,10 +67,10 @@ class StoreCartDao extends BaseDao
$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');
$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');
$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']);
@ -84,7 +84,7 @@ class StoreCartDao extends BaseDao
{
return StoreCart::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');
$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');
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) {
@ -107,7 +107,7 @@ class StoreCartDao extends BaseDao
}
},
'productAttr' => function (Relation $query) {
$query->field('image,extension_one,extension_two,product_id,stock,price,unique,sku,volume,weight,ot_price,cost')
$query->field('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) {

View File

@ -37,6 +37,16 @@ use think\Model;
*/
class StoreOrderDao 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
@ -82,18 +92,28 @@ class StoreOrderDao extends BaseDao
$query->where('activity_type', $where['activity_type']);
})
->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
if ($where['status'] == -2)
$query->where('paid', 1)->whereNotIn('StoreOrder.status', [10, 11]);
else if ($where['status'] == 0)
$query->whereIn('StoreOrder.status', [0, 9]);
else if ($where['status'] == 10)
$query->whereIn('StoreOrder.status', [10, 11]);
else
$query->where('StoreOrder.status', $where['status']);
switch ($where['status']) {
case 0 :
$query->whereIn('StoreOrder.status', [0, 9]);
break;
case -2 :
$query->where('paid', 1)->whereNotIn('StoreOrder.status', [10, 11]);
break;
case 10 :
$query->where('paid', 1)->whereIn('StoreOrder.status', [10, 11]);
break;
default:
$query->where('StoreOrder.status', $where['status']);
break;
}
})
->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
$query->where('uid', $where['uid']);
})
//待核销订单
->when(isset($where['is_verify']) && $where['is_verify'], function ($query) use ($where) {
$query->where('StoreOrder.order_type', 1)->where('StoreOrder.status',0);
})
->when(isset($where['pay_type']) && $where['pay_type'] !== '', function ($query) use ($where) {
$query->where('StoreOrder.pay_type', $where['pay_type']);
})
@ -152,7 +172,9 @@ class StoreOrderDao extends BaseDao
$query->where('mer_id',$where['mer_id']);
})->column('order_id');
$query->where(function($query) use($orderId,$where){
$query->whereIn('order_id',$orderId ?: '')->whereOr('order_sn','like',"%{$where['search']}%");
$query->whereIn('order_id',$orderId ? $orderId : '')
->whereOr('order_sn','like',"%{$where['search']}%")
->whereOr('user_phone','like',"%{$where['search']}%");
});
})
->when(isset($where['group_order_sn']) && $where['group_order_sn'] !== '', function ($query) use ($where) {

View File

@ -28,7 +28,8 @@ use think\model\Relation;
*/
class StoreOrderProductDao extends BaseDao
{
const ORDER_VERIFY_STATUS_ = 1;
const ORDER_VERIFY_STATUS_SUCCESS = 3;
/**
* @return string
* @author xaboy
@ -64,7 +65,7 @@ class StoreOrderProductDao extends BaseDao
*/
public function noReplyProductCount($orderId)
{
return StoreOrderProduct::getDB()->where('order_id', $orderId)->where('is_reply', 0)
return StoreOrderProduct::getDB()->where('order_id', $orderId)->where('is_refund','<>','3')->where('is_reply', 0)
->count();
}

View File

@ -63,7 +63,7 @@ class StoreRefundOrderDao extends BaseDao
})->when(isset($where['type']) && $where['type'] == 1, function ($query) {
$query->whereIn('StoreRefundOrder.status', [0, 1, 2]);
})->when(isset($where['type']) && $where['type'] == 2, function ($query) {
$query->whereIn('status', [-1, 3]);
$query->whereIn('status', [-1, 3,-10]);
})->when(isset($where['refund_type']) && $where['refund_type'] !== '',function($query)use($where){
$query->where('refund_type',$where['refund_type']);
})->when(isset($where['reconciliation_type']) && $where['reconciliation_type'] !== '' ,function($query)use($where){

View File

@ -15,6 +15,7 @@ namespace app\common\dao\store\product;
use app\common\dao\BaseDao;
use app\common\model\store\product\ProductAttrValue as model;
use app\common\repositories\store\product\ProductRepository;
use think\db\exception\DbException;
use think\facade\Db;
@ -257,4 +258,22 @@ class ProductAttrValueDao extends BaseDao
});
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(ProductRepository::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');
}
}

View File

@ -103,6 +103,9 @@ class SpuDao extends BaseDao
->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');
})
@ -158,6 +161,9 @@ class SpuDao extends BaseDao
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);
}

View File

@ -68,6 +68,7 @@ class CacheDao extends BaseDao
{
$cache = $this->getModel()::getDB()->whereIn('key',$keys)->column('result','key');
$ret = [];
foreach ($cache as $k => $v) {
$ret[$k] = json_decode($v);
}

View File

@ -32,13 +32,16 @@ class RelevanceDao extends BaseDao
}
public function joinUser($uid)
public function joinUser($where)
{
$query = Relevance::hasWhere('community',function($query) use($uid){
$query = Relevance::hasWhere('community',function($query) use($where){
$query->where('status',1)->where('is_show',1)->where('is_del',0);
$query->when(isset($where['is_type']) && $where['is_type'] !== '',function($query) use($where){
$query->where('is_type',$where['is_type']);
});
});
$query->where('left_id',$uid)->where('type',RelevanceRepository::TYPE_COMMUNITY_START);
$query->where('left_id',$where['uid'])->where('type',RelevanceRepository::TYPE_COMMUNITY_START);
return $query;
}

View File

@ -230,9 +230,11 @@ class MerchantDao extends BaseDao
{
$field = 'mer_money';
$merchant = $this->getModel()::getDB()->where('mer_id', $merId)->find();
$mer_money = bcadd($merchant[$field], $num, 2);
$merchant[$field] = $mer_money;
$merchant->save();
if ($merchant) {
$mer_money = bcadd($merchant[$field], $num, 2);
$merchant[$field] = $mer_money;
$merchant->save();
}
}
/**
@ -246,9 +248,11 @@ class MerchantDao extends BaseDao
{
$field = 'mer_money';
$merchant = $this->getModel()::getDB()->where('mer_id', $merId)->find();
$mer_money = bcsub($merchant[$field], $num, 2);
$merchant[$field] = $mer_money;
$merchant->save();
if ($merchant) {
$mer_money = bcsub($merchant[$field], $num, 2);
$merchant[$field] = $mer_money;
$merchant->save();
}
}
public function clearTypeId(int $typeId)

View File

@ -37,4 +37,30 @@ class SystemNoticeConfigDao extends BaseDao
$value = $this->getModel()::getDb()->where('const_key',$key)->field('notice_sys,notice_wechat,notice_routine,notice_sms')->find();
return $value;
}
public function search($where)
{
$query = $this->getModel()::getDb()
->when(isset($where['is_sms']) && $where['is_sms'] != '', function($query){
$query->whereIn('notice_sms',[0,1]);
})
->when(isset($where['is_routine']) && $where['is_routine'] != '', function($query){
$query->whereIn('notice_routine',[0,1]);
})
->when(isset($where['is_wechat']) && $where['is_wechat'] != '', function($query){
$query->whereIn('notice_wechat',[0,1]);
})
;
return $query;
}
public function getSubscribe()
{
$arr = [];
$res = $this->search([])->where(['notice_routine' => 1])->with(['routineTemplate'])->select()->toArray();
foreach ($res as $re) {
$arr[$re['const_key']] = $re['routineTemplate']['tempid'] ?? '';
}
return $arr;
}
}

View File

@ -70,12 +70,13 @@ class UserDao extends BaseDao
} else {
$query = User::getDB()->alias('User');
}
$query->whereNull('User.cancel_time')->when(isset($where['keyword']) && $where['keyword'], function (BaseQuery $query) use ($where) {
$query->whereNull('User.cancel_time')
->when(isset($where['keyword']) && $where['keyword'], function (BaseQuery $query) use ($where) {
return $query->where('User.uid|User.real_name|User.nickname|User.phone', 'like', '%' . $where['keyword'] . '%');
})->when(isset($where['user_type']) && $where['user_type'] !== '', function (BaseQuery $query) use ($where) {
return $query->where('User.user_type', $where['user_type']);
})->when(isset($where['uids']) && $where['uids'] !== '', function (BaseQuery $query) use ($where) {
return $query->whereIn('User.uid', $where['uids']);
})->when(isset($where['uid']) && $where['uid'] !== '', function (BaseQuery $query) use ($where) {
return $query->where('User.uid', $where['uid']);
})->when(isset($where['status']) && $where['status'] !== '', function (BaseQuery $query) use ($where) {
return $query->where('User.status', intval($where['status']));
})->when(isset($where['group_id']) && $where['group_id'], function (BaseQuery $query) use ($where) {
@ -121,6 +122,10 @@ class UserDao extends BaseDao
$query->order('User.' . $where['sort']);
}, function ($query) {
$query->order('User.uid DESC');
})->when(isset($where['is_svip']) && $where['is_svip'] !== '', function (BaseQuery $query) use ($where) {
return $query->where('User.is_svip','>',0);
})->when(isset($where['svip_type']) && $where['svip_type'] !== '', function (BaseQuery $query) use ($where) {
return $query->where('User.is_svip',$where['svip_type']);
});
return $query;
@ -287,7 +292,7 @@ class UserDao extends BaseDao
return User::getDB()->alias('A')
->join('StoreOrder B', 'A.uid = B.uid and B.paid = 1 and B.pay_time between \'' . date('Y/m/d', strtotime('first day of')) . ' 00:00:00\' and \'' . date('Y/m/d H:i:s') . '\'')
->join('PresellOrder C', 'C.order_id = B.order_id and C.paid = 1', 'LEFT')
->field('A.uid,A.avatar,A.nickname,A.now_money,A.pay_price,A.pay_count, sum(B.pay_price + IFNULL(C.pay_price,0)) as total_pay_price, count(B.order_id) as total_pay_count')
->field('A.uid,A.avatar,A.nickname,A.now_money,A.pay_price,A.pay_count, sum(B.pay_price + IFNULL(C.pay_price,0)) as total_pay_price, count(B.order_id) as total_pay_count,is_svip,svip_endtime,svip_save_money')
->where('A.uid', $uid)
->find();
}

View File

@ -0,0 +1,68 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\dao\user;
use app\common\dao\BaseDao;
use app\common\model\user\LabelRule;
use app\common\model\user\UserOrder;
class UserOrderDao extends BaseDao
{
protected function getModel(): string
{
return UserOrder::class;
}
public function search(array $where)
{
return UserOrder::hasWhere('user',function($query)use($where){
$query->when(isset($where['uid']) && $where['uid'] != '',function($query) use($where){
$query->where('uid', $where['uid']);
})
->when(isset($where['keyword']) && $where['keyword'] != '',function($query) use($where){
$query->whereLike('nickname', "%{$where['keyword']}%");
})
->when(isset($where['phone']) && $where['phone'] != '',function($query) use($where){
$query->where('phone', $where['phone']);
});
$query->where(true);
})
->when(isset($where['order_sn']) && $where['order_sn'] !== '', function ($query) use ($where) {
$query->whereLike('order_sn', "%{$where['order_sn']}%");
})
->when(isset($where['title']) && $where['title'] !== '', function ($query) use ($where) {
$query->whereLike('title', "%{$where['title']}%");
})
->when(isset($where['order_type']) && $where['order_type'] !== '', function ($query) use ($where) {
$query->where('order_type', $where['order_type']);
})
->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
$query->where('paid', $where['paid']);
})
->when(isset($where['pay_type']) && $where['pay_type'] !== '', function ($query) use ($where) {
$query->where('pay_type', $where['pay_type']);
})
->when(isset($where['pay_time']) && $where['pay_time'] !== '', function ($query) use ($where) {
$query->whereDay('pay_time', $where['pay_time']);
})
->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
$query->whereDay('mer_id', $where['mer_id']);
})
->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
getModelTime($query, $where['date'], 'UserOrder.create_time');
})
;
}
}

View File

@ -93,6 +93,9 @@ class AdminTokenMiddleware extends BaseMiddleware
$request->macro('adminInfo', function () use (&$admin) {
return $admin;
});
$request->macro('userType', function () {
return 2;
});
}
public function after(Response $response)

View File

@ -35,7 +35,7 @@ class AllowOriginMiddleware extends BaseMiddleware
'Access-Control-Allow-Headers' => 'X-Token, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With,Form-type,Referer,Connection,Content-Length,Host,Origin,Authorization,Authori-zation,Accept,Accept-Encoding',
//,Host,Origin,Authorization,Authori-zation,Accept,Accept-Encoding
//'Access-Control-Allow-Headers' => '*',
'Access-Control-Allow-Methods' => 'GET,POST,PATCH,PUT,DELETE,OPTIONS,DELETE',
'Access-Control-Allow-Methods' => 'GET,POST,PATCH,PUT,DELETE,OPTIONS',
'Access-Control-Max-Age' => '1728000'
];

View File

@ -0,0 +1,59 @@
<?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\middleware;
use app\common\repositories\system\auth\MenuRepository;
use app\common\repositories\system\auth\RoleRepository;
use app\Request;
use Doctrine\Common\Cache\RedisCache;
use http\Exception\InvalidArgumentException;
use think\facade\Cache;
use think\Response;
class BlockerMiddleware extends BaseMiddleware
{
protected $key;
public function before(Request $request)
{
$uid = request()->uid();
$this->key = md5(request()->rule()->getRule() . $uid);
if (!$this->setMutex($this->key)) {
throw new InvalidArgumentException('请求太过频繁,请稍后再试');
}
}
public function setMutex(string $key, int $timeout = 10)
{
$curTime = time();
$readMutexKey = "redis:mutex:{$key}";
$mutexRes = Cache::store('redis')->handler()->setnx($readMutexKey, $curTime + $timeout);
if ($mutexRes) {
return true;
}
//就算意外退出下次进来也会检查key防止死锁
$time = Cache::store('redis')->handler()->get($readMutexKey);
if ($curTime > $time) {
Cache::store('redis')->handler()->del($readMutexKey);
return Cache::store('redis')->handler()->setnx($readMutexKey, $curTime + $timeout);
}
return false;
}
public function after(Response $response)
{
Cache::store('redis')->handler()->del("redis:mutex:{$this->key}");
// TODO: Implement after() method.
}
}

View File

@ -109,6 +109,9 @@ class MerchantTokenMiddleware extends BaseMiddleware
$request->macro('merchant', function () use (&$merchant) {
return $merchant;
});
$request->macro('userType', function () use (&$merchant) {
return 3;
});
}
public function after(Response $response)

View File

@ -0,0 +1,35 @@
<?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\middleware;
use app\Request;
use crmeb\interfaces\MiddlewareInterface;
use crmeb\services\LockService;
use think\Response;
class RequestLockMiddleware implements MiddlewareInterface
{
final public function handle(Request $request, \Closure $next, ...$args): Response
{
$params = $request->route();
if (!count($params) || in_array(strtolower($request->method()), ['get', 'options']) || $request->rule()->getOption('_lock', true) === false) {
return $next($request);
}
ksort($params);
$key = 're:' . $request->rule()->getName() . ':' . implode('-', $params);
return app()->make(LockService::class)->exec($key, function () use ($next, $request) {
return $next($request);
}, 8);
}
}

View File

@ -81,6 +81,9 @@ class UserTokenMiddleware extends BaseMiddleware
$request->macro('isLogin', function () {
return true;
});
$request->macro('userType', function () {
return 1;
});
$request->macro('tokenInfo', function () use (&$payload) {
return $payload;
});

View File

@ -70,6 +70,14 @@ class Community extends BaseModel
->where('type',RelevanceRepository::TYPE_COMMUNITY_PRODUCT);
}
/*
* 右侧为内容ID的
*/
public function relevanceRight()
{
return $this->hasMany(Relevance::class, 'right_id','community_id');
}
public function isStart()
{
return $this->hasOne(Relevance::class, 'right_id','community_id')->where('type', RelevanceRepository::TYPE_COMMUNITY_START)->bind(['relevance_id']);
@ -77,7 +85,7 @@ class Community extends BaseModel
public function isFans()
{
return $this->hasOne(Relevance::class, 'right_id','uid')->where('type', RelevanceRepository::TYPE_COMMUNITY_FANS)->bind(['right_id']);
return $this->hasOne(Relevance::class, 'right_id','uid')->where('type', RelevanceRepository::TYPE_COMMUNITY_FANS)->bind(['is_fans' => 'right_id']);
}
public function category()
@ -90,6 +98,11 @@ class Community extends BaseModel
return date('m月d日',strtotime($this->create_time));
}
public function getCountReplyAttr()
{
return CommunityReply::where('community_id',$this->community_id)->where('status',1)->count();
}
public function searchTopicIdAttr($query, $value)
{
$query->where('topic_id', $value);
@ -142,6 +155,21 @@ class Community extends BaseModel
->column('left_id');
$query->where('community_id','in', $id);
}
public function searchIsTypeAttr($query, $value)
{
$query->whereIn('is_type', $value);
}
public function searchCommunityIdAttr($query, $value)
{
$query->where('community_id', $value);
}
public function searchNotIdAttr($query, $value)
{
$query->where('community_id', '<>',$value);
}
public function searchNoCategoryIdAttr($query, $value)
{
$query->where('category_id', '<>',$value);

View File

@ -27,4 +27,20 @@ class CityArea extends BaseModel
{
return 'city_area';
}
public function parent()
{
return $this->hasOne(self::class,'id','parent_id');
}
public function getChildrenAttr()
{
return [];
}
public function getHasChildrenAttr()
{
$count = self::where('parent_id',$this->id)->count();
return $count ? true : false;
}
}

View File

@ -0,0 +1,39 @@
<?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\system\Relevance;
use app\common\repositories\system\RelevanceRepository;
class PriceRule extends BaseModel
{
public static function tablePk(): string
{
return 'rule_id';
}
public static function tableName(): string
{
return 'price_rule';
}
public function cate()
{
return $this->hasMany(Relevance::class, 'left_id', 'rule_id')->where([
'type' => RelevanceRepository::PRICE_RULE_CATEGORY
])->with(['category']);
}
}

View File

@ -51,6 +51,10 @@ class StoreCoupon extends BaseModel
{
return $this->hasOne(StoreCouponIssueUser::class, 'coupon_id', 'coupon_id');
}
public function svipIssue()
{
return $this->hasOne(StoreCouponIssueUser::class, 'coupon_id', 'coupon_id')->whereMonth('create_time');
}
public function merchant()
{

View File

@ -23,6 +23,7 @@ use app\common\model\store\product\ProductGroup;
use app\common\model\store\product\ProductPresell;
use app\common\model\store\product\ProductPresellSku;
use app\common\model\store\product\ProductSku;
use app\common\model\store\product\Spu;
use app\common\model\store\product\StoreDiscounts;
use app\common\model\system\merchant\Merchant;
use app\common\repositories\store\order\StoreOrderProductRepository;
@ -79,6 +80,7 @@ class StoreCart extends BaseModel
return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
}
public function productPresell()
{
return $this->hasOne(ProductPresell::class,'product_presell_id','source_id');
@ -146,6 +148,21 @@ class StoreCart extends BaseModel
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 Spu::where($where)->field('spu_id,store_name')->find();
}
/**
* TODO 检测商品是否有效
* @return bool

View File

@ -51,6 +51,11 @@ class StoreOrder extends BaseModel
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(Merchant::class, 'mer_id', 'mer_id');
@ -60,6 +65,10 @@ class StoreOrder extends BaseModel
{
return $this->hasOne(User::class, 'uid', 'uid');
}
public function receipt()
{
return $this->hasOne(StoreOrderReceipt::class, 'order_id', 'order_id');
}
public function spread()
{
@ -158,4 +167,8 @@ class StoreOrder extends BaseModel
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');
}
}

View File

@ -18,6 +18,7 @@ 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;
@ -25,6 +26,7 @@ use app\common\model\store\StoreSeckillActive;
use app\common\model\system\merchant\Merchant;
use app\common\repositories\store\StoreCategoryRepository;
use crmeb\services\VicWordService;
use Darabonba\GatewaySpi\Models\InterceptorContext\request;
use think\db\BaseQuery;
use think\facade\Db;
use think\model\concern\SoftDelete;
@ -71,19 +73,30 @@ class Product extends BaseModel
public function getMaxExtensionAttr($value)
{
if($this->extension_type){
return ($this->attrValue()->order('extension_two DESC')->value('extension_one'));
$org_extension = ($this->attrValue()->order('extension_two DESC')->value('extension_one'));
} else {
return bcmul(($this->attrValue()->order('price DESC')->value('price')) , systemConfig('extension_one_rate'),2);
$org_extension = bcmul(($this->attrValue()->order('price DESC')->value('price')) , systemConfig('extension_one_rate'),2);
}
$spreadUser = (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){
return ($this->attrValue()->order('extension_two ASC')->value('extension_two'));
$org_extension = ($this->attrValue()->order('extension_two ASC')->value('extension_two'));
} else {
return bcmul(($this->attrValue()->order('price ASC')->value('price')) , systemConfig('extension_one_rate'),2);
$org_extension = bcmul(($this->attrValue()->order('price ASC')->value('price')) , systemConfig('extension_one_rate'),2);
}
$spreadUser = (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;
@ -159,6 +172,14 @@ class Product extends BaseModel
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;
}
@ -202,6 +223,26 @@ class Product extends BaseModel
}
}
/**
* 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;
}
/*
* -----------------------------------------------------------------------------------------------------------------
* 关联模型
@ -279,6 +320,93 @@ class Product extends BaseModel
return $this->hasOne(GuaranteeTemplate::class,'guarantee_template_id','guarantee_template_id')->where('status',1)->where('is_del',0);
}
/**
* TODO 是否是会员
* @return bool
* @author Qinii
* @day 2023/1/4
*/
public function getIsVipAttr()
{
if (request()->isLogin()) {
if (request()->userType() == 1) {
$userInfo = request()->userInfo();
return $userInfo->is_svip ? 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;
}
/*
* -----------------------------------------------------------------------------------------------------------------
* 搜索器

View File

@ -17,7 +17,6 @@ use app\common\model\system\merchant\Merchant;
use app\common\repositories\store\product\ProductAssistSetRepository;
use app\common\repositories\store\product\ProductAssistUserRepository;
use app\common\repositories\store\product\SpuRepository;
use crmeb\jobs\ChangeSpuStatusJob;
class ProductAssist extends BaseModel
{
@ -83,8 +82,7 @@ class ProductAssist extends BaseModel
if($end_time <= $time) {
$this->action_status = -1;
$this->save();
//app()->make(SpuRepository::class)->changeStatus($this->product_assist_id,3);
Queue(ChangeSpuStatusJob::class, ['id' => $this->product_assist_id, 'product_type' => 3]);
app()->make(SpuRepository::class)->changeStatus($this->product_assist_id,3);
return 2;
}
}

View File

@ -45,6 +45,21 @@ class ProductAttrValue extends BaseModel
return json_decode($value);
}
public function product()
{
return $this->hasOne(Product::class, 'product_id','product_id');
}
public function getSvipPriceAttr()
{
if ($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 getBcExtensionOneAttr()
{
if(!intval(systemConfig('extension_status'))) return 0;

View File

@ -15,7 +15,6 @@ use app\common\model\store\order\StoreOrderProduct;
use app\common\model\system\merchant\Merchant;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\store\product\SpuRepository;
use crmeb\jobs\ChangeSpuStatusJob;
class ProductGroup extends BaseModel
{

View File

@ -48,6 +48,11 @@ class ProductGroupUser extends BaseModel
return $this->hasOne(ProductGroupBuying::class,'group_buying_id','group_buying_id');
}
public function productGroup()
{
return $this->hasOne(ProductGroup::class,'product_group_id','product_group_id');
}
// public function getAvatarAttr($value)
// {
// return $value ? $value : '/static/f.png';

View File

@ -15,10 +15,7 @@ namespace app\common\model\store\product;
use app\common\model\BaseModel;
use app\common\model\system\merchant\Merchant;
use app\common\repositories\store\coupon\StoreCouponRepository;
use app\common\repositories\store\order\StoreOrderProductRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\store\product\SpuRepository;
use crmeb\jobs\ChangeSpuStatusJob;
class ProductPresell extends BaseModel
{
@ -86,8 +83,7 @@ class ProductPresell extends BaseModel
$this->action_status = -1;
$this->save();
}
queue(ChangeSpuStatusJob::class, ['id' => $this->product_presell_id, 'product_type' => 2]);
//app()->make(SpuRepository::class)->changeStatus($this->product_presell_id,2);
app()->make(SpuRepository::class)->changeStatus($this->product_presell_id,2);
return 2;
}
}

View File

@ -67,4 +67,23 @@ class ProductReply extends BaseModel
return $this->hasOne(StoreOrderProduct::class,'order_product_id','order_product_id');
}
/**
* TODO 用户昵称处理
* @param $value
* @return string
* @author Qinii
* @day 2022/11/28\
*/
public function getNicnameAttr($value)
{
if (strlen($value) > 1) {
$str = mb_substr($value,0,1) . '*';
if (strlen($value) > 2) {
$str .= mb_substr($value, -1,1);
}
return $str;
}
return $value;
}
}

View File

@ -102,6 +102,7 @@ class Spu extends BaseModel
return explode(',',rtrim(ltrim($value,','),','));
}
public function setSysLabelsAttr($value)
{
if (!empty($value)) {
@ -127,6 +128,28 @@ class Spu extends BaseModel
}
}
/**
* TODO 是否展示会员价
* @return array
* @author Qinii
* @day 2023/1/4
*/
public function getShowSvipInfoAttr($value, $data)
{
return $this->product->show_svip_info;
}
/**
* TODO 获取会员价
* @return int|string
* @author Qinii
* @day 2023/1/4
*/
public function getSvipPriceAttr()
{
return $this->product->svip_price;
}
/*
* -----------------------------------------------------------------------------------------------------------------
* 关联表

View File

@ -60,7 +60,7 @@ class Relevance extends BaseModel
public function community()
{
return $this->hasOne(Community::class,'community_id','right_id')
->bind(['community_id','title','image','start','uid','create_time','count_start','author']);
->bind(['community_id','title','image','start','uid','create_time','count_start','author','is_type']);
}
public function getIsStartAttr()

View File

@ -85,7 +85,7 @@ class Merchant extends BaseModel
->field('mer_id,product_id,store_name,image,price,is_show,status,is_gift_bag,is_good,cate_id')
->order('sort DESC, create_time DESC')
->limit(3)
->select();
->select()->append(['show_svip_info']);
if ($list) {
$data = [];
$make = app()->make(StoreActivityRepository::class);

View File

@ -15,6 +15,7 @@ namespace app\common\model\system\notice;
use app\common\model\BaseModel;
use app\common\model\wechat\TemplateMessage;
/**
* Class SystemNoticeLog
@ -45,6 +46,16 @@ class SystemNoticeConfig extends BaseModel
return 'system_notice_config';
}
public function wechatTemplate()
{
return $this->hasOne(TemplateMessage::class,'tempkey','wechat_tempkey');
}
public function routineTemplate()
{
return $this->hasOne(TemplateMessage::class,'tempkey','routine_tempkey');
}
public function searchKeywordAttr($query, $value)
{
$query->whereLike("notice_title|notice_key|notice_info","%{$value}%");
@ -54,4 +65,9 @@ class SystemNoticeConfig extends BaseModel
{
$query->where("type",$value);
}
public function searchConstKeyAttr($query, $value)
{
$query->where("const_key",$value);
}
}

View File

@ -12,6 +12,7 @@ namespace app\common\model\system\serve;
use app\common\model\BaseModel;
use app\common\model\system\merchant\Merchant;
use app\common\model\user\User;
class ServeOrder extends BaseModel
{
@ -36,6 +37,11 @@ class ServeOrder extends BaseModel
return $this->hasOne(Merchant::class,'mer_id','mer_id');
}
public function userInfo()
{
return $this->hasOne(User::class,'mer_id','ud');
}
public function searchTypeAttr($query, $value)
{
$query->where('type', $value);
@ -70,4 +76,9 @@ class ServeOrder extends BaseModel
{
getModelTime($query, $value);
}
public function searchPayTypeAttr($query,$value)
{
$query->where('value');
}
}

View File

@ -52,4 +52,10 @@ class MemberInterests extends BaseModel
{
$query->where('brokerage_level', '<=', $value);
}
public function searchStatusAttr($query, $value)
{
$query->where('status', $value);
}
}

View File

@ -66,6 +66,16 @@ class User extends BaseModel
return $value == '0000-00-00' ? '' : $value;
}
public function getIsSvipAttr($value)
{
if (systemConfig('svip_switch_status') == 1) {
return $value;
} else {
return $value > 0 ? 0 : $value;
}
}
/**
* @param $value
* @return array

View File

@ -0,0 +1,36 @@
<?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\user;
use app\common\model\BaseModel;
class UserOrder extends BaseModel
{
public static function tablePk(): ?string
{
return 'order_id';
}
public static function tableName(): string
{
return 'user_order';
}
public function user()
{
return $this->hasOne(User::class,'uid','uid');
}
}

View File

@ -85,13 +85,14 @@ class CommunityCategoryRepository extends BaseRepository
->setOption('filed',[])->field('category_id,cate_name')->with(['children'])->order('sort DESC,category_id DESC')->select();
$list = [];
if ($res) $list = $res->toArray();
$hot = app()->make(CommunityTopicRepository::class)->getHotList();
$data[] = [
'category_id' => 0,
"cate_name" => "推荐",
"children" => $hot['list']
];
return array_merge($data,$list);
// $hot = app()->make(CommunityTopicRepository::class)->getHotList();
// $data[] = [
// 'category_id' => 0,
// "cate_name" => "推荐",
// "children" => $hot['list']
// ];
// return array_merge($data,$list);
return $list;
}
public function checkName($name, $id)

View File

@ -136,7 +136,6 @@ class CommunityReplyRepository extends BaseRepository
$res = Db::transaction(function () use ($replyId, $data, $make) {
$res = $this->dao->create($data);
if ($replyId) $this->dao->incField($data['pid'], 'count_reply', 1);
$make->incField($data['community_id'], 'count_reply', 1);
return $res;
});
@ -183,6 +182,7 @@ class CommunityReplyRepository extends BaseRepository
public function statusForm(int $id)
{
$formData = $this->dao->get($id)->toArray();
if ($formData['status'] !== 0) throw new ValidateException('请勿重复审核');
$form = Elm::createForm(Route::buildUrl('systemCommunityReplyStatus', ['id' => $id])->build());
@ -191,12 +191,14 @@ class CommunityReplyRepository extends BaseRepository
Elm::radio('status', '审核状态', 1)->options([
['value' => -1, 'label' => '未通过'],
['value' => 1, 'label' => '通过']])->control([
['value' => -1, 'rule' => [
Elm::textarea('refusal', '未通过原因', '')->required()
]]
['value' => 1, 'label' => '通过']]
)->control([
['value' => -1, 'rule' => [
Elm::textarea('refusal', '未通过原因', '')->required()
]]
]),
]);
$formData['status'] = 1;
return $form->setTitle('审核评论')->formData($formData);
}
}

View File

@ -19,6 +19,7 @@ use app\common\repositories\store\product\SpuRepository;
use app\common\repositories\system\RelevanceRepository;
use app\common\repositories\user\UserBrokerageRepository;
use app\common\repositories\user\UserRepository;
use crmeb\services\QrcodeService;
use FormBuilder\Factory\Elm;
use think\exception\ValidateException;
use think\facade\Db;
@ -37,6 +38,9 @@ class CommunityRepository extends BaseRepository
'is_del' => 0,
];
public const COMMUNIT_TYPE_FONT = '1';
public const COMMUNIT_TYPE_VIDEO = '2';
/**
* CommunityRepository constructor.
* @param CommunityDao $dao
@ -46,9 +50,25 @@ class CommunityRepository extends BaseRepository
$this->dao = $dao;
}
public function title(array $where)
{
$where['is_type'] = self::COMMUNIT_TYPE_FONT;
$list[] = [
'count' => $this->dao->search($where)->count(),
'title' => '图文列表',
'type' => self::COMMUNIT_TYPE_FONT,
];
$where['is_type'] = self::COMMUNIT_TYPE_VIDEO;
$list[] = [
'count' => $this->dao->search($where)->count(),
'title' => '短视频列表',
'type' => self::COMMUNIT_TYPE_VIDEO,
];
return $list;
}
public function getList(array $where, int $page, int $limit)
{
$where['is_del'] = 0;
$query = $this->dao->search($where)->with([
'author' => function($query) {
$query->field('uid,real_name,status,avatar,nickname,count_start');
@ -61,14 +81,17 @@ class CommunityRepository extends BaseRepository
]);
$count = $query->count();
$list = $query->page($page, $limit)->select();
return compact('count','list');
}
public function getApiList(array $where, int $page, int $limit, $userInfo)
{
$config = systemConfig("community_app_switch");
if (!isset($where['is_type']) && $config) $where['is_type'] = $config;
$where['is_del'] = 0;
$query = $this->dao->getSearch($where)->order('start DESC,create_time DESC,community_id DESC');
$query = $this->dao->search($where)->order('start DESC,Community.create_time DESC,community_id DESC');
$query->with([
'author' => function($query) use($userInfo){
$query->field('uid,real_name,status,avatar,nickname,count_start');
@ -91,63 +114,63 @@ class CommunityRepository extends BaseRepository
]);
$count = $query->count();
$list = $query->page($page, $limit)->setOption('field',[])
->field('community_id,title,image,topic_id,count_start,count_reply,start,create_time,uid,status,is_show,content')
->field('community_id,title,image,topic_id,Community.count_start,count_reply,start,Community.create_time,Community.uid,Community.status,is_show,content,video_link,is_type,refusal')
->select()->append(['time']);
if ($list) $list = $list->toArray();
return compact('count','list');
}
public function getApiListTwo(array $where, int $page, int $limit, $userInfo)
public function getFirtVideo($where,$page, $userInfo)
{
if (!$userInfo){
$count=0;
$list=[];
return compact('count','list');
}
$village_id=Db::name('nk_user')->where('user_id',$userInfo->uid)->value('village_id');
if (!$village_id){
$count=0;
$list=[];
return compact('count','list');
}
$arr=Db::name('community_address')->where('village_id',$village_id)->page($page, $limit)->select();
if (count($arr)==0){
$count=0;
$list=[];
return compact('count','list');
}
$arr2=[];
foreach ($arr as $k=>$v){
$arr2[]=$v['community_id'];
}
$arrWhere=['id_and_in'=>$arr2];
$query = $this->dao->getSearch($arrWhere)->order('start DESC,create_time DESC,community_id DESC');
$query->with([
'author' => function($query) use($userInfo){
$query->field('uid,real_name,status,avatar,nickname,count_start');
},
'is_start' => function($query) use ($userInfo) {
$query->where('left_id',$userInfo->uid ?? null);
},
'topic' => function($query) {
$query->where('status', 1)->where('is_del',0);
$query->field('topic_id,topic_name,status,category_id,pic,is_del');
},
'relevance' => [
'spu' => function($query) {
$query->field('spu_id,store_name,image,price,product_type,activity_id,product_id');
$with =[];
if ($page == 1) {
$with = [
'author' => function($query) {
$query->field('uid,real_name,status,avatar,nickname,count_start');
},
'is_start' => function($query) use ($userInfo) {
$query->where('left_id',$userInfo->uid ?? null);
},
'topic' => function($query) {
$query->where('status', 1)->where('is_del',0);
$query->field('topic_id,topic_name,status,category_id,pic,is_del');
},
'relevance' => [
'spu' => function($query) {
$query->field('spu_id,store_name,image,price,product_type,activity_id,product_id,status');
}
],
'is_fans' => function($query) use($userInfo){
$query->where('left_id',$userInfo->uid?? 0);
}
],
'is_fans' => function($query) use($userInfo){
$query->where('left_id',$userInfo->uid?? 0);
}
]);
$count = Db::name('community_address')->where('village_id',$village_id)->count();
$list = $query->setOption('field',[])
->field('community_id,title,image,topic_id,count_start,count_reply,start,create_time,uid,status,is_show,content')
->select()->append(['time']);
return compact('count','list');
];
}
return $this->dao->getSearch($where)->with($with)->field('community_id,image,title,topic_id,count_start,count_reply,start,create_time,uid,status,is_show,content,video_link,is_type,refusal')->find();
}
public function getApiVideoList(array $where, int $page, int $limit, $userInfo, $type = 0)
{
$where['is_type'] = self::COMMUNIT_TYPE_VIDEO;
$first = $this->getFirtVideo($where,$page, $userInfo);
if ($type) { // 点赞过的内容
$where['uid'] = $userInfo->uid;
$where['community_ids'] = $this->dao->joinUser($where)->column('community_id');
} else { // 条件视频
if ($first) $where['topic_id'] = $first['topic_id'];
}
$where['not_id'] = $where['community_id'];
unset($where['community_id']);
$data = $this->getApiList($where, $page, $limit, $userInfo);
if (empty($data['list']) && isset($where['topic_id'])) {
unset($where['topic_id']);
$data = $this->getApiList($where, $page, $limit, $userInfo);
}
if ($page == 1 && $first) {
array_unshift($data['list'],$first->toArray());
}
return $data;
}
/**
* TODO 后台详情
* @param int $id
@ -157,7 +180,13 @@ class CommunityRepository extends BaseRepository
*/
public function detail(int $id)
{
return $this->dao->getSearch([$this->dao->getPk() => $id, 'is_del' => 0])->with([
$where = [
$this->dao->getPk() => $id,
'is_del' => 0
];
$config = systemConfig("community_app_switch");
if ($config) $where['is_type'] = $config;
return $this->dao->getSearch($where)->with([
'author' => function($query) {
$query->field('uid,real_name,status,avatar,nickname,count_start');
},
@ -184,6 +213,8 @@ class CommunityRepository extends BaseRepository
$where = ['is_del' => 0];
$is_author = 1;
}
$config = systemConfig("community_app_switch");
if ($config) $where['is_type'] = $config;
$where[$this->dao->getPk()] = $id;
$data = $this->dao->getSearch($where)
->with([
@ -383,9 +414,7 @@ class CommunityRepository extends BaseRepository
$form = Elm::createForm(Route::buildUrl('systemCommunityStatus', ['id' => $id])->build());
$data = $this->dao->get($id);
if (!$data) throw new ValidateException('数据不存在');
$formData = $data->toArray();
return $form->setRule([
Elm::radio('status', '强制下架')->options([
['value' => -2, 'label' => '下架'], ['value' => 1, 'label' => '上架']])->control([
@ -432,7 +461,7 @@ class CommunityRepository extends BaseRepository
$make = app()->make(UserBrokerageRepository::class);
$make->incMemberValue($ret['uid'], 'member_community_num', $id);
}
$data['status_time'] = date('Y-m-d H:i;s', time());
$this->dao->update($id, $data);
event('community.status',compact('id'));
});
@ -453,5 +482,24 @@ class CommunityRepository extends BaseRepository
->field('community_id,title,image')
->limit(3)->select();
}
public function qrcode($id, $type,$user)
{
$res = $this->dao->search(['is_type' => self::COMMUNIT_TYPE_VIDEO,'community_id' => $id])->find();
if (!$res) throw new ValidateException('数据不存在');
$make = app()->make(QrcodeService::class);
if ($type == 'routine') {
$name = md5('rcwx' . $id . $type . $user->uid . $user['is_promoter'] . date('Ymd')) . '.jpg';
$params = 'id=' . $id . '&spid=' . $user['uid'];
$link = '/pages/short_video/nvueSwiper/index?id=';
$make->getRoutineQrcodePath($name, $link, $params);
} else {
$name = md5('cwx' . $id . $type . $user->uid . $user['is_promoter'] . date('Ymd')) . '.jpg';
$link = 'pages/short_video/nvueSwiper/index';
$link = $link . '?id=' . $id . '&spid=' . $user['uid'];
$key = 'com' . $type . '_' . $id . '_' . $user['uid'];
return $make->getWechatQrcodePath($name, $link, false, $key);
}
}
}

View File

@ -15,6 +15,9 @@ namespace app\common\repositories\store;
use app\common\dao\store\CityAreaDao;
use app\common\repositories\BaseRepository;
use FormBuilder\Factory\Elm;
use think\exception\ValidateException;
use think\facade\Route;
/**
* @mixin CityAreaDao
@ -30,4 +33,31 @@ class CityAreaRepository extends BaseRepository
{
return $this->search(['pid' => $pid])->select();
}
public function getList($where)
{
return $this->dao->getSearch($where)->with(['parent'])->order('id ASC')->select()->append(['children','hasChildren']);
}
public function form(?int $id, ?int $parentId)
{
$parent = ['id' => 0, 'name' => '全国', 'level' => 0,];
$formData = [];
if ($id) {
$formData = $this->dao->getWhere(['id' => $id],'*',['parent'])->toArray();
if (!$formData) throw new ValidateException('数据不存在');
$form = Elm::createForm(Route::buildUrl('systemCityAreaUpdate', ['id' => $id])->build());
if (!is_null($formData['parent'])) $parent = $formData['parent'];
} else {
$form = Elm::createForm(Route::buildUrl('systemCityAreaCreate')->build());
if ($parentId) $parent = $this->dao->getWhere(['id' => $parentId]);
}
$form->setRule([
Elm::input('parent_id', '', $parent['id'] ?? 0)->hiddenStatus(true),
Elm::input('level', '', $parent['level'] + 1)->hiddenStatus(true),
Elm::input('parent_name', '上级地址', $parent['name'])->disabled(true),
Elm::input('name', '地址名称', '')->required(),
]);
return $form->setTitle($id ? '编辑城市' : '添加城市')->formData($formData);
}
}

View File

@ -0,0 +1,89 @@
<?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\PriceRuleDao;
use app\common\repositories\BaseRepository;
use app\common\repositories\system\RelevanceRepository;
use think\facade\Db;
/**
* @mixin PriceRuleDao
*/
class PriceRuleRepository extends BaseRepository
{
public function __construct(PriceRuleDao $dao)
{
$this->dao = $dao;
}
public function lst(array $where, $page, $limit)
{
$query = $this->dao->search($where)->order('sort DESC, rule_id DESC');
$count = $query->count();
$list = $query->page($page, $limit)->with(['cate'])->select();
return compact('count', 'list');
}
public function createRule(array $data)
{
$cateIds = (array)$data['cate_id'];
unset($data['cate_id']);
return Db::transaction(function () use ($cateIds, $data) {
$data['is_default'] = count($cateIds) ? 0 : 1;
$rule = $this->dao->create($data);
$inserts = [];
foreach ($cateIds as $id) {
$inserts[] = [
'left_id' => $rule['rule_id'],
'right_id' => (int)$id,
'type' => RelevanceRepository::PRICE_RULE_CATEGORY
];
}
if (count($inserts)) {
app()->make(RelevanceRepository::class)->insertAll($inserts);
}
return $rule;
});
}
public function updateRule(int $id, array $data)
{
$cateIds = (array)$data['cate_id'];
unset($data['cate_id']);
$data['update_time'] = date('Y-m-d H:i:s');
return Db::transaction(function () use ($id, $cateIds, $data) {
$data['is_default'] = count($cateIds) ? 0 : 1;
$this->dao->update($id, $data);
$inserts = [];
foreach ($cateIds as $cid) {
$inserts[] = [
'left_id' => $id,
'right_id' => (int)$cid,
'type' => RelevanceRepository::PRICE_RULE_CATEGORY
];
}
app()->make(RelevanceRepository::class)->query([
'left_id' => $id,
'type' => RelevanceRepository::PRICE_RULE_CATEGORY
])->delete();
if (count($inserts)) {
app()->make(RelevanceRepository::class)->insertAll($inserts);
}
});
}
}

View File

@ -200,7 +200,7 @@ class BroadcastRoomRepository extends BaseRepository
public function applyForm($id)
{
return Elm::createForm(Route::buildUrl('systemBroadcastRoomApply', compact('id'))->build(), [
Elm::radio('status', '审核状态', 1)->options([['value' => -1, 'label' => '未通过'], ['value' => 1, 'label' => '通过']])->control([
Elm::radio('status', '审核状态', '1')->options([['value' => '-1', 'label' => '未通过'], ['value' => '1', 'label' => '通过']])->control([
['value' => -1, 'rule' => [
Elm::textarea('msg', '未通过原因', '信息有误,请完善')->required()
]]
@ -468,13 +468,11 @@ class BroadcastRoomRepository extends BaseRepository
{
$make = app()->make(BroadcastAssistantRepository::class);
$data = $make->getSearch(['assistant_ids' => $ids])->column('username,nickname');
foreach ($data as $datum) {
$params = [
'roomId' => $roomId,
'user' => $datum,
];
MiniProgramService::create()->miniBroadcast()->addAssistant($params);
}
$params = [
'roomId' => $roomId,
'users' => $data
];
MiniProgramService::create()->miniBroadcast()->addAssistant($params);
}
public function pushMessage(int $id)

View File

@ -23,6 +23,7 @@ use app\common\repositories\store\StoreCategoryRepository;
use app\common\repositories\system\merchant\MerchantCategoryRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use app\common\repositories\system\merchant\MerchantTypeRepository;
use app\common\repositories\user\UserRepository;
use FormBuilder\Exception\FormBuilderException;
use FormBuilder\Factory\Elm;
use FormBuilder\Form;
@ -54,6 +55,19 @@ class StoreCouponRepository extends BaseRepository
//平台跨店券
const TYPE_PLATFORM_STORE = 12;
//获取方式
const GET_COUPON_TYPE_RECEIVE = 0;
//消费满赠
const GET_COUPON_TYPE_PAY_MEET = 1;
//新人券
const GET_COUPON_TYPE_NEW = 2;
//买赠
const GET_COUPON_TYPE_PAY = 3;
//首单赠送
const GET_COUPON_TYPE_FIRST = 4;
//会员券
const GET_COUPON_TYPE_SVIP = 5;
/**
* @var StoreCouponDao
*/
@ -103,6 +117,15 @@ class StoreCouponRepository extends BaseRepository
}
return compact('count', 'list');
}
public function sviplist(array $where,$uid)
{
$with = [];
if ($uid) $with['svipIssue'] = function ($query) use ($uid) {
$query->where('uid', $uid);
};
$list = $this->validCouponQueryWithMerchant($where, $uid)->with($with)->setOption('field',[])->field('C.*')->select();
return $list;
}
public function apiList(array $where, int $page, int $limit, $uid)
{
@ -261,11 +284,23 @@ class StoreCouponRepository extends BaseRepository
$coupon = $this->dao->validCoupon($id, $uid);
if (!$coupon)
throw new ValidateException('优惠券失效');
if (!is_null($coupon['issue']))
throw new ValidateException('优惠券已领取');
$this->sendCoupon($coupon, $uid,StoreCouponUserRepository::SEND_TYPE_RECEIVE);
}
public function receiveSvipCounpon($id,$uid)
{
$coupon = $this->dao->validSvipCoupon($id, $uid);
if (!$coupon)
throw new ValidateException('优惠券失效');
if (!is_null($coupon['svipIssue']))
throw new ValidateException('优惠券已领取');
$this->sendCoupon($coupon, $uid,StoreCouponUserRepository::SEND_TYPE_RECEIVE);
}
public function sendCoupon(StoreCoupon $coupon, $uid, $type)
{
event('user.coupon.send.before', compact('coupon', 'uid', 'type'));
@ -346,12 +381,12 @@ class StoreCouponRepository extends BaseRepository
Elm::input('title', '优惠券名称')->required(),
Elm::radio('type', '优惠券类型', 10)
->setOptions([
['value' => 10, 'label' => '通用券'],
['value' => 11, 'label' => '品类券'],
['value' => 12, 'label' => '跨店券'],
['value' => self::TYPE_PLATFORM_ALL, 'label' => '通用券'],
['value' => self::TYPE_PLATFORM_CATE, 'label' => '品类券'],
['value' => self::TYPE_PLATFORM_STORE, 'label' => '跨店券'],
])->control([
[
'value' => 11,
'value' => self::TYPE_PLATFORM_CATE,
'rule' => [
Elm::cascader('cate_ids', '选择品类')->options(function (){
return app()->make(StoreCategoryRepository::class)->getTreeList(0, 1);
@ -359,7 +394,7 @@ class StoreCouponRepository extends BaseRepository
]
],
[
'value' => 12,
'value' => self::TYPE_PLATFORM_STORE,
'rule' => [
Elm::radio('mer_type', '选择商户',2)
->setOptions([
@ -412,31 +447,71 @@ class StoreCouponRepository extends BaseRepository
])->appendControl(1, [
Elm::number('use_min_price', '优惠券最低消费')->min(0)->required(),
]),
Elm::radio('coupon_type', '使用有效期', 0)
->setOptions([
['value' => 0, 'label' => '天数'],
['value' => 1, 'label' => '时间段'],
])->control([
[
'value' => 0,
'rule' => [
Elm::number('coupon_time', ' ', 0)->min(0)->required(),
]
],
[
'value' => 1,
'rule' => [
Elm::dateTimeRange('use_start_time', ' ')->required(),
]
],
]),
Elm::radio('is_timeout', '领取时间', 0)->options([['label' => '限时', 'value' => 1], ['label' => '不限时', 'value' => 0]])
->appendControl(1, [Elm::dateTimeRange('range_date', ' ')->placeholder('不填为永久有效')]),
Elm::radio('send_type', '获取方式', 0)->setOptions([
['value' => 0, 'label' => '领取'],
['value' => 2, 'label' => '新人券'],
// ['value' => 3, 'label' => '赠送券'],
])->appendControl(1, [Elm::number('full_reduction', '满赠金额', 0)->min(0)->placeholder('赠送优惠券的最低消费金额')]),
['value' => self::GET_COUPON_TYPE_RECEIVE, 'label' => '领取'],
['value' => self::GET_COUPON_TYPE_NEW, 'label' => '新人券'],
['value' => self::GET_COUPON_TYPE_SVIP, 'label' => '付费会员券'],
])->control([
[
'value' => self::GET_COUPON_TYPE_RECEIVE,
'rule' => [
Elm::radio('coupon_type', '使用有效期', 0)
->setOptions([
['value' => 0, 'label' => '天数'],
['value' => 1, 'label' => '时间段'],
])->control([
[
'value' => 0,
'rule' => [
Elm::number('coupon_time', ' ', 0)->min(0)->required(),
]
],
[
'value' => 1,
'rule' => [
Elm::dateTimeRange('use_start_time', ' ')->required(),
]
],
]),
Elm::radio('is_timeout', '领取时间', 0)->options([['label' => '限时', 'value' => 1], ['label' => '不限时', 'value' => 0]])
->appendControl(1, [Elm::dateTimeRange('range_date', ' ')->placeholder('不填为永久有效')]),
]
],
[
'value' => self::GET_COUPON_TYPE_NEW,
'rule' => [
Elm::radio('coupon_type', '使用有效期', 0)
->setOptions([
['value' => 0, 'label' => '天数'],
['value' => 1, 'label' => '时间段'],
])->control([
[
'value' => 0,
'rule' => [
Elm::number('coupon_time', ' ', 0)->min(0)->required(),
]
],
[
'value' => 1,
'rule' => [
Elm::dateTimeRange('use_start_time', ' ')->required(),
]
],
]),
Elm::radio('is_timeout', '领取时间', 0)->options([['label' => '限时', 'value' => 1], ['label' => '不限时', 'value' => 0]])
->appendControl(1, [Elm::dateTimeRange('range_date', ' ')->placeholder('不填为永久有效')]),
]
],
])->appendControl(1, [
Elm::number('full_reduction', '满赠金额', 0)->min(0)->placeholder('赠送优惠券的最低消费金额')
])->appendRule('suffix', [
'type' => 'div',
'style' => ['color' => '#999999'],
'domProps' => [
'innerHTML' =>'会员优惠券创建成功后会自动发送给创建时间之后的新付费会员之后每月1日零点自动发送给所有付费会员在创建优惠券之前已成为付费会员的用户可在会员中心手动领取优惠券',
]
]),
Elm::radio('is_limited', '是否限量', 0)->options([['label' => '限量', 'value' => 1], ['label' => '不限量', 'value' => 0]])
->appendControl(1, [Elm::number('total_count', '发布数量', 0)->min(0)]),
Elm::number('sort', '排序', 0)->precision(0)->max(99999),
@ -562,4 +637,23 @@ class StoreCouponRepository extends BaseRepository
}
return compact('count', 'list');
}
public function sendSvipCoupon()
{
$data = ['mark' => [], 'is_all'=> '', 'search' => '',];
$uids = app()->make(UserRepository::class)->search(['is_svip' => 1])->column('uid');
$isMake = app()->make(StoreCouponIssueUserRepository::class);
$senMake = app()->make(StoreCouponSendRepository::class);
$couponIds = $this->dao->validCouponQuery(null,StoreCouponRepository::GET_COUPON_TYPE_SVIP)->column('coupon_id');
if ($couponIds && $uids) {
foreach ($couponIds as $item) {
$issUids = $isMake->getSearch([])->whereMonth('create_time')->whereIn('uid',$uids)->column('uid');
$uids_ = array_values(array_diff($uids,$issUids));
$data['coupon_id'] = $item;
$data['uid'] = $uids_;
if (!empty($data['uid'])) return $senMake->create($data,0);
}
}
}
}

View File

@ -82,7 +82,6 @@ class StoreCouponSendRepository extends BaseRepository
return Db::transaction(function () use ($uid, $merId, $data, $coupon, $uTotal) {
$search = $data['mark'];
if($coupon['is_limited']){
$coupon->remain_count -= $uTotal;
}
@ -97,7 +96,6 @@ class StoreCouponSendRepository extends BaseRepository
]
]);
$coupon->save();
Cache::store('file')->set('_send_coupon' . $send->coupon_send_id, $uid);
Queue::push(MerchantSendCouponJob::class, $send->coupon_send_id);
return $send;

View File

@ -69,7 +69,7 @@ class StoreCouponUserRepository extends BaseRepository
$query = $this->dao->search($where);
$count = $query->count();
$list = $query->with(['coupon' => function ($query) {
$query->field('coupon_id,type');
$query->field('coupon_id,type,send_type');
}, 'merchant' => function ($query) {
$query->field('mer_id,mer_name,mer_avatar');
}])->page($page, $limit)->select();

View File

@ -45,21 +45,21 @@ class StoreCartRepository extends BaseRepository
* @return array
* @author Qinii
*/
public function getList($uid)
public function getList($user)
{
$res = $this->dao->getAll($uid)->append(['checkCartProduct', 'UserPayCount', 'ActiveSku', 'attrValue', 'attr']);
$res = $this->dao->getAll($user->uid)->append(['checkCartProduct', 'UserPayCount', 'ActiveSku', 'attrValue', 'attr','spu']);
$make = app()->make(ProductRepository::class);
$res->map(function ($item) use ($make) {
$item['attr'] = $make->detailAttr($item['attr']);
});
return $this->checkCartList($res, $uid);
return $this->checkCartList($res, $user->uid, $user);
}
public function checkCartList($res, $hasCoupon = 0)
public function checkCartList($res, $hasCoupon = 0, $user = null)
{
$arr = $fail = [];
$product_make = app()->make(ProductRepository::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']);
@ -77,6 +77,13 @@ class StoreCartRepository extends BaseRepository
$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;
}
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;
}
}

View File

@ -16,6 +16,7 @@ namespace app\common\repositories\store\order;
use app\common\dao\store\order\StoreGroupOrderDao;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\coupon\StoreCouponRepository;
use app\common\repositories\store\coupon\StoreCouponUserRepository;
use app\common\repositories\user\UserBillRepository;
use app\common\repositories\user\UserRepository;
@ -157,4 +158,16 @@ class StoreGroupOrderRepository extends BaseRepository
});
Queue::push(CancelGroupOrderJob::class, $id);
}
public function isVipCoupon($groupOrder)
{
if (!$groupOrder->coupon_id) {
return false;
}
$cid = app()->make(StoreCouponUserRepository::class)->query(['coupon_user_id' => $groupOrder->coupon_id])->value('coupon_id');
if ($cid) {
return app()->make(StoreCouponRepository::class)->query(['coupon_id' => $cid])->value('send_type') === StoreCouponRepository::GET_COUPON_TYPE_SVIP;
}
return false;
}
}

View File

@ -12,13 +12,14 @@ use app\common\repositories\store\product\ProductRepository;
use app\common\repositories\store\product\StoreDiscountRepository;
use app\common\repositories\store\StoreCategoryRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use app\common\repositories\user\MemberinterestsRepository;
use app\common\repositories\user\UserAddressRepository;
use app\common\repositories\user\UserBillRepository;
use app\common\repositories\user\UserMerchantRepository;
use app\common\repositories\user\UserRepository;
use app\validate\api\OrderVirtualFieldValidate;
use app\validate\api\UserAddressValidate;
use crmeb\jobs\SendTemplateMessageJob;
use crmeb\jobs\SendSmsJob;
use crmeb\services\SwooleTaskService;
use think\exception\ValidateException;
use think\facade\Db;
@ -41,20 +42,22 @@ class StoreOrderCreateRepository extends StoreOrderRepository
}
$storeCartRepository = app()->make(StoreCartRepository::class);
$res = $storeCartRepository->checkCartList($storeCartRepository->cartIbByData($cartId, $uid, $address));
$res = $storeCartRepository->checkCartList($storeCartRepository->cartIbByData($cartId, $uid, $address), 0, $user);
$merchantCartList = $res['list'];
$fail = $res['fail'];
//检查购物车失效数据
if (count($fail)) {
if ($fail[0]['is_fail'])
throw new ValidateException('[已失效]' . $fail[0]['product']['store_name']);
throw new ValidateException('[已失效]' . mb_substr($fail[0]['product']['store_name'],0,10).'...');
if (in_array($fail[0]['product_type'], [1, 2, 3]) && !$fail[0]['userPayCount']) {
throw new ValidateException('[超出限购数]' . $fail[0]['product']['store_name']);
throw new ValidateException('[超出限购数]' . mb_substr($fail[0]['product']['store_name'],0,10).'...');
}
throw new ValidateException('[已失效]' . $fail[0]['product']['store_name']);
throw new ValidateException('[已失效]' . mb_substr($fail[0]['product']['store_name'],0,10).'...');
}
$svip_status = $user->is_svip > 0 && systemConfig('svip_switch_status') == '1';
$svip_integral_rate = $svip_status ? app()->make(MemberinterestsRepository::class)->getSvipInterestVal(MemberinterestsRepository::HAS_TYPE_PAY) : 0;
//订单活动类型
$order_type = 0;
//虚拟订单
@ -66,15 +69,15 @@ class StoreOrderCreateRepository extends StoreOrderRepository
foreach ($merchantCart['list'] as $cart) {
if ($cart['product_type']==0) {
if ($cart['product']['once_min_count'] > 0 && $cart['product']['once_min_count'] > $cart['cart_num'])
throw new ValidateException('[低于起购数:'.$cart['product']['once_min_count'].']'.$cart['product']['store_name']);
throw new ValidateException('[低于起购数:'.$cart['product']['once_min_count'].']'.mb_substr($cart['product']['store_name'],0,10).'...');
if ($cart['product']['pay_limit'] == 1 && $cart['product']['once_max_count'] < $cart['cart_num'])
throw new ValidateException('[超出单次限购数:'.$cart['product']['once_max_count'].']'.$cart['product']['store_name']);
throw new ValidateException('[超出单次限购数:'.$cart['product']['once_max_count'].']'.mb_substr($cart['product']['store_name'],0,10).'...');
if ($cart['product']['pay_limit'] == 2){
//如果长期限购
//已购买数量
$count = app()->make(StoreOrderRepository::class)->getMaxCountNumber($cart['uid'],$cart['product_id']);
if (($cart['cart_num'] + $count) > $cart['product']['once_max_count'])
throw new ValidateException('[超出限购总数:'. $cart['product']['once_max_count'].']'.$cart['product']['store_name']);
throw new ValidateException('[超出限购总数:'. $cart['product']['once_max_count'].']'.mb_substr($cart['product']['store_name'],0,10).'...');
}
}
@ -111,6 +114,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
}
$orderDeliveryStatus = true;
$order_svip_discount = 0;
// 循环计算每个店铺的订单数据
foreach ($merchantCartList as &$merchantCart) {
$postageRule = [];
@ -121,6 +125,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$product_price = [];
$final_price = 0;
$down_price = 0;
$total_svip_discount = 0;
//是否自提
$isTake = in_array($merchantCart['mer_id'], $takes ?? []);
@ -198,7 +203,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository
if (!$enabledCoupon) {
$merchantCart['coupon'] = [];
}
$svip_coupon_merge = merchantConfig($merchantCart['mer_id'], 'svip_coupon_merge');
$use_svip = 0;
//获取运费规则和统计商品数据
foreach ($merchantCart['list'] as &$cart) {
@ -209,7 +215,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
if ($cart['cart_num'] <= 0) {
throw new ValidateException('购买商品数必须大于0');
}
$svip_discount = 0;
$price = bcmul($cart['cart_num'], $this->cartByPrice($cart), 2);
$cart['total_price'] = $price;
@ -217,6 +223,15 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$total_price = bcadd($total_price, $price, 2);
$total_num += $cart['cart_num'];
$_price = bcmul($cart['cart_num'], $this->cartByCouponPrice($cart), 2);
$cart['svip_coupon_merge'] = 1;
if ($cart['productAttr']['show_svip_price']) {
$svip_discount = max(bcmul($cart['cart_num'], bcsub($cart['productAttr']['org_price'] ?? 0, $cart['productAttr']['price'], 2), 2), 0);
if ($svip_coupon_merge != '1') {
$_price = 0;
$cart['svip_coupon_merge'] = 0;
}
$use_svip = 1;
}
$valid_total_price = bcadd($valid_total_price, $_price, 2);
$cart['allow_price'] = $_price;
$temp1 = $cart['product']['temp'];
@ -299,6 +314,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$postageRule[$tempId]['region'] = $regionRule;
}
unset($cart);
$total_svip_discount = bcadd($total_svip_discount, $svip_discount, 2);
if (!$isTake) {
//计算运费
@ -340,6 +356,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$merCouponIds = array_reverse($merCouponIds);
$sortIds = $merCouponIds;
// $all_coupon_product = [];
unset($defaultSort);
$defaultSort = [];
if (count($merCouponIds)) {
foreach ($merchantCart['coupon'] as &$item) {
@ -365,6 +382,10 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$coupon['disabled'] = true;
continue;
}
if($svip_coupon_merge != '1' && $use_svip){
$coupon['disabled'] = true;
continue;
}
$flag = false;
foreach ($coupon['product'] as $_product) {
if (isset($product_price[$_product['product_id']]) && $product_price[$_product['product_id']] >= $coupon['use_min_price']) {
@ -416,6 +437,10 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$coupon['checked'] = false;
$coupon['disabled'] = $pay_price <= 0;
if ($use_store_coupon || $pay_price <= 0) continue;
if($svip_coupon_merge != '1' && $use_svip){
$coupon['disabled'] = true;
continue;
}
//店铺券
if ($valid_total_price >= $coupon['use_min_price']) {
if ($useCouponFlag) {
@ -496,6 +521,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
//单个商品实际支付金额
$cart['coupon_price'] = bcsub($_cartTotalPrice, $cartTotalPrice, 2);
$cart['true_price'] = $cartTotalPrice;
$cart['svip_discount'] = $svip_discount;
}
unset($cart, $_k);
$total_true_price = bcadd($_pay_price, $total_true_price, 2);
@ -508,6 +534,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
'final_price' => $final_price,
'down_price' => $down_price,
'coupon_price' => $coupon_price,
'svip_coupon_merge' => $svip_coupon_merge,
'postage_price' => $postage_price,
'isTake' => $isTake,
'total_num' => $total_num,
@ -516,8 +543,11 @@ class StoreOrderCreateRepository extends StoreOrderRepository
'allow_take' => $merTake,
'allow_delivery' => $merDelivery,
'delivery_status' => $deliveryStatus,
'svip_discount' => $total_svip_discount,
'use_svip' => $use_svip,
];
$order_total_postage = bcadd($order_total_postage, $postage_price, 2);
$order_svip_discount = bcadd($total_svip_discount, $order_svip_discount, 2);
if (count($defaultSort)) {
$merchantCart['coupon'] = &$defaultSort;
}
@ -528,6 +558,25 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$usePlatformCouponId = is_array($usePlatformCouponId) ? array_pop($usePlatformCouponId) : $usePlatformCouponId;
$usePlatformCouponFlag = isset($useCoupon[0]);
foreach ($merchantCartList as &$merchantCart) {
if (!$merchantCart['order']['use_svip'])
continue;
$totalMergePrice = 0;
foreach ($merchantCart['list'] as &$cart) {
if (!$cart['svip_coupon_merge']) {
$totalMergePrice = bcadd($totalMergePrice, $cart['true_price'], 2);
$cart['allow_price'] = $cart['true_price'];
}
}
unset($cart);
if ($totalMergePrice > 0) {
$total_true_price = bcadd($total_true_price, $totalMergePrice, 2);
$merchantCart['order']['valid_total_price'] = bcadd($merchantCart['order']['valid_total_price'], $totalMergePrice, 2);
$merchantCart['order']['true_price'] = $merchantCart['order']['valid_total_price'];
}
}
unset($merchantCart);
//计算平台券优惠金额
// if ($total_true_price > 0) {
$StoreCouponUser = app()->make(StoreCouponUserRepository::class);
@ -577,6 +626,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
}
];
$coupon['checked'] = true;
$flag = true;
}
//品类券
} else if ($coupon['coupon']['type'] === StoreCouponRepository::TYPE_PLATFORM_CATE) {
@ -584,17 +634,17 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$_use_count = 0;
$cateIds = $coupon['product']->column('product_id');
$allCateIds = array_unique(array_merge(app()->make(StoreCategoryRepository::class)->allChildren($cateIds), $cateIds));
$flag = true;
$flag2 = true;
foreach ($allCateIds as $cateId) {
if (isset($catePriceLst[$cateId])) {
$_price = bcadd($catePriceLst[$cateId]['price'], $_price, 2);
$_use_count += count($catePriceLst[$cateId]['cart']);
$flag = false;
$flag2 = false;
}
}
$coupon['disabled'] = $flag || $coupon['use_min_price'] > $_price;
$coupon['disabled'] = $flag2 || $coupon['use_min_price'] > $_price;
//品类券可用
if (!$platformCouponRate && !$coupon['disabled'] && !$flag && ((!$usePlatformCouponId && !$usePlatformCouponFlag) || $usePlatformCouponId == $coupon['coupon_user_id'])) {
if (!$platformCouponRate && !$coupon['disabled'] && !$flag && !$flag2 && ((!$usePlatformCouponId && !$usePlatformCouponFlag) || $usePlatformCouponId == $coupon['coupon_user_id'])) {
$platformCouponRate = [
'id' => $coupon['coupon_user_id'],
'type' => $coupon['coupon']['type'],
@ -613,18 +663,18 @@ class StoreOrderCreateRepository extends StoreOrderRepository
} else if ($coupon['coupon']['type'] === StoreCouponRepository::TYPE_PLATFORM_STORE) {
$_price = 0;
$_use_count = 0;
$flag = true;
$flag2 = true;
foreach ($coupon['product'] as $item) {
$merId = $item['product_id'];
if (isset($storePriceLst[$merId])) {
$_price = bcadd($storePriceLst[$merId]['price'], $_price, 2);
$_use_count += $storePriceLst[$merId]['num'];
$flag = false;
$flag2 = false;
}
}
$coupon['disabled'] = $flag || $coupon['use_min_price'] > $_price;
$coupon['disabled'] = $flag2 || $coupon['use_min_price'] > $_price;
//店铺券可用
if (!$platformCouponRate && !$coupon['disabled'] && !$flag && ((!$usePlatformCouponId && !$usePlatformCouponFlag) || $usePlatformCouponId == $coupon['coupon_user_id'])) {
if (!$platformCouponRate && !$coupon['disabled'] && !$flag && !$flag2 && ((!$usePlatformCouponId && !$usePlatformCouponFlag) || $usePlatformCouponId == $coupon['coupon_user_id'])) {
$_merIds = $coupon['product']->column('product_id');
$platformCouponRate = [
'id' => $coupon['coupon_user_id'],
@ -650,6 +700,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$total_platform_coupon_price = 0;
//计算平台优惠券
if (isset($platformCouponRate)) {
$_coupon_price = $platformCouponRate['coupon_price'];
foreach ($merchantCartList as &$merchantCart) {
$_price = 0;
foreach ($merchantCart['list'] as &$cart) {
@ -658,7 +709,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
if ($platformCouponRate['use_count'] === 1) {
$couponPrice = min($platformCouponRate['coupon_price'], $cart['true_price']);
} else {
$couponPrice = min(bcmul($platformCouponRate['coupon_price'], bcdiv($cart['true_price'], $platformCouponRate['price'], 3), 2), $cart['true_price']);
$couponPrice = min(bcmul($_coupon_price, bcdiv($cart['true_price'], $platformCouponRate['price'], 3), 2), $cart['true_price']);
}
$platformCouponRate['coupon_price'] = bcsub($platformCouponRate['coupon_price'], $couponPrice, 2);
$cart['true_price'] = bcsub($cart['true_price'], $couponPrice, 2);
@ -776,6 +827,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository
//计算赠送积分, 只有普通商品赠送积分
if ($giveIntegralFlag && !$order_type && $pay_price > 0) {
$total_give_integral = floor(bcmul($pay_price, $sysIntegralConfig['integral_order_rate'], 0));
if ($total_give_integral > 0 && $svip_status && $svip_integral_rate > 0) {
$total_give_integral = bcmul($svip_integral_rate, $total_give_integral, 0);
}
}
$order_total_give_integral = bcadd($total_give_integral, $order_total_give_integral, 0);
@ -800,11 +854,21 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$allow_no_address = false;
}
foreach ($merchantCartList as &$merchantCart) {
foreach ($merchantCart['list'] as &$cart) {
$cart['total_price'] = bcadd($cart['total_price'], $cart['svip_discount'], 2);
}
unset($cart);
$merchantCart['order']['total_price'] = bcadd($merchantCart['order']['total_price'], $merchantCart['order']['svip_discount'], 2);
$order_total_price = bcadd($order_total_price, $merchantCart['order']['svip_discount'], 2);
}
unset($merchantCart);
$status = ($address || $order_model || $allow_no_address) ? ($noDeliver ? 'noDeliver' : 'finish') : 'noAddress';
$order = $merchantCartList;
$total_price = $order_total_price;
$openIntegral = $merIntegralFlag && !$order_type && $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_money'] > 0;
$total_coupon = bcadd(bcadd($total_platform_coupon_price, $order_coupon_price, 2), $order_total_integral_price, 2);
$total_coupon = bcadd($order_svip_discount, bcadd(bcadd($total_platform_coupon_price, $order_coupon_price, 2), $order_total_integral_price, 2), 2);
return compact(
'order_type',
'order_model',
@ -818,6 +882,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
'order_total_integral',
'order_total_integral_price',
'order_total_give_integral',
'order_svip_discount',
'total_platform_coupon_price',
'total_coupon',
'order_coupon_price',
@ -1011,6 +1076,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
'total_price' => $merchantCart['order']['total_price'],
'total_postage' => $merchantCart['order']['postage_price'],
'pay_postage' => $merchantCart['order']['postage_price'],
'svip_discount' => $merchantCart['order']['svip_discount'],
'pay_price' => $merchantCart['order']['pay_price'],
'integral' => $merchantCart['order']['total_integral'],
'integral_price' => $merchantCart['order']['total_integral_price'],
@ -1237,6 +1303,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
'extension_one' => $extension_one,
'extension_two' => $extension_two,
'postage_price' => $cart['postage_price'],
'svip_discount' => $cart['svip_discount'],
'cost' => $cart['cost'],
'coupon_price' => $cart['coupon_price'],
'platform_coupon_price' => $cart['platform_coupon_price'],
@ -1277,7 +1344,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
}
}
}
Queue::push(SendTemplateMessageJob::class, ['tempCode' => 'ORDER_CREATE', 'id' => $group->group_order_id]);
Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_CREATE', 'id' => $group->group_order_id]);
return $group;
}
}

View File

@ -19,13 +19,9 @@ use app\common\repositories\BaseRepository;
use app\common\repositories\delivery\DeliveryOrderRepository;
use app\common\repositories\store\coupon\StoreCouponRepository;
use app\common\repositories\store\coupon\StoreCouponUserRepository;
use app\common\repositories\store\MerchantTakeRepository;
use app\common\repositories\store\product\ProductAssistSetRepository;
use app\common\repositories\store\product\ProductAssistSkuRepository;
use app\common\repositories\store\product\ProductAttrValueRepository;
use app\common\repositories\store\product\ProductCopyRepository;
use app\common\repositories\store\product\ProductGroupBuyingRepository;
use app\common\repositories\store\product\ProductGroupSkuRepository;
use app\common\repositories\store\product\ProductPresellSkuRepository;
use app\common\repositories\store\product\ProductRepository;
use app\common\repositories\store\product\StoreDiscountRepository;
@ -36,15 +32,12 @@ use app\common\repositories\system\attachment\AttachmentRepository;
use app\common\repositories\system\merchant\FinancialRecordRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use app\common\repositories\system\serve\ServeDumpRepository;
use app\common\repositories\user\UserAddressRepository;
use app\common\repositories\user\UserBillRepository;
use app\common\repositories\user\UserBrokerageRepository;
use app\common\repositories\user\UserMerchantRepository;
use app\common\repositories\user\UserRepository;
use app\validate\api\OrderVirtualFieldValidate;
use crmeb\jobs\PayGiveCouponJob;
use crmeb\jobs\SendSmsJob;
use crmeb\jobs\SendTemplateMessageJob;
use crmeb\jobs\UserBrokerageLevelJob;
use crmeb\services\CombinePayService;
use crmeb\services\CrmebServeServices;
@ -157,7 +150,7 @@ class StoreOrderRepository extends BaseRepository
$order->pay_type = $pay_type;
$order->save();
}
$order->save();
$groupOrder->save();
});
}
@ -202,9 +195,12 @@ class StoreOrderRepository extends BaseRepository
$storeOrderProfitsharingRepository = app()->make(StoreOrderProfitsharingRepository::class);
$uid = $groupOrder->uid;
$i = 1;
$isVipCoupon = app()->make(StoreGroupOrderRepository::class)->isVipCoupon($groupOrder);
$svipDiscount = 0;
foreach ($groupOrder->orderList as $_k => $order) {
$order->paid = 1;
$order->pay_time = $time;
$svipDiscount = bcadd($order->svip_discount, $svipDiscount, 2);
if (isset($subOrders[$order->order_sn])) {
$order->transaction_id = $subOrders[$order->order_sn]['transaction_id'];
}
@ -349,7 +345,7 @@ class StoreOrderRepository extends BaseRepository
'order_sn' => $order->order_sn,
'user_info' => $groupOrder->user->nickname,
'user_id' => $uid,
'financial_type' => 'order_platform_coupon',
'financial_type' => $isVipCoupon ? 'order_svip_coupon' : 'order_platform_coupon',
'financial_pm' => 0,
'type' => 1,
'number' => $order->platform_coupon_price,
@ -393,6 +389,7 @@ class StoreOrderRepository extends BaseRepository
app()->make(UserRepository::class)->update($groupOrder->uid, [
'pay_count' => Db::raw('pay_count+' . count($groupOrder->orderList)),
'pay_price' => Db::raw('pay_price+' . $groupOrder->pay_price),
'svip_save_money' => Db::raw('svip_save_money+' . $svipDiscount),
]);
$this->giveIntegral($groupOrder);
if (count($profitsharing)) {
@ -412,19 +409,8 @@ class StoreOrderRepository extends BaseRepository
}
}
Queue::push(SendTemplateMessageJob::class, [
'tempCode' => 'ORDER_PAY_SUCCESS',
'id' => $groupOrder->group_order_id
]);
Queue::push(SendSmsJob::class, [
'tempId' => 'ORDER_PAY_SUCCESS',
'id' => $groupOrder->group_order_id
]);
Queue::push(SendSmsJob::class, [
'tempId' => 'ADMIN_PAY_SUCCESS_CODE',
'id' => $groupOrder->group_order_id
]);
Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_PAY_SUCCESS', 'id' => $groupOrder->group_order_id]);
Queue::push(SendSmsJob::class, ['tempId' => 'ADMIN_PAY_SUCCESS_CODE', 'id' => $groupOrder->group_order_id]);
Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->uid, 'type' => 'pay_money', 'inc' => $groupOrder->pay_price]);
Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->uid, 'type' => 'pay_num', 'inc' => 1]);
app()->make(UserBrokerageRepository::class)->incMemberValue($groupOrder->uid, 'member_pay_num', $groupOrder->group_order_id);
@ -554,9 +540,15 @@ class StoreOrderRepository extends BaseRepository
public function getDetail($id, $uid = null)
{
$where = [];
$with = ['orderProduct', 'merchant' => function ($query) {
return $query->field('mer_id,mer_name,service_phone')->append(['services_type']);
}];
$with = [
'orderProduct',
'merchant' => function ($query) {
return $query->field('mer_id,mer_name,service_phone')->append(['services_type']);
},
'receipt' => function ($query) {
return $query->field('order_id,order_receipt_id');
}
];
if ($uid) {
$where['uid'] = $uid;
} else if (!$uid) {
@ -583,9 +575,18 @@ class StoreOrderRepository extends BaseRepository
{
$where = [];
if ($uid) $where['uid'] = $uid;
return $this->dao->search($where)->where('verify_code', $code)->where('StoreOrder.is_del', 0)->with(['orderProduct', 'merchant' => function ($query) {
return $query->field('mer_id,mer_name');
}])->find();
$data = $this->dao->search($where)->where('verify_code', $code)
->where('StoreOrder.is_del', 0)
->with([
'orderProduct',
'merchant' => function ($query) {
return $query->field('mer_id,mer_name');
}
])
->find();
if ($data['status'])
throw new ValidateException('该订单已全部核销');
return $data;
}
public function giveIntegral($groupOrder)
@ -677,19 +678,10 @@ class StoreOrderRepository extends BaseRepository
$this->computed($order, $user);
//TODO 确认收货
$statusRepository = app()->make(StoreOrderStatusRepository::class);
$statusRepository->status($order->order_id, $statusRepository::ORDER_STATUS_TAKE, '已收货');
Queue::push(SendTemplateMessageJob::class, [
'tempCode' => 'ORDER_TAKE_SUCCESS',
'id' => $order->order_id
]);
Queue::push(SendSmsJob::class, [
'tempId' => 'ORDER_TAKE_SUCCESS',
'id' => $order->order_id
]);
Queue::push(SendSmsJob::class, [
'tempId' => 'ADMIN_TAKE_DELIVERY_CODE',
'id' => $order->order_id
]);
$statusRepository->status($order->order_id, $statusRepository::ORDER_STATUS_TAKE, $order->order_type == 1 ? '已核销' :'已收货');
Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_TAKE_SUCCESS', 'id' => $order->order_id]);
Queue::push(SendSmsJob::class, ['tempId' => 'ADMIN_TAKE_DELIVERY_CODE', 'id' => $order->order_id]);
app()->make(MerchantRepository::class)->computedLockMoney($order);
$order->save();
});
@ -811,6 +803,7 @@ class StoreOrderRepository extends BaseRepository
break; // 已退款
case 7:
$param['StoreOrder.is_del'] = 1;
break; // 待核销
break; // 已删除
default:
unset($param['StoreOrder.is_del']);
@ -1189,7 +1182,11 @@ class StoreOrderRepository extends BaseRepository
}
$order = $this->dao->get($id);
$newOrder = app()->make(StoreOrderSplitRepository::class)->splitOrder($order, $splitData);
if ($newOrder) $id = $newOrder->order_id;
if ($newOrder){
$id = $newOrder->order_id;
} else {
throw new ValidateException('商品不能全部拆单');
}
}
return $this->{$method}($id, $merId, $data);
});
@ -1210,36 +1207,36 @@ class StoreOrderRepository extends BaseRepository
if ($order['is_virtual'] && $data['delivery_type'] != 3)
throw new ValidateException('虚拟商品只能虚拟发货');
$statusRepository = app()->make(StoreOrderStatusRepository::class);
if ($data['delivery_type'] == 1) {
$exprss = app()->make(ExpressRepository::class)->getWhere(['code' => $data['delivery_name']]);
if (!$exprss) throw new ValidateException('快递公司不存在');
$data['delivery_name'] = $exprss['name'];
$change_type = $statusRepository::ORDER_DELIVERY_COURIER;
$change_message = '订单已配送【快递名称】:' . $exprss['name'] . '; 【快递单号】:' . $data['delivery_id'];
$temp_code = 'ORDER_POSTAGE_SUCCESS';
switch ($data['delivery_type']) {
case 1:
$exprss = app()->make(ExpressRepository::class)->getWhere(['code' => $data['delivery_name']]);
if (!$exprss) throw new ValidateException('快递公司不存在');
$data['delivery_name'] = $exprss['name'];
$change_type = $statusRepository::ORDER_DELIVERY_COURIER;
$change_message = '订单已配送【快递名称】:' . $exprss['name'] . '; 【快递单号】:' . $data['delivery_id'];
$temp_code = 'DELIVER_GOODS_CODE';
break;
case 2:
if (!preg_match("/^1[3456789]{1}\d{9}$/", $data['delivery_id'])) throw new ValidateException('手机号格式错误');
$change_type = 'delivery_1';
$change_message = '订单已配送【送货人姓名】:' . $data['delivery_name'] . '; 【手机号】:' . $data['delivery_id'];
$temp_code = 'ORDER_DELIVER_SUCCESS';
break;
case 3:
$change_type = $statusRepository::ORDER_DELIVERY_NOTHING;
$change_message = '订单已配送【虚拟发货】';
$data['status'] = 2;
break;
case 4:
$exprss = app()->make(ExpressRepository::class)->getWhere(['code' => $data['delivery_name']]);
if (!$exprss) throw new ValidateException('快递公司不存在');
$data['delivery_name'] = $exprss['name'];
$change_type = $statusRepository::ORDER_DELIVERY_COURIER;
$change_message = '订单已配送【快递名称】:' . $exprss['name'] . '; 【快递单号】:' . $data['delivery_id'];
$temp_code = 'DELIVER_GOODS_CODE';
break;
}
if ($data['delivery_type'] == 2) {
if (!preg_match("/^1[3456789]{1}\d{9}$/", $data['delivery_id'])) throw new ValidateException('手机号格式错误');
$change_type = 'delivery_1';
$change_message = '订单已配送【送货人姓名】:' . $data['delivery_name'] . '; 【手机号】:' . $data['delivery_id'];
$temp_code = 'DELIVER_GOODS_CODE';
}
if ($data['delivery_type'] == 3) {
$change_type = $statusRepository::ORDER_DELIVERY_NOTHING;
$change_message = '订单已配送【虚拟发货】';
$data['status'] = 2;
}
if ($data['delivery_type'] == 4) {
$exprss = app()->make(ExpressRepository::class)->getWhere(['code' => $data['delivery_name']]);
if (!$exprss) throw new ValidateException('快递公司不存在');
$data['delivery_name'] = $exprss['name'];
$change_type = $statusRepository::ORDER_DELIVERY_COURIER;
$change_message = '订单已配送【快递名称】:' . $exprss['name'] . '; 【快递单号】:' . $data['delivery_id'];
$temp_code = 'ORDER_POSTAGE_SUCCESS';
}
event('order.delivery.before', compact('order', 'data'));
$this->dao->update($id, $data);
@ -1250,9 +1247,8 @@ class StoreOrderRepository extends BaseRepository
}
$statusRepository->status($id, $change_type, $change_message);
Queue::push(SendSmsJob::class, ['tempId' => 'DELIVER_GOODS_CODE', 'id' => $order->order_id]);
if (isset($temp_code)) Queue::push(SendSmsJob::class, ['tempId' => $temp_code, 'id' => $order->order_id]);
if (isset($temp_code)) Queue::push(SendTemplateMessageJob::class, ['tempCode' => $temp_code, 'id' => $order['order_id']]);
event('order.delivery', compact('order', 'data'));
return $data;
}
@ -1274,12 +1270,11 @@ class StoreOrderRepository extends BaseRepository
$make->create($id, $merId, $data, $order);
$this->dao->update($id, ['delivery_type' => 5, 'status' => 1,'remark' => $data['remark']]);
$change_message = '订单已配送【同城配送】';
$temp_code = 'DELIVER_GOODS_CODE';
$statusRepository = app()->make(StoreOrderStatusRepository::class);
$statusRepository->status($id, $statusRepository::ORDER_DELIVERY_CITY, $change_message);
Queue::push(SendTemplateMessageJob::class, ['tempCode' => $temp_code, 'id' => $id]);
$statusRepository = app()->make(StoreOrderStatusRepository::class);
$statusRepository->status($id, $statusRepository::ORDER_DELIVERY_CITY, '订单已配送【同城配送】');
Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_DELIVER_SUCCESS', 'id' => $id]);
}
@ -1293,7 +1288,7 @@ class StoreOrderRepository extends BaseRepository
return $this->dao->getWhere($where, '*', [
'orderProduct',
'user' => function ($query) {
$query->field('uid,real_name,nickname');
$query->field('uid,real_name,nickname,is_svip,svip_endtime,phone');
},
'refundOrder' => function ($query) {
$query->field('order_id,extension_one,extension_two,refund_price,integral')->where('status', 3);
@ -1570,7 +1565,10 @@ class StoreOrderRepository extends BaseRepository
'merchant' => function ($query) {
return $query->field('mer_id,mer_name');
},
'community'
'community',
'receipt' => function ($query) {
return $query->field('order_id,order_receipt_id');
},
])->page($page, $limit)->order('pay_time DESC')->append(['refund_status'])->select();
foreach ($list as $order) {
@ -1704,16 +1702,17 @@ class StoreOrderRepository extends BaseRepository
}
$data = [
'order_sn' => $order['order_sn'],
'pay_time' => $order['pay_time'],
'real_name' => $order['real_name'],
'order_sn' => $order['order_sn'],
'order_type' => $order['order_type'],
'pay_time' => $order['pay_time'],
'real_name' => $order['real_name'],
'user_phone' => $order['user_phone'],
'user_address' => $order['user_address'],
'total_price' => $order['total_price'],
'total_price' => $order['total_price'],
'coupon_price' => $order['coupon_price'],
'pay_price' => $order['pay_price'],
'pay_price' => $order['pay_price'],
'total_postage' => $order['total_postage'],
'pay_postage' => $order['pay_postage'],
'pay_postage' => $order['pay_postage'],
'mark' => $order['mark'],
];
@ -1731,17 +1730,18 @@ class StoreOrderRepository extends BaseRepository
event('order.print', compact('order', 'res'));
}
public function verifyOrder($id, $merId, $serviceId)
public function verifyOrder(int $id, int $merId, array $data, $serviceId = 0)
{
$order = $this->dao->getWhere(['verify_code' => $id, 'mer_id' => $merId]);
if (!$order)
throw new ValidateException('订单不存在');
if ($order->status != 9 && $order->status >= 2)
throw new ValidateException('请勿重复核销~');
if ($order->status != 0 && $order->status != 9)
throw new ValidateException('订单状态有误');
if (!$order->paid)
throw new ValidateException('订单未支付');
$order = $this->dao->getWhere(['order_id' => $id, 'mer_id' => $merId,'verify_code' => $data['verify_code'],'order_type' => 1],'*',['orderProduct']);
if (!$order) throw new ValidateException('订单不存在');
if (!$order->paid) throw new ValidateException('订单未支付');
if ($order['status']) throw new ValidateException('订单已全部核销,请勿重复操作');
foreach ($data['data'] as $v) {
$splitData[$v['id']] = $v['num'];
}
$spl = app()->make(StoreOrderSplitRepository::class)->splitOrder($order, $splitData);
if ($spl) $order = $spl;
$order->status = 2;
$order->verify_time = date('Y-m-d H:i:s');
$order->verify_service_id = $serviceId;
@ -1913,19 +1913,36 @@ class StoreOrderRepository extends BaseRepository
public function orderRefundAllAfter($order)
{
$couponId = [];
if ($order->coupon_id) {
$couponId = explode(',', $order->coupon_id);
}
$statusRepository = app()->make(StoreOrderStatusRepository::class);
$statusRepository->status($order['order_id'], $statusRepository::ORDER_STATUS_REFUND_ALL, '订单已全部退款');
if (count($couponId)) {
app()->make(StoreCouponUserRepository::class)->updates($couponId, ['status' => 0]);
}
if ($order->activity_type == 10) {
app()->make(StoreDiscountRepository::class)->incStock($order->orderProduct[0]['activity_id']);
}
app()->make(MerchantRepository::class)->computedLockMoney($order);
$mainId = $order->main_id ?: $order->order_id;
$count = $this->query([])->where('status', '<>', -1)->where(function ($query) use ($mainId) {
$query->where('order_id', $mainId)->whereOr('main_id', $mainId);
})->count();
//拆单后完全退完
if (!$count) {
if ($order->main_id) {
$order = $this->query(['order_id' => $mainId])->find();
}
$couponId = [];
if ($order->coupon_id) {
$couponId = explode(',', $order->coupon_id);
}
app()->make(MerchantRepository::class)->computedLockMoney($order);
//总单所有订单全部退完
if (!$this->query([])->where('status', '<>', -1)->where('group_order_id', $order->group_order_id)->count()) {
if ($order->groupOrder->coupon_id) {
$couponId[] = $order->groupOrder->coupon_id;
}
}
if (count($couponId)) {
app()->make(StoreCouponUserRepository::class)->updates($couponId, ['status' => 0]);
}
}
event('order.refundAll', compact('order'));
}

View File

@ -13,6 +13,7 @@ namespace app\common\repositories\store\order;
use app\common\dao\store\order\StoreOrderDao;
use app\common\model\store\order\StoreOrder;
use crmeb\services\LockService;
use think\exception\ValidateException;
use think\facade\Db;
@ -26,6 +27,13 @@ use think\facade\Db;
class StoreOrderSplitRepository extends StoreOrderRepository
{
public function splitOrder(StoreOrder $order, array $rule)
{
return app()->make(LockService::class)->exec('order.split.' . $order->order_id, function () use ($rule, $order) {
return $this->execSplitOrder($order, $rule);
});
}
public function execSplitOrder(StoreOrder $order, array $rule)
{
if ($order['status'] != 0) {
throw new ValidateException('订单已发货');
@ -45,6 +53,7 @@ class StoreOrderSplitRepository extends StoreOrderRepository
$newOrder['extension_two'] = 0;
$newOrder['coupon_price'] = 0;
$newOrder['platform_coupon_price'] = 0;
$newOrder['svip_discount'] = 0;
$newOrder['cost'] = 0;
$newOrder['integral_price'] = 0;
$newOrder['integral'] = 0;
@ -75,7 +84,8 @@ class StoreOrderSplitRepository extends StoreOrderRepository
}
if (!$flag) {
throw new ValidateException('商品不能全部拆单');
return $flag;
//throw new ValidateException('商品不能全部拆单');
}
foreach ($order['orderProduct'] as $product) {
@ -98,22 +108,22 @@ class StoreOrderSplitRepository extends StoreOrderRepository
$product['is_refund'] = 3;
}
$newProduct['product_price'] = $product['product_price'] > 0 ? bcmul(bcdiv($product['product_price'], $product['product_num'], 3), $num, 2) : 0;
$newProduct['total_price'] = $product['total_price'] > 0 ? bcmul(bcdiv($product['total_price'], $product['product_num'], 3), $num, 2) : 0;
$newProduct['product_price'] = $product['product_price'] > 0 ? round(bcmul(bcdiv($product['product_price'], $product['product_num'], 3), $num, 3), 2) : 0;
$newProduct['total_price'] = $product['total_price'] > 0 ? round(bcmul(bcdiv($product['total_price'], $product['product_num'], 2), $num, 2), 2) : 0;
$newProduct['extension_one'] = $product['extension_one'];
$newProduct['extension_two'] = $product['extension_two'];
$newProduct['coupon_price'] = $product['coupon_price'] > 0 ? bcmul(bcdiv($product['coupon_price'], $product['product_num'], 3), $num, 2) : 0;
$newProduct['cost'] = $product['cost'] > 0 ? bcmul(bcdiv($product['cost'], $product['product_num'], 3), $num, 2) : 0;
$newProduct['integral_price'] = $product['integral_price'] > 0 ? bcmul(bcdiv($product['integral_price'], $product['product_num'], 3), $num, 2) : 0;
$newProduct['platform_coupon_price'] = $product['platform_coupon_price'] > 0 ? bcmul(bcdiv($product['platform_coupon_price'], $product['product_num'], 3), $num, 2) : 0;
$newProduct['postage_price'] = $product['postage_price'] > 0 ? bcmul(bcdiv($product['postage_price'], $product['product_num'], 3), $num, 2) : 0;
$newProduct['integral_total'] = $product['integral_total'] > 0 ? bcmul(bcdiv($product['integral_total'], $product['integral_total'], 3), $num, 0) : 0;
$newProduct['coupon_price'] = $product['coupon_price'] > 0 ? bcmul(bcdiv($product['coupon_price'], $product['product_num'], 2), $num, 2) : 0;
$newProduct['svip_discount'] = $product['svip_discount'] > 0 ? bcmul(bcdiv($product['svip_discount'], $product['product_num'], 2), $num, 2) : 0;
$newProduct['integral_price'] = $product['integral_price'] > 0 ? bcmul(bcdiv($product['integral_price'], $product['product_num'], 2), $num, 2) : 0;
$newProduct['platform_coupon_price'] = $product['platform_coupon_price'] > 0 ? bcmul(bcdiv($product['platform_coupon_price'], $product['product_num'], 2), $num, 2) : 0;
$newProduct['postage_price'] = $product['postage_price'] > 0 ? bcmul(bcdiv($product['postage_price'], $product['product_num'], 2), $num, 2) : 0;
$newProduct['integral_total'] = $product['integral_total'] > 0 ? floor(bcmul(bcdiv($product['integral_total'], $product['integral_total'], 2), $num, 0)) : 0;
$product['product_price'] = $product['product_price'] > 0 ? bcsub($product['product_price'], $newProduct['product_price'], 2) : 0;
$product['total_price'] = $product['total_price'] > 0 ? bcsub($product['total_price'], $newProduct['total_price'], 2) : 0;
$product['coupon_price'] = $product['coupon_price'] > 0 ? bcsub($product['coupon_price'], $newProduct['coupon_price'], 2) : 0;
$product['svip_discount'] = $product['svip_discount'] > 0 ? bcsub($product['svip_discount'], $newProduct['svip_discount'], 2) : 0;
$product['integral_price'] = $product['integral_price'] > 0 ? bcsub($product['integral_price'], $newProduct['integral_price'], 2) : 0;
$product['cost'] = $product['cost'] > 0 ? bcsub($product['cost'], $newProduct['cost'], 2) : 0;
$product['platform_coupon_price'] = $product['platform_coupon_price'] > 0 ? bcsub($product['platform_coupon_price'], $newProduct['platform_coupon_price'], 2) : 0;
$product['postage_price'] = $product['postage_price'] > 0 ? bcsub($product['postage_price'], $newProduct['postage_price'], 2) : 0;
$product['integral_total'] = $product['integral_total'] > 0 ? bcsub($product['integral_total'], $newProduct['integral_total'], 0) : 0;
@ -124,7 +134,7 @@ class StoreOrderSplitRepository extends StoreOrderRepository
$product->save();
}
$give_integral = $order['give_integral'] > 0 ? bcmul(bcdiv($newProduct['product_price'], $order['pay_price'], 3), $order['give_integral'], 0) : 0;
$give_integral = $order['give_integral'] > 0 ? floor(bcmul(bcdiv($newProduct['product_price'], $order['pay_price'], 2), $order['give_integral'], 0)) : 0;
$extension_one = $newProduct['extension_one'] > 0 ? bcmul($newProduct['extension_one'], $num, 2) : 0;
$extension_two = $newProduct['extension_two'] > 0 ? bcmul($newProduct['extension_two'], $num, 2) : 0;
$order['total_num'] -= $newProduct['product_num'];
@ -133,6 +143,7 @@ class StoreOrderSplitRepository extends StoreOrderRepository
$order['pay_postage'] = $order['total_postage'];
$order['extension_one'] = $order['extension_one'] > 0 ? bcsub($order['extension_one'], $extension_one, 2) : 0;
$order['extension_two'] = $order['extension_two'] > 0 ? bcsub($order['extension_two'], $extension_two, 2) : 0;
$order['svip_discount'] = $order['svip_discount'] > 0 ? bcsub($order['svip_discount'], $newProduct['svip_discount'], 2) : 0;
$order['coupon_price'] = $order['coupon_price'] > 0 ? bcsub($order['coupon_price'], $newProduct['coupon_price'], 2) : 0;
$order['coupon_price'] = $order['platform_coupon_price'] > 0 ? bcsub($order['coupon_price'], $newProduct['platform_coupon_price'], 2) : $order['coupon_price'];
$order['platform_coupon_price'] = $order['platform_coupon_price'] > 0 ? bcsub($order['platform_coupon_price'], $newProduct['platform_coupon_price'], 2) : 0;
@ -148,6 +159,7 @@ class StoreOrderSplitRepository extends StoreOrderRepository
$newOrder['pay_postage'] = $newOrder['total_postage'];
$newOrder['extension_one'] = bcadd($newOrder['extension_one'], $extension_one, 2);
$newOrder['extension_two'] = bcadd($newOrder['extension_two'], $extension_two, 2);
$newOrder['svip_discount'] = bcadd($newOrder['svip_discount'], $newProduct['svip_discount'], 2);
$newOrder['coupon_price'] = bcadd($newOrder['coupon_price'], $newProduct['coupon_price'], 2);
$newOrder['coupon_price'] = bcadd($newOrder['coupon_price'], $newProduct['platform_coupon_price'], 2);
$newOrder['platform_coupon_price'] = bcadd($newOrder['platform_coupon_price'], $newProduct['platform_coupon_price'], 2);
@ -161,14 +173,16 @@ class StoreOrderSplitRepository extends StoreOrderRepository
}
if (!count($inserts)) {
throw new ValidateException('请选择拆单商品');
throw new ValidateException('请选择需拆出的商品');
}
$newOrder['pay_price'] = bcadd($newOrder['pay_price'], $newOrder['pay_postage'], 2);
$order['pay_price'] = bcsub($order['pay_price'], $newOrder['pay_postage'], 2);
$newOrder['order_sn'] = explode('-', $newOrder['order_sn'])[0] . ('-' . ($this->getSearch([])->where('main_id', $order['order_id'])->count() + 1));
$newOrder['main_id'] = $order['main_id'] ?: $order['order_id'];
if ($newOrder['verify_code']) {
$newOrder['verify_code'] = $this->verifyCode();
}
unset($newOrder['order_id']);
$newOrder = $this->create($newOrder);
$newOrderId = $newOrder['order_id'];

View File

@ -24,7 +24,6 @@ use app\common\repositories\system\merchant\MerchantRepository;
use app\common\repositories\user\UserBillRepository;
use app\common\repositories\user\UserRepository;
use crmeb\jobs\SendSmsJob;
use crmeb\jobs\SendTemplateMessageJob;
use crmeb\services\AlipayService;
use crmeb\services\ExpressService;
use crmeb\services\MiniProgramService;
@ -51,6 +50,16 @@ use think\Model;
*/
class StoreRefundOrderRepository extends BaseRepository
{
//状态 0:待审核 -1:审核未通过 1:待退货 2:待收货 3:已退款 -10 取消
public const REFUND_STATUS_WAIT = 0;
public const REFUND_STATUS_BACK = 1;
public const REFUND_STATUS_THEGOODS = 2;
public const REFUND_STATUS_SUCCESS = 1;
public const REFUND_STATUS_REFUSED = -1;
public const REFUND_STATUS_CANCEL= -2;
/**
* StoreRefundOrderRepository constructor.
* @param StoreRefundOrderDao $dao
@ -116,7 +125,7 @@ class StoreRefundOrderRepository extends BaseRepository
});
}
public function createRefund(StoreOrder $order, $refund_type = 1, $refund_message = '自动发起退款')
public function createRefund(StoreOrder $order, $refund_type = 1, $refund_message = '自动发起退款', $refund_postage = true)
{
$products = $order->orderProduct;
$ids = array_column($products->toArray(), 'order_product_id');
@ -137,12 +146,12 @@ class StoreRefundOrderRepository extends BaseRepository
$total_extension_one = bcadd($total_extension_one, bcmul($product['refund_num'], $product['extension_one'], 2), 2);
if ($product['extension_two'] > 0)
$total_extension_two = bcadd($total_extension_two, bcmul($product['refund_num'], $product['extension_two'], 2), 2);
$postagePrice = !$order->status ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
$postagePrice = ($refund_postage || !$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
$totalRefundNum += $product['refund_num'];
$refundPrice = 0;
//计算可退金额
if ($product['product_price'] > 0) {
$refundPrice = bcsub($product['product_price'], $productRefundPrice['refund_price'] ?? 0, 2);
$refundPrice = bcsub($product['product_price'], bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2);
}
$platform_refund_price = 0;
//计算退的平台优惠券金额
@ -204,7 +213,7 @@ class StoreRefundOrderRepository extends BaseRepository
$totalRefundPrice = 0;
foreach ($products as $product) {
$productRefundPrice = $productRefundPrices[$product['order_product_id']] ?? [];
$postagePrice = !$order->status ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
$postagePrice = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
$refundPrice = 0;
if ($product['product_price'] > 0) {
$refundPrice = bcsub($product['product_price'], bcsub($productRefundPrice['refund_price'] ?? 0,$productRefundPrice['refund_postage']??0 ,2), 2);
@ -220,9 +229,8 @@ class StoreRefundOrderRepository extends BaseRepository
$productRefundPrices = app()->make(StoreRefundProductRepository::class)->userRefundPrice($products->column('order_product_id'));
$product = $products[0];
$productRefundPrice = $productRefundPrices[$product['order_product_id']] ?? [];
$price = bcmul(bcdiv($product['product_price'],$product['product_num'], 2),$product['refund_num'],2);
$total_refund_price = bcsub($price, $product['refund_price'], 2);
$postage_price = !$order->status ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
$total_refund_price = bcsub($product['product_price'], bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2);
$postage_price = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
return compact('total_refund_price', 'postage_price');
}
@ -261,12 +269,12 @@ class StoreRefundOrderRepository extends BaseRepository
$total_extension_one = bcadd($total_extension_one, bcmul($product['refund_num'], $product['extension_one'], 2), 2);
if ($product['extension_two'] > 0)
$total_extension_two = bcadd($total_extension_two, bcmul($product['refund_num'], $product['extension_two'], 2), 2);
$postagePrice = !$order->status ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
$postagePrice = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
$totalRefundNum += $product['refund_num'];
$refundPrice = 0;
//计算可退金额
if ($product['product_price'] > 0) {
$refundPrice = bcsub($product['product_price'], bcsub($productRefundPrice['refund_price'] ?? 0,$productRefundPrice['refund_postage']??0) , 2);
$refundPrice = bcsub($product['product_price'], bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2);
}
$platform_refund_price = 0;
//计算退的平台优惠券金额
@ -324,12 +332,7 @@ class StoreRefundOrderRepository extends BaseRepository
public function applyRefundAfter($refund, $order)
{
event('refund.create', compact('refund', 'order'));
$tempData = ['tempCode' => 'ORDER_REFUND_STATUS', 'id' => $refund->refund_order_id];
Queue::push(SendTemplateMessageJob::class, $tempData);
Queue::push(SendSmsJob::class, [
'tempId' => 'ADMIN_RETURN_GOODS_CODE',
'id' => $refund->refund_order_id
]);
Queue::push(SendSmsJob::class, ['tempId' => 'ADMIN_RETURN_GOODS_CODE', 'id' => $refund->refund_order_id]);
SwooleTaskService::merchant('notice', [
'type' => 'new_refund_order',
'data' => [
@ -366,13 +369,13 @@ class StoreRefundOrderRepository extends BaseRepository
$productRefundPrice = app()->make(StoreRefundProductRepository::class)->userRefundPrice([$productId])[$productId] ?? [];
//计算可退运费
$postagePrice = !$order->status ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
$postagePrice = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
$refundPrice = 0;
//计算可退金额
if ($product['product_price'] > 0) {
if ($product['refund_num'] == $num) {
$refundPrice = bcsub($product['product_price'], $productRefundPrice['refund_price'] ?? 0, 2);
$refundPrice = bcsub($product['product_price'], bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2);
} else {
$refundPrice = bcmul(bcdiv($product['product_price'], $product['product_num'], 2), $num, 2);
}
@ -471,7 +474,7 @@ class StoreRefundOrderRepository extends BaseRepository
*/
public function getList(array $where, int $page, int $limit)
{
$query = $this->dao->search($where)->where('is_system_del', 0)->with([
$query = $this->dao->search($where)->where('is_system_del', 0)->where('status','<>',-2)->with([
'order' => function ($query) {
$query->field('order_id,order_sn,activity_type,real_name,user_address,status,order_type,is_del');
},
@ -513,7 +516,7 @@ class StoreRefundOrderRepository extends BaseRepository
public function getAdminList(array $where, int $page, int $limit)
{
$query = $this->dao->search($where)->with(['order' => function ($query) {
$query = $this->dao->search($where)->where('status','<>',-2)->with(['order' => function ($query) {
$query->field('order_id,order_sn,activity_type');
}, 'refundProduct.product', 'user' => function ($query) {
$query->field('uid,nickname,phone');
@ -760,14 +763,9 @@ class StoreRefundOrderRepository extends BaseRepository
$this->dao->update($id, $data);
$refund = $res;
event('refund.refuse',compact('id','refund'));
$tempData = ['tempCode' => 'ORDER_REFUND_NOTICE', 'id' => $id];
Queue::push(SendTemplateMessageJob::class, $tempData);
$statusRepository = app()->make(StoreRefundStatusRepository::class);
$statusRepository->status($id, $statusRepository::CHANGE_REFUND_REFUSE, '订单退款已拒绝');
Queue::push(SendSmsJob::class, [
'tempId' => 'REFUND_FAIL_CODE',
'id' => $id
]);
Queue::push(SendSmsJob::class, ['tempId' => 'REFUND_FAIL_CODE', 'id' => $id]);
});
}
@ -801,12 +799,7 @@ class StoreRefundOrderRepository extends BaseRepository
$data['status'] = 1;
$statusRepository = app()->make(StoreRefundStatusRepository::class);
$statusRepository->status($id, $statusRepository::CHANGE_REFUND_AGREE, '退款申请已通过,请将商品寄回');
$tempData = ['tempCode' => 'ORDER_REFUND_NOTICE', 'id' => $id];
Queue::push(SendTemplateMessageJob::class, $tempData);
Queue::push(SendSmsJob::class, [
'tempId' => 'REFUND_SUCCESS_CODE',
'id' => $id
]);
Queue::push(SendSmsJob::class, ['tempId' => 'REFUND_SUCCESS_CODE', 'id' => $id]);
}
$data['status_time'] = date('Y-m-d H:i:s');
$this->dao->update($id, $data);
@ -995,12 +988,7 @@ class StoreRefundOrderRepository extends BaseRepository
if ($refundAll) {
$refundOrder->order->status = -1;
}
$tempData = ['tempCode' => 'ORDER_REFUND_END', 'id' => $refundOrder->refund_order_id];
Queue::push(SendTemplateMessageJob::class, $tempData);
Queue::push(SendSmsJob::class, [
'tempId' => 'REFUND_CONFORM_CODE',
'id' => $refundOrder->refund_order_id
]);
Queue::push(SendSmsJob::class, ['tempId' => 'REFUND_CONFORM_CODE', 'id' => $refundOrder->refund_order_id]);
$this->descBrokerage($refundOrder);
//退回平台优惠
@ -1012,12 +1000,13 @@ class StoreRefundOrderRepository extends BaseRepository
} else {
app()->make(MerchantRepository::class)->subLockMoney($refundOrder->mer_id, 'order', $refundOrder->order->order_id, $refundOrder->platform_refund_price);
}
$isVipCoupon = app()->make(StoreGroupOrderRepository::class)->isVipCoupon($refundOrder->order->groupOrder);
app()->make(FinancialRecordRepository::class)->dec([
'order_id' => $refundOrder->refund_order_id,
'order_sn' => $refundOrder->refund_order_sn,
'user_info' => $refundOrder->user->nickname,
'user_id' => $refundOrder->uid,
'financial_type' => 'refund_platform_coupon',
'financial_type' => $isVipCoupon ? 'refund_svip_coupon' : 'refund_platform_coupon',
'type' => 1,
'number' => $refundOrder->platform_refund_price,
], $refundOrder->mer_id);
@ -1469,4 +1458,26 @@ class StoreRefundOrderRepository extends BaseRepository
return $data;
}
/**
* TODO 用户取消退款单申请
* @param int $id
* @param $user
* @author Qinii
* @day 2022/11/18
*/
public function cancel(int $id, $user)
{
//状态 0:待审核 -1:审核未通过 1:待退货 2:待收货 3:已退款
$res = $this->dao->getWhere(['refund_order_id' => $id, 'uid' => $user->uid],'*', ['refundProduct.product']);
if (!$res) throw new ValidateException('数据不存在');
if (!in_array($res['status'],[self::REFUND_STATUS_WAIT, self::REFUND_STATUS_BACK]))
throw new ValidateException('当前状态不可取消');
Db::transaction(function () use ($id, $res) {
$this->getProductRefundNumber($res, -1);
$this->dao->update($id, ['status_time' => date('Y-m-d H:i:s'), 'status' => self::REFUND_STATUS_CANCEL]);
$statusRepository = app()->make(StoreRefundStatusRepository::class);
$statusRepository->status($id, $statusRepository::CHANGE_REFUND_CANCEL, '用户取消退款');
});
}
}

View File

@ -38,6 +38,8 @@ class StoreRefundStatusRepository extends BaseRepository
const CHANGE_REFUND_PRICE = 'refund_price';
//订单退款已拒绝
const CHANGE_REFUND_REFUSE = 'refund_refuse';
//用户取消退款
const CHANGE_REFUND_CANCEL = 'refund_cancel';
/**
* StoreRefundStatusRepository constructor.
* @param StoreRefundStatusDao $dao

View File

@ -17,7 +17,6 @@ use app\common\model\store\product\ProductLabel;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\order\StoreOrderProductRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use crmeb\jobs\ChangeSpuStatusJob;
use crmeb\services\SwooleTaskService;
use think\exception\ValidateException;
use think\facade\Db;
@ -285,7 +284,10 @@ class ProductAssistRepository extends BaseRepository
$where = $this->dao->assistShow();
$where[$this->dao->getPk()] = $id;
$data = $this->dao->search($where)->append(['assist_status'])->find();
if(!$data) throw new ValidateException('商品已下架');
if(!$data) {
app()->make(SpuRepository::class)->changeStatus($id,3);
throw new ValidateException('商品已下架');
}
$make = app()->make(ProductRepository::class);
$data['product'] = $make->apiProductDetail(['product_id' => $data['product_id']],3,$id);
$data['product']['store_name'] = $data['store_name'];
@ -367,8 +369,8 @@ class ProductAssistRepository extends BaseRepository
$productAssist->is_del = 1;
$productAssist->save();
event('product.assistDelete',compact('productAssist'));
queue(ChangeSpuStatusJob::class, ['id' => $productAssist[$this->getPk()], 'product_type' => 3]);
//app()->make(SpuRepository::class)->changeStatus($data[$this->getPk()],3);
// queue(ChangeSpuStatusJob::class, ['id' => $productAssist[$this->getPk()], 'product_type' => 3]);
app()->make(SpuRepository::class)->changeStatus($productAssist[$this->getPk()],3);
});
}
@ -485,4 +487,27 @@ class ProductAssistRepository extends BaseRepository
return $make->updateSort($ret['product_id'],$ret[$this->dao->getPk()],3,$data);
}
public function switchStatus($id, $data)
{
$data['product_status'] = $data['status'];
$ret = $this->dao->get($id);
if (!$ret)
throw new ValidateException('数据不存在');
event('product.assistStatus.before', compact('id', 'data'));
$this->dao->update($id, $data);
event('product.assistStatus', compact('id', 'data'));
$type = ProductRepository::NOTIC_MSG[$data['status']][3];
$message = '您有1个助力'. ProductRepository::NOTIC_MSG[$data['status']]['msg'];
SwooleTaskService::merchant('notice', [
'type' => $type,
'data' => [
'title' => $data['status'] == -2 ? '下架提醒' : '审核结果',
'message' => $message,
'id' => $id[0]
]
], $ret->mer_id);
app()->make(SpuRepository::class)->changeStatus($id,3);
}
}

View File

@ -79,4 +79,6 @@ class ProductAttrValueRepository extends BaseRepository
{
return $this->dao->getFieldExists(null,'unique',$unique)->find();
}
}

View File

@ -13,6 +13,8 @@
namespace app\common\repositories\store\product;
use app\common\repositories\BaseRepository;
use app\common\repositories\system\attachment\AttachmentCategoryRepository;
use app\common\repositories\system\attachment\AttachmentRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use crmeb\services\CopyProductService;
use crmeb\services\CrmebServeServices;
@ -20,14 +22,16 @@ use crmeb\services\DownloadImageService;
use Exception;
use think\exception\ValidateException;
use app\common\dao\store\product\ProductCopyDao;
use think\facade\Cache;
use think\facade\Db;
class ProductCopyRepository extends BaseRepository
{
protected $host = ['taobao', 'tmall', 'jd', 'pinduoduo', 'suning', 'yangkeduo','1688'];
protected $AttachmentCategoryName = '远程下载';
protected $dao;
protected $updateImage = ['image', 'slider_image'];
protected $AttachmentCategoryPath = 'copy';
/**
* ProductRepository constructor.
* @param dao $dao
@ -37,132 +41,212 @@ class ProductCopyRepository extends BaseRepository
$this->dao = $dao;
}
public function copyProduct(array $data,?int $merId)
public function getProduct($url,$merId)
{
$type = $data['type'];
$id = $data['id'];
$shopid = $data['shopid'];
$url = $data['url'];
$apikey = systemConfig('copy_product_apikey');
if ((!$type || !$id) && $url) {
$url_arr = parse_url($url);
if (isset($url_arr['host'])) {
foreach ($this->host as $name) {
if (strpos($url_arr['host'], $name) !== false) {
$type = $name;
}
}
}
$type = ($type == 'pinduoduo' || $type == 'yangkeduo') ? 'pdd' : $type;
try{
switch ($type) {
case 'taobao':
case 'tmall':
$params = [];
if (isset($url_arr['query']) && $url_arr['query']) {
$queryParts = explode('&', $url_arr['query']);
foreach ($queryParts as $param) {
$item = explode('=', $param);
if (isset($item[0]) && $item[1]) $params[$item[0]] = $item[1];
}
}
$id = $params['id'] ?? '';
break;
case 'jd':
$params = [];
if (isset($url_arr['path']) && $url_arr['path']) {
$path = str_replace('.html', '', $url_arr['path']);
$params = explode('/', $path);
}
$id = $params[1] ?? '';
break;
case 'pdd':
$params = [];
if (isset($url_arr['query']) && $url_arr['query']) {
$queryParts = explode('&', $url_arr['query']);
foreach ($queryParts as $param) {
$item = explode('=', $param);
if (isset($item[0]) && $item[1]) $params[$item[0]] = $item[1];
}
}
$id = $params['goods_id'] ?? '';
break;
case 'suning':
$params = [];
if (isset($url_arr['path']) && $url_arr['path']) {
$path = str_replace('.html', '', $url_arr['path']);
$params = explode('/', $path);
}
$id = $params[2] ?? '';
$shopid = $params[1] ?? '';
break;
case '1688':
$params = [];
if (isset($url_arr['query']) && $url_arr['query']) {
$path = str_replace('.html', '', $url_arr['path']);
$params = explode('/', $path);
}
$id = $params[2] ?? '';
$shopid = $params[1] ?? '';
$type = 'alibaba';
break;
$key = $merId.'_url_'.$url;
}
}catch (Exception $exception){
throw new ValidateException('url有误');
}
}
$result = CopyProductService::getInfo($type, ['itemid' => $id, 'shopid' => $shopid], $apikey);
if ($result) {
$this->add([
'type' => $data['type']?: 'copy',
'num' => -1,
'info' => $data['url'],
'message' => '复制商品「'.$result['data']['store_name'] .'」'
],$merId);
return ['info' => $result['data']];
if ($result= Cache::get($key)) return $result;
if (systemConfig('copy_product_status') == 2) {
$resultData['data'] = app()->make(CrmebServeServices::class)->copy()->goods($url);
$resultData['status'] = 200;
} else {
throw new ValidateException($result['msg']);
$resultData = $this->useApi($url);
}
if ($resultData['status']) {
$result = $this->getParamsData($resultData['data']);
Cache::set($key,$result);
$this->add(['type' => 'copy', 'num' => 1, 'info' => $url , 'mer_id'=> $merId, 'message' => '采集商品',],$merId);
return $result;
} else {
throw new ValidateException('采集失败,请更换链接重试!');
}
}
/**
* TODO 一号通复制
* @param array $data
* @param int|null $merId
* TODO 99api采集
* @param $url
* @return array
* @author Qinii
* @day 7/27/21
* @day 2022/11/11
*/
public function crmebCopyProduct(array $data,?int $merId)
public function useApi($url)
{
$result = app()->make(CrmebServeServices::class)->copy()->goods($data['url']);
if ($result) {
$this->add([
'type' => 'copy',
'num' => -1,
'info' => $data['url'],
'message' => '复制商品「'.$result['store_name'] .'」'
],$merId);
}
if (!is_array($result['slider_image'])){
$result['slider_image'] = json_decode($result['slider_image']);
}
if ($result['items']) {
foreach ($result['items'] as $k => $item) {
if ($item['value'] == '') unset($result['items'][$k]);
$apikey = systemConfig('copy_product_apikey');
if (!$apikey) throw new ValidateException('请前往平台后台-设置-第三方接口-配置接口密钥');
$url_arr = parse_url($url);
if (isset($url_arr['host'])) {
foreach ($this->host as $name) {
if (strpos($url_arr['host'], $name) !== false) {
$type = $name;
}
}
$result['spec_type'] = 1;
$result['info'] = app()->make(CopyProductService::class)->formatAttr($result['items']);
}else{
$result['spec_type'] = 0;
$result['info'] = null;
}
$type = ($type == 'pinduoduo' || $type == 'yangkeduo') ? 'pdd' : $type;
try{
switch ($type) {
case 'taobao':
case 'tmall':
$params = [];
if (isset($url_arr['query']) && $url_arr['query']) {
$queryParts = explode('&', $url_arr['query']);
foreach ($queryParts as $param) {
$item = explode('=', $param);
if (isset($item[0]) && $item[1]) $params[$item[0]] = $item[1];
}
}
$id = $params['id'] ?? '';
break;
case 'jd':
$params = [];
if (isset($url_arr['path']) && $url_arr['path']) {
$path = str_replace('.html', '', $url_arr['path']);
$params = explode('/', $path);
}
$id = $params[1] ?? '';
break;
case 'pdd':
$params = [];
if (isset($url_arr['query']) && $url_arr['query']) {
$queryParts = explode('&', $url_arr['query']);
foreach ($queryParts as $param) {
$item = explode('=', $param);
if (isset($item[0]) && $item[1]) $params[$item[0]] = $item[1];
}
}
$id = $params['goods_id'] ?? '';
break;
case 'suning':
$params = [];
if (isset($url_arr['path']) && $url_arr['path']) {
$path = str_replace('.html', '', $url_arr['path']);
$params = explode('/', $path);
}
$id = $params[2] ?? '';
$shopid = $params[1] ?? '';
break;
case '1688':
$params = [];
if (isset($url_arr['query']) && $url_arr['query']) {
$path = str_replace('.html', '', $url_arr['path']);
$params = explode('/', $path);
}
$id = $params[2] ?? '';
$shopid = $params[1] ?? '';
$type = 'alibaba';
break;
return ['info' => $result];
}
}catch (Exception $exception){
throw new ValidateException('url有误');
}
$result = CopyProductService::getInfo($type, ['itemid' => $id, 'shopid' => $shopid ?? ''], $apikey);
return $result;
}
/**
* TODO 整理参数
* @param $data
* @return array
* @author Qinii
* @day 2022/11/11
*
*/
public function getParamsData($data)
{
if(!is_array($data['slider_image'])) $data['slider_image'] = json_decode($data['slider_image']);
$params = ProductRepository::CREATE_PARAMS;
foreach ($params as $param) {
if (is_array($param)) {
$res[$param[0]] = $param[1];
} else {
$res[$param] = $data[$param] ?? '';
}
if (in_array($param,$this->updateImage)) {
$res[$param] = $this->getImageByUrl($data[$param]);
}
}
$res['attr'] = $data['items'] ?? $data['info']['attr'];
$res['spec_type'] = count($res['attr']) ? '1' : '0';
$res['content'] = $this->getDescriptionImage($data['description_image'] ?? $data['description_images'],$data['description']);
return $res;
}
/**
* TODO 替换详情页的图片地址
* @param $images
* @param $html
* @return mixed|string|string[]|null
* @author Qinii
* @day 2022/11/11
*/
public function getDescriptionImage($images, $html)
{
preg_match_all('#<img.*?src="([^"]*)"[^>]*>#i', $html, $match);
if (isset($match[1])) {
foreach ($match[1] as $item) {
$uploadValue = $this->getImageByUrl($item);
//下载成功更新数据库
if ($uploadValue) {
//替换图片
$html = str_replace($item, $uploadValue, $html);
} else {
//替换掉没有下载下来的图片
$html = preg_replace('#<img.*?src="' . $item . '"*>#i', '', $html);
}
}
}
return $html;
}
/**
* TODO 根据url下载图片
* @param $data
* @return array|mixed|string
* @author Qinii
* @day 2022/11/11
*/
public function getImageByUrl($data)
{
$merId = request()->merId();
$category = app()->make( AttachmentCategoryRepository::class)->findOrCreate([
'attachment_category_enname' => $this->AttachmentCategoryPath,
'attachment_category_name' => $this->AttachmentCategoryName,
'mer_id' => $merId,
'pid' => 0,
]);
$make = app()->make(AttachmentRepository::class);
$serve = app()->make(DownloadImageService::class);
$type = systemConfig('upload_type');
if (is_array($data)) {
foreach ($data as $datum) {
$arcurl = is_int(strpos($datum, 'http')) ? $datum : 'http://' . ltrim( $datum, '\//');
$image = $serve->downloadImage($arcurl,$this->AttachmentCategoryPath);
$dir = $type == 1 ? rtrim(systemConfig('site_url'), '/').$image['path'] : $image['path'];
$data = [
'attachment_category_id' => $category->attachment_category_id,
'attachment_name' => $image['name'],
'attachment_src' => $dir
];
$make->create($type,$merId, request()->adminId(), $data);
$res[] = $dir;
}
} else {
$arcurl = is_int(strpos($data, 'http')) ? $data : 'http://' . ltrim( $data, '\//');
$image = $serve->downloadImage($arcurl,$this->AttachmentCategoryPath);
$dir = $type == 1 ? rtrim(systemConfig('site_url'), '/').$image['path'] : $image['path'];
$data = [
'attachment_category_id' => $category->attachment_category_id,
'attachment_name' => $image['name'],
'attachment_src' => $dir
];
$make->create($type,$merId, request()->adminId(), $data);
$res = $dir;
}
return $res;
}
/**
* TODO 添加记录并修改数据
* @param $data
@ -183,21 +267,11 @@ class ProductCopyRepository extends BaseRepository
break;
case 'sys':
//nobreak;
case 'taobao':
//nobreak;
case 'jd':
//nobreak;
case 'pay_copy':
//nobreak;
case 'copy':
//nobreak;
case 'suning':
//nobreak;
case 'pdd':
//nobreak;
case '1688':
//nobreak;
case 'tmall':
$field = 'copy_product_num';
break;
default:
@ -254,24 +328,4 @@ class ProductCopyRepository extends BaseRepository
$list = $query->page($page,$limit)->select();
return compact('count','list');
}
/**
* 保存复制商品
* @Author:Qinii
* @Date: 2020/10/9
* @param array $data
*/
public function create(array $data)
{
$serve = app()->make(DownloadImageService::class);
if (is_int(strpos( $data['image'], 'http')))
$arcurl = $data['image'];
else
$arcurl = 'http://' . ltrim( $data['image'], '\//');
$image = $serve->downloadImage($arcurl,'',systemConfig('upload_type'));
$data['image'] = systemConfig('upload_type') == 1 ? rtrim(systemConfig('site_url'), '/').$image['path'] : $image['path'];
app()->make(ProductRepository::class)->create($data, 0);
}
}

View File

@ -17,7 +17,7 @@ use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\store\order\StoreRefundOrderRepository;
use app\common\repositories\user\UserRepository;
use crmeb\jobs\CancelGroupBuyingJob;
use crmeb\jobs\SendTemplateMessageJob;
use crmeb\jobs\SendSmsJob;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Queue;
@ -193,7 +193,7 @@ class ProductGroupBuyingRepository extends BaseRepository
$productGroupUserRepository->updateStatus($res['group_buying_id']);
$orderIds = $productGroupUserRepository->groupOrderIds($res['group_buying_id']);
app()->make(StoreOrderRepository::class)->groupBuyingStatus($orderIds, 0);
Queue(SendTemplateMessageJob::class,['tempCode' => 'GROUP_BUYING_SUCCESS', 'id' =>$res->group_buying_id]);
Queue::push(SendSmsJob::class,['tempId' => 'USER_BALANCE_CHANGE', 'id' => $res->group_buying_id]);
}

View File

@ -16,7 +16,6 @@ use app\common\dao\store\product\ProductGroupDao;
use app\common\repositories\store\order\StoreOrderProductRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\store\StoreCategoryRepository;
use crmeb\jobs\ChangeSpuStatusJob;
use crmeb\services\SwooleTaskService;
use think\exception\ValidateException;
use think\facade\Db;
@ -377,7 +376,7 @@ class ProductGroupRepository extends BaseRepository
}
])->hidden(['ficti_status','ficti_num','refusal','is_del'])->find();
if(!$data) {
queue(ChangeSpuStatusJob::class,['id' => $id,'product_type' => 4]);
app()->make(SpuRepository::class)->changeStatus($id,4);
throw new ValidateException('商品已下架或不在活动时间内');
}
@ -472,4 +471,27 @@ class ProductGroupRepository extends BaseRepository
return $make->updateSort($ret['product_id'],$ret[$this->dao->getPk()],4,$data);
}
public function switchStatus($id, $data)
{
$data['product_status'] = $data['status'];
$ret = $this->dao->get($id);
if (!$ret)
throw new ValidateException('数据不存在');
event('product.groupStatus.before', compact('id', 'data'));
$this->dao->update($id, $data);
event('product.groupStatus', compact('id', 'data'));
$type = ProductRepository::NOTIC_MSG[$data['status']][4];
$message = '您有1个拼团'. ProductRepository::NOTIC_MSG[$data['status']]['msg'];
SwooleTaskService::merchant('notice', [
'type' => $type,
'data' => [
'title' => $data['status'] == -2 ? '下架提醒' : '审核结果',
'message' => $message,
'id' => $id[0]
]
], $ret->mer_id);
app()->make(SpuRepository::class)->changeStatus($id,4);
}
}

View File

@ -12,6 +12,8 @@ namespace app\common\repositories\store\product;
use app\common\repositories\BaseRepository;
use app\common\dao\store\product\ProductGroupUserDao;
use crmeb\services\LockService;
use think\exception\ValidateException;
class ProductGroupUserRepository extends BaseRepository
{
@ -19,14 +21,14 @@ class ProductGroupUserRepository extends BaseRepository
/**
* ProductGroupRepository constructor.
* @param ProductGroupDao $dao
* @param ProductGroupUserDao $dao
*/
public function __construct(ProductGroupUserDao $dao)
{
$this->dao = $dao;
}
public function create($userInfo,$data)
public function create($userInfo, $data)
{
$_where = [
'product_group_id' => $data['product_group_id'],
@ -34,28 +36,22 @@ class ProductGroupUserRepository extends BaseRepository
'uid' => $userInfo->uid,
];
$user = $this->getWhere($_where);
if($user){
if ($user) {
throw new ValidateException('您已经参加过此团');
}else{
$data = [
'product_group_id' => $data['product_group_id'],
'group_buying_id' => $data['group_buying_id'],
'is_initiator' => $data['is_initiator'],
'order_id' => $data['order_id'],
'uid' => $userInfo->uid,
'nickname'=> $userInfo->nickname,
'avatar' => $userInfo->avatar,
];
makeLock('group_buying')->lock();
try{
$user = $this->dao->create($data);
}catch (\Exception $exception){
makeLock('group_buying')->unlock();
}
makeLock('group_buying')->unlock();
}
return $user;
$data = [
'product_group_id' => $data['product_group_id'],
'group_buying_id' => $data['group_buying_id'],
'is_initiator' => $data['is_initiator'],
'order_id' => $data['order_id'],
'uid' => $userInfo->uid,
'nickname' => $userInfo->nickname,
'avatar' => $userInfo->avatar,
];
return app()->make(LockService::class)->exec('order.group_buying', function () use ($data) {
$this->dao->create($data);
});
}
/**

View File

@ -17,7 +17,6 @@ use app\common\model\store\product\ProductLabel;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\order\StoreOrderProductRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use crmeb\jobs\ChangeSpuStatusJob;
use crmeb\services\SwooleTaskService;
use think\exception\ValidateException;
use think\facade\Db;
@ -287,8 +286,7 @@ class ProductPresellRepository extends BaseRepository
$where['product_presell_id'] = $id;
$data = $this->dao->search($where)->append(['presell_status', 'tattend_one', 'tattend_two', 'seles'])->find();
if (!$data){
//app()->make(SpuRepository::class)->changeStatus($id,2);
queue(ChangeSpuStatusJob::class, ['id' => $id, 'product_type' => 2]);
app()->make(SpuRepository::class)->changeStatus($id,2);
throw new ValidateException('商品已下架');
}
if ($data['pay_count'] && $userInfo->uid) {
@ -411,8 +409,7 @@ class ProductPresellRepository extends BaseRepository
$data->product->save();
$productPresell = $data;
event('product.presellDelete',compact('productPresell'));
queue(ChangeSpuStatusJob::class, ['id' => $data[$this->getPk()], 'product_type' => 2]);
//app()->make(SpuRepository::class)->changeStatus($data[$this->getPk()],2);
app()->make(SpuRepository::class)->changeStatus($data[$this->getPk()],2);
});
}
@ -521,4 +518,27 @@ class ProductPresellRepository extends BaseRepository
$make = app()->make(SpuRepository::class);
return $make->updateSort($ret['product_id'], $id, 2, $data);
}
public function switchStatus($id, $data)
{
$data['product_status'] = $data['status'];
$ret = $this->dao->get($id);
if (!$ret)
throw new ValidateException('数据不存在');
event('product.presellStatus.before', compact('id', 'data'));
$this->dao->update($id, $data);
event('product.presellStatus', compact('id', 'data'));
$type = ProductRepository::NOTIC_MSG[$data['status']][2];
$message = '您有1个预售'. ProductRepository::NOTIC_MSG[$data['status']]['msg'];
SwooleTaskService::merchant('notice', [
'type' => $type,
'data' => [
'title' => $data['status'] == -2 ? '下架提醒' : '审核结果',
'message' => $message,
'id' => $id[0]
]
], $ret->mer_id);
app()->make(SpuRepository::class)->changeStatus($id,2);
}
}

View File

@ -87,7 +87,6 @@ class ProductReplyRepository extends BaseRepository
$count = 0;
$list = [];
} else {
$query = $this->dao->search($where)->where('is_del', 0)
->when($where['type'] !== '', function ($query) use ($where) {
$query->where($this->switchType($where['type']));
@ -99,6 +98,13 @@ class ProductReplyRepository extends BaseRepository
$count = $query->count();
$list = $query->page($page, $limit)->hidden(['is_virtual'])->select()->each(function ($item) {
$item['sku'] = $item['orderProduct']['cart_info']['productAttr']['sku'] ?? '';
if (mb_strlen($item['nickname']) > 1) {
$str = mb_substr($item['nickname'],0,1) . '*';
if (mb_strlen($item['nickname']) > 2) {
$str .= mb_substr($item['nickname'], -1,1);
}
$item['nickname'] = $str;
}
unset($item['orderProduct']);
return $item;
});

View File

@ -23,12 +23,16 @@ use app\common\repositories\store\GuaranteeValueRepository;
use app\common\repositories\store\order\StoreCartRepository;
use app\common\repositories\store\order\StoreOrderProductRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\store\parameter\ParameterValueRepository;
use app\common\repositories\store\StoreActivityRepository;
use app\common\repositories\store\StoreSeckillActiveRepository;
use app\common\repositories\store\StoreSeckillTimeRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use app\common\repositories\user\UserRelationRepository;
use app\common\repositories\user\UserVisitRepository;
use app\validate\merchant\StoreProductValidate;
use crmeb\jobs\ChangeSpuStatusJob;
use crmeb\jobs\SendSmsJob;
use crmeb\services\QrcodeService;
use crmeb\services\RedisCacheService;
use crmeb\services\SwooleTaskService;
@ -41,8 +45,8 @@ use app\common\dao\store\product\ProductDao as dao;
use app\common\repositories\store\StoreCategoryRepository;
use app\common\repositories\store\shipping\ShippingTemplateRepository;
use app\common\repositories\store\StoreBrandRepository;
use think\facade\Queue;
use think\facade\Route;
use crmeb\jobs\ChangeSpuStatusJob;
use think\contract\Arrayable;
/**
@ -55,9 +59,48 @@ class ProductRepository extends BaseRepository
{
protected $dao;
protected $admin_filed = 'Product.product_id,Product.mer_id,brand_id,spec_type,unit_name,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,U.rank,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,star,ficti,integral_total,integral_price_total,sys_labels';
protected $filed = 'Product.product_id,Product.mer_id,brand_id,unit_name,spec_type,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,integral_total,integral_price_total,mer_labels,Product.is_good,Product.is_del,type';
const CREATE_PARAMS = [
"image", "slider_image", "store_name", "store_info", "keyword", "bar_code", "guarantee_template_id", "cate_id", "mer_cate_id", "unit_name", "sort" , "is_show", "is_good", 'is_gift_bag', 'integral_rate', "video_link", "temp_id", "content", "spec_type", "extension_type", "attr", 'mer_labels', 'delivery_way', 'delivery_free','param_temp_id','extend',
["brand_id",0],
['once_max_count',0],
['once_min_count',0],
['pay_limit', 0],
["attrValue",[]],
['give_coupon_ids',[]],
['type',0],
['svip_price',0],
['svip_price_type',0],
['params',[]],
];
protected $admin_filed = 'Product.product_id,Product.mer_id,brand_id,spec_type,unit_name,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,U.rank,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,star,ficti,integral_total,integral_price_total,sys_labels,param_temp_id';
protected $filed = 'Product.product_id,Product.mer_id,brand_id,unit_name,spec_type,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,integral_total,integral_price_total,mer_labels,Product.is_good,Product.is_del,type,param_temp_id';
const NOTIC_MSG = [
1 => [
'0' => 'product_success',
'1' => 'product_seckill_success',
'2' => 'product_presell_success',
'3' => 'product_assist_success',
'4' => 'product_group_success',
'msg' => '审核通过'
],
-1 => [
'0' => 'product_fail',
'1' => 'product_seckill_fail',
'2' => 'product_presell_fail',
'3' => 'product_assist_fail',
'4' => 'product_group_fail',
'msg' => '审核失败'
],
-2 => [
'0' => 'product_fail',
'1' => 'product_seckill_fail',
'2' => 'product_presell_fail',
'3' => 'product_assist_fail',
'4' => 'product_group_fail',
'msg' => '被下架'
],
];
/**
* ProductRepository constructor.
* @param dao $dao
@ -172,41 +215,32 @@ class ProductRepository extends BaseRepository
$data['attr'] = [];
if (count($data['attrValue']) > 1) throw new ValidateException('单规格商品属性错误');
}
return Db::transaction(function () use ($data, $productType,$conType) {
event('product.create.before', compact('data','productType','conType'));
$content = [
'content' => $conType ? json_encode($data['content']) : $data['content'] ,
'type' => $conType
];
$product = $this->setProduct($data);
event('product.create.before', compact('data','productType','conType'));
return Db::transaction(function () use ($data, $productType,$conType,$content,$product) {
$activity_id = 0;
$product = $this->setProduct($data);
$result = $this->dao->create($product);
$settleParams = $this->setAttrValue($data['attrValue'], $result->product_id, $productType, 0);
$settleParams = $this->setAttrValue($data, $result->product_id, $productType, 0);
$settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $result->product_id, $data['mer_id']);
$settleParams['attr'] = $this->setAttr($data['attr'], $result->product_id);
$content = [
'content' => $conType ? json_encode($data['content']) : $data['content'] ,
'type' => $conType
];
if ($productType ==0 ) app()->make(ParameterValueRepository::class)->create($result->product_id, $data['params'] ?? [],$data['mer_id']);
$this->save($result->product_id, $settleParams, $content,$product,$productType);
if ($productType == 1) { //秒杀商品
$dat = $this->setSeckillProduct($data);
$dat['product_id'] = $result->product_id;
$seckill = app()->make(StoreSeckillActiveRepository::class)->create($dat);
$activity_id = $seckill->seckill_active_id;
}
if (in_array($productType, [0, 1])) {
if ($productType == 1) { //秒杀商品
$dat = $this->setSeckillProduct($data);
$dat['product_id'] = $result->product_id;
$seckill = app()->make(StoreSeckillActiveRepository::class)->create($dat);
$activity_id = $seckill->seckill_active_id;
}
$product['price'] = $settleParams['data']['price'];
$product['mer_labels'] = $data['mer_labels'];
app()->make(SpuRepository::class)->create($product, $result->product_id, $activity_id, $productType);
}
$product = $result;
if ($productType==0){
$find=Db::name('merchant_address')->where('mer_id',$data['mer_id'])->find();
if ($find && $find['street_id']!=0){
$addsdata=[
'address_id'=>$find['street_id'],
'product_id'=>$result->product_id
];
Db::name('merchant_address_product')->insert($addsdata);
}
}
event('product.create',compact('product'));
return $result->product_id;
});
@ -226,8 +260,7 @@ class ProductRepository extends BaseRepository
}
event('product.update.before', compact('id','data','merId','productType','conType'));
$spuData = $product = $this->setProduct($data);
$settleParams = $this->setAttrValue($data['attrValue'], $id, $productType, 1);
$settleParams = $this->setAttrValue($data, $id, $productType, 1);
$settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId);
$settleParams['attr'] = $this->setAttr($data['attr'], $id);
$content = [
@ -238,15 +271,20 @@ class ProductRepository extends BaseRepository
$spuData['mer_id'] = $merId;
$spuData['mer_labels'] = $data['mer_labels'];
Db::transaction(function () use ($id, $data, $productType, $settleParams,$content,$product,$spuData) {
Db::transaction(function () use ($id, $data, $productType, $settleParams,$content,$product,$spuData,$merId) {
$this->save($id, $settleParams, $content, $product, $productType);
if ($productType == 1) { //秒杀商品
$dat = $this->setSeckillProduct($data);
app()->make(StoreSeckillActiveRepository::class)->updateByProduct($id, $dat);
}
if ($productType == 0) {
$make = app()->make(ParameterValueRepository::class);
$make->clear($id, 'product_id');
$make->create($id, $data['params'] ?? [], $merId);
}
app()->make(SpuRepository::class)->baseUpdate($spuData, $id, 0, $productType);
event('product.update',compact('id'));
Queue(ChangeSpuStatusJob::class, ['id' => $id, 'product_type' => $productType]);
app()->make(SpuRepository::class)->changeStatus($id, $productType);
});
}
@ -256,19 +294,18 @@ class ProductRepository extends BaseRepository
$data['attr'] = [];
if (count($data['attrValue']) > 1) throw new ValidateException('单规格商品属性错误');
}
$settleParams = $this->setAttrValue($data['attrValue'], $id, 0, 1);
$res = $this->dao->get($id);
$data['svip_price_type'] = $res['svip_price_type'];
$settleParams = $this->setAttrValue($data, $id, 0, 1);
$settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId);
$settleParams['attr'] = $this->setAttr($data['attr'], $id);
$data['price'] = $settleParams['data']['price'];
unset($data['attrValue'],$data['attr'],$data['mer_cate_id']);
$where = [
'product_id' => $id,
'product_type' => 0,
];
$ret = app()->make(SpuRepository::class)->getSearch($where)->find();
$ret = app()->make(SpuRepository::class)->getSearch(['product_id' => $id, 'product_type' => 0,])->find();
Db::transaction(function () use ($id, $data, $settleParams,$ret) {
$this->save($id, $settleParams, null, [], 0);
app()->make(SpuRepository::class)->update($ret->spu_id,['price' => $data['price']]);
Queue(SendSmsJob::class, ['tempId' => 'PRODUCT_INCREASE', 'id' => $id]);
});
}
@ -311,7 +348,7 @@ class ProductRepository extends BaseRepository
}
}
if ($content){
(app()->make(ProductContentRepository::class))->clearAttr($id,$content['type']);
app()->make(ProductContentRepository::class)->clearAttr($id,$content['type']);
$this->dao->createContent($id, $content);
}
@ -320,11 +357,15 @@ class ProductRepository extends BaseRepository
$data['ot_price'] = $settleParams['data']['ot_price'];
$data['cost'] = $settleParams['data']['cost'];
$data['stock'] = $settleParams['data']['stock'];
$data['svip_price'] = $settleParams['data']['svip_price'];
}
if(isset($data['status']) && $data['status']!== 1){
$message = $productType ? '您有一个新的秒杀商品待审核':($data['is_gift_bag'] ? '您有一个新的礼包商品待审核' :'您有一个新的商品待审核' );
$res = $this->dao->update($id, $data);
if(isset($data['status']) && $data['status'] !== 1 ){
$message = '您有1个新的'. ($productType ? '秒杀商品' : ($data['is_gift_bag'] ? '礼包商品' :'商品')) . '待审核';
$type = $productType ? 'new_seckill' : ($data['is_gift_bag'] ? 'new_bag' :'new_product');
SwooleTaskService::admin('notice', [
'type' => $productType ? 'new_seckill' : ($data['is_gift_bag'] ? 'new_bag' :'new_product'),
'type' => $type,
'data' => [
'title' => '商品审核',
'message' => $message,
@ -332,9 +373,7 @@ class ProductRepository extends BaseRepository
]
]);
}
if($productType == 0) queue(ChangeSpuStatusJob::class, ['id' => $id, 'product_type' => 0]);
return $this->dao->update($id, $data);
return $res;
}
/**
@ -430,20 +469,20 @@ class ProductRepository extends BaseRepository
'once_min_count' => $data['once_min_count'] ?? 0,
'once_max_count' => $data['once_max_count'] ?? 0,
'pay_limit' => $data['pay_limit'] ?? 0,
'svip_price_type' => $data['svip_price_type'] ?? 0,
];
if (isset($data['mer_id']))
$result['mer_id'] = $data['mer_id'];
if (isset($data['old_product_id'])){
if (isset($data['old_product_id']))
$result['old_product_id'] = $data['old_product_id'];
}
if (isset($data['product_type']))
$result['product_type'] = $data['product_type'];
if (isset($data['type']) && $data['type'])
$result['type'] = $data['type'];
if (isset($data['param_temp_id']))
$result['param_temp_id'] = $data['param_temp_id'];
if (isset($data['extend']))
$result['extend'] = $data['extend'] ? json_encode($data['extend'], JSON_UNESCAPED_UNICODE) :[];
return $result;
}
@ -506,21 +545,17 @@ class ProductRepository extends BaseRepository
*/
public function setAttrValue(array $data, int $productId, int $productType, int $isUpdate = 0)
{
$extension_status = systemConfig('extension_status');
if ($isUpdate) {
$product = app()->make(ProductAttrValueRepository::class)->search(['product_id' => $productId])->select()->toArray();
$oldSku = $this->detailAttrValue($product, null);
}
$price = $stock = $ot_price = $cost = 0;
$price = $stock = $ot_price = $cost = $svip_price = 0;
try {
foreach ($data as $value) {
foreach ($data['attrValue'] as $value) {
$sku = '';
if (isset($value['detail']) && !empty($value['detail'])) {
if (is_array($value['detail']) ){
$sku = implode(',', $value['detail']);
}
if (isset($value['detail']) && !empty($value['detail']) && is_array($value['detail'])) {
$sku = implode(',', $value['detail']);
}
$ot_price_ = $value['price'];
if (isset($value['active_price'])) {
@ -533,16 +568,22 @@ class ProductRepository extends BaseRepository
$ot_price_ = $value['ot_price'];
$sprice = ($value['price'] < 0) ? 0 : $value['price'];
}
if (isset($value['svip_price']) && $data['svip_price_type']) {
$svip_price = !$svip_price ? $value['svip_price'] : (($svip_price > $value['svip_price']) ? $value['svip_price'] : $svip_price);
}
$cost = !$cost ? $value['cost'] : (($cost > $value['cost']) ?$cost: $value['cost']);
$price = !$price ? $sprice : (($price > $sprice) ? $sprice : $price);
$ot_price = !$ot_price ? $ot_price_ : (($ot_price > $ot_price_) ? $ot_price : $ot_price_);
$unique = $this->setUnique($productId, $sku, $productType);
$result['attrValue'][] = [
'detail' => json_encode($value['detail'] ?? ''),
"bar_code" => $value["bar_code"] ?? '',
"image" => $value["image"],
"image" => $value["image"] ?? '',
"cost" => $value['cost'] ? (($value['cost'] < 0) ? 0 : $value['cost']) : 0,
"price" => $value['price'] ? (($value['price'] < 0) ? 0 : $value['price']) : 0,
"volume" => $value['volume'] ? (($value['volume'] < 0) ? 0 : $value['volume']) : 0,
"weight" => $value['weight'] ? (($value['weight'] < 0) ? 0 : $value['weight']) : 0,
"volume" => isset($value['volume']) ? ($value['volume'] ? (($value['volume'] < 0) ? 0 : $value['volume']) : 0) :0,
"weight" => isset($value['weight']) ? ($value['weight'] ? (($value['weight'] < 0) ? 0 : $value['weight']) : 0) :0,
"stock" => $value['stock'] ? (($value['stock'] < 0) ? 0 : $value['stock']) : 0,
"ot_price" => $value['ot_price'] ? (($value['ot_price'] < 0) ? 0 : $value['ot_price']) : 0,
"extension_one" => $extension_status ? ($value['extension_one'] ?? 0) : 0,
@ -552,27 +593,19 @@ class ProductRepository extends BaseRepository
"sku" => $sku,
"unique" => $unique,
'sales' => $isUpdate ? ($oldSku[$sku]['sales'] ?? 0) : 0,
'svip_price' => $svip_price,
];
if (!$price) $price = $sprice;
if (!$ot_price) $ot_price = $ot_price_;
if (!$cost) $cost = $value['cost'];
$ot_price = ($ot_price > $ot_price_) ? $ot_price_ : $ot_price;
$price = ($price > $sprice) ? $sprice : $price;
$cost = ($cost > $value['cost']) ? $value['cost'] : $cost;
$stock = $stock + intval($value['stock']);
}
$result['data'] = [
'price' => $price ,
'stock' => $stock,
'ot_price' => $ot_price,
'cost' => $cost
'ot_price' => $ot_price,
'cost' => $cost,
'svip_price' => $svip_price,
];
} catch (\Exception $exception) {
throw new ValidateException('商品属性格式错误');
throw new ValidateException('规格错误 '.$exception->getMessage());
}
return $result;
}
@ -611,7 +644,8 @@ class ProductRepository extends BaseRepository
'merchant'=> function($query){
$query->field('mer_id,mer_avatar,mer_name,is_trader');
},
'guarantee.templateValue.value'
'guarantee.templateValue.value',
];
$data = $this->dao->geTrashedtProduct($id)->with($with)->find();
@ -625,7 +659,7 @@ class ProductRepository extends BaseRepository
$append = [];
if ($data['product_type'] == 0) {
$append = ['us_status'];
$append = ['us_status', 'params'];
$activeId = 0;
}
if ($data['product_type'] == 1){
@ -663,6 +697,7 @@ class ProductRepository extends BaseRepository
$arr = [];
if (in_array($data['product_type'], [1, 3])) $value_make = app()->make(ProductAttrValueRepository::class);
foreach ($attrValue as $key => $item) {
if ($data['product_type'] == 1) {
$value = $value_make->getSearch(['sku' => $item['sku'], 'product_id' => $data['old_product_id']])->find();
$old_stock = $value['stock'];
@ -820,7 +855,7 @@ class ProductRepository extends BaseRepository
$count = $query->count();
$data = $query->page($page, $limit)->setOption('field', [])->field($this->filed)->select();
$data->append(['max_extension', 'min_extension', 'us_status']);
$data->append(['us_status']);
$list = hasMany(
$data ,
@ -892,9 +927,7 @@ class ProductRepository extends BaseRepository
]);
$count = $query->count();
$data = $query->page($page, $limit)->setOption('field', [])->field($this->admin_filed)->select();
$data->append(['max_extension', 'min_extension', 'us_status']);
$data->append([ 'us_status']);
$list = hasMany(
$data ,
'sys_labels',
@ -1084,10 +1117,10 @@ class ProductRepository extends BaseRepository
return $this->apiProductDetail($where, 1, null,$userInfo);
}
public function apiProductDetail(array $where, int $productType, ?int $activityId, $userInfo = null)
{
$field = 'is_show,product_id,mer_id,image,slider_image,store_name,store_info,unit_name,price,cost,ot_price,stock,sales,video_link,product_type,extension_type,old_product_id,rate,guarantee_template_id,temp_id,once_max_count,pay_limit,once_min_count,integral_rate,delivery_way,delivery_free,type,cate_id';
$field = 'is_show,product_id,mer_id,image,slider_image,store_name,store_info,unit_name,price,cost,ot_price,stock,sales,video_link,product_type,extension_type,old_product_id,rate,guarantee_template_id,temp_id,once_max_count,pay_limit,once_min_count,integral_rate,delivery_way,delivery_free,type,cate_id,svip_price_type,svip_price,mer_svip_status';
$with = [
'attr',
'content' => function($query) {
@ -1101,105 +1134,117 @@ class ProductRepository extends BaseRepository
'seckillActive' => function ($query) {
$query->field('start_day,end_day,start_time,end_time,product_id');
},
'temp',
'temp'
];
$append = ['guaranteeTemplate'];
$append = ['guaranteeTemplate','params'];
$where['product_type'] = $productType;
$res = $this->dao->getWhere($where, $field, $with);
if ($res) {
switch ($res['product_type']) {
case 0:
$append[] = 'max_integral';
break;
case 1:
$_where = $this->dao->productShow();
$_where['product_id'] = $res['old_product_id'];
$oldProduct = $this->dao->getWhere($_where);
$result = $this->getSeckillAttrValue($res['attrValue'], $res['old_product_id']);
$res['attrValue'] = $result['item'];
if (!$res) return [];
switch ($res['product_type']) {
case 0:
$append[] = 'max_integral';
$append[] = 'show_svip_info';
break;
case 1:
$_where = $this->dao->productShow();
$_where['product_id'] = $res['old_product_id'];
$oldProduct = $this->dao->getWhere($_where);
$result = $this->getSeckillAttrValue($res['attrValue'], $res['old_product_id']);
$res['attrValue'] = $result['item'];
$res['stock'] = $result['stock'];
$res['stop'] = strtotime(date('Y-m-d', time()) . $res['seckillActive']['end_time'] . ':00:00');
$res['sales'] = app()->make(StoreOrderRepository::class)->seckillOrderCounut($where['product_id']);
$res['quota'] = $this->seckillStock($where['product_id']);
$res['old_status'] = $oldProduct ? 1 : 0;
$append[] = 'seckill_status';
break;
default:
break;
}
if ($userInfo) {
$relation_make = app()->make(UserRelationRepository::class);
try {
$isRelation = $relation_make->getUserRelation(
[
'type_id' => $activityId ?? $where['product_id'],
'type' => $res['product_type']
],
$userInfo['uid']
);
} catch (\Exception $e) {
$isRelation = false;
}
$res['stock'] = $result['stock'];
$res['stop'] = strtotime(date('Y-m-d', time()) . $res['seckillActive']['end_time'] . ':00:00');
$res['sales'] = app()->make(StoreOrderRepository::class)->seckillOrderCounut($where['product_id']);
$res['quota'] = $this->seckillStock($where['product_id']);
$res['old_status'] = $oldProduct ? 1 : 0;
$append[] = 'seckill_status';
break;
default:
break;
}
if ($this->getUserIsPromoter($userInfo) && $productType == 0) {
$append[] = 'max_extension';
$append[] = 'min_extension';
}
if ($userInfo) {
try {
$isRelation = app()->make(UserRelationRepository::class)->getUserRelation(['type_id' => $activityId ?? $where['product_id'], 'type' => $res['product_type']], $userInfo['uid']);
} catch (\Exception $e) {
$isRelation = false;
}
$attr = $this->detailAttr($res['attr']);
$attrValue = (in_array($res['product_type'], [3, 4])) ? $res['oldAttrValue'] : $res['attrValue'];
$sku = $this->detailAttrValue($attrValue, $userInfo, $productType, $activityId);
$res['isRelation'] = $isRelation ?? false;
$care = false;
if ($userInfo) {
$care = app()->make(MerchantRepository::class)->getCareByUser($res['mer_id'], $userInfo->uid);
}
$res['merchant']['top_banner'] = merchantConfig($res['mer_id'], 'mer_pc_top');
$res['merchant']['care'] = $care;
$res['replayData'] = null;
if (systemConfig('sys_reply_status')){
$res['replayData'] = app()->make(ProductReplyRepository::class)->getReplyRate($res['product_id']);
$append[] = 'topReply';
}
unset($res['attr'], $res['attrValue'], $res['oldAttrValue'], $res['seckillActive']);
$res['attr'] = $attr;
$res['sku'] = $sku;
$res->append($append);
if ($res['content'] && $res['content']['type'] == 1) {
$res['content']['content'] = json_decode($res['content']['content']);
}
$res['merchant']['recommend'] = $this->getRecommend($res['product_id'], $res['mer_id']);
$spu = app()->make(SpuRepository::class)->getSpuData(
$activityId ?: $res['product_id'],
$productType,
0
);
$res['spu_id'] = $spu->spu_id;
if (systemConfig('community_status')) {
$res['community'] = app()->make(CommunityRepository::class)->getDataBySpu($spu->spu_id);
}
//热卖排行
if (systemConfig('hot_ranking_switch') && $res['spu_id']) {
$hot = $this->getHotRanking($res['spu_id'], $res['cate_id']);
$res['top_name'] = $hot['top_name'] ?? '';
$res['top_num'] = $hot['top_num'] ?? 0;
$res['top_pid'] = $hot['top_pid'] ?? 0;
}
//活动氛围图
if (in_array($res['product_type'],[0,2,4])){
$active = app()->make(StoreActivityRepository::class)->getActivityBySpu(StoreActivityRepository::ACTIVITY_TYPE_ATMOSPHERE,$res['spu_id'],$res['cate_id'],$res['mer_id']);
if ($active) $res['atmosphere_pic'] = $active['pic'];
if ($this->getUserIsPromoter($userInfo) && $productType == 0) {
$append[] = 'max_extension';
$append[] = 'min_extension';
}
}
$attr = $this->detailAttr($res['attr']);
$attrValue = (in_array($res['product_type'], [3, 4])) ? $res['oldAttrValue'] : $res['attrValue'];
$sku = $this->detailAttrValue($attrValue, $userInfo, $productType, $activityId);
$res['isRelation'] = $isRelation ?? false;
$care = false;
if ($userInfo) {
$care = app()->make(MerchantRepository::class)->getCareByUser($res['mer_id'], $userInfo->uid);
}
$res['merchant']['top_banner'] = merchantConfig($res['mer_id'], 'mer_pc_top');
$res['merchant']['care'] = $care;
$res['replayData'] = null;
if (systemConfig('sys_reply_status')){
$res['replayData'] = app()->make(ProductReplyRepository::class)->getReplyRate($res['product_id']);
$append[] = 'topReply';
}
unset($res['attr'], $res['attrValue'], $res['oldAttrValue'], $res['seckillActive']);
if (count($attr) > 0) {
$firstSku = [];
foreach ($attr as $item) {
$firstSku[] = $item['attr_values'][0];
}
$firstSkuKey = implode(',', $firstSku);
if (isset($sku[$firstSkuKey])) {
$sku = array_merge([$firstSkuKey => $sku[$firstSkuKey]], $sku);
}
}
$res['attr'] = $attr;
$res['sku'] = $sku;
$res->append($append);
if ($res['content'] && $res['content']['type'] == 1) {
$res['content']['content'] = json_decode($res['content']['content']);
}
$res['merchant']['recommend'] = $this->getRecommend($res['product_id'], $res['mer_id']);
$spu = app()->make(SpuRepository::class)->getSpuData(
$activityId ?: $res['product_id'],
$productType,
0
);
$res['spu_id'] = $spu->spu_id;
if (systemConfig('community_status')) {
$res['community'] = app()->make(CommunityRepository::class)->getDataBySpu($spu->spu_id);
}
//热卖排行
if (systemConfig('hot_ranking_switch') && $res['spu_id']) {
$hot = $this->getHotRanking($res['spu_id'], $res['cate_id']);
$res['top_name'] = $hot['top_name'] ?? '';
$res['top_num'] = $hot['top_num'] ?? 0;
$res['top_pid'] = $hot['top_pid'] ?? 0;
}
//活动氛围图
if (in_array($res['product_type'],[0,2,4])){
$active = app()->make(StoreActivityRepository::class)->getActivityBySpu(StoreActivityRepository::ACTIVITY_TYPE_ATMOSPHERE,$res['spu_id'],$res['cate_id'],$res['mer_id']);
if ($active) $res['atmosphere_pic'] = $active['pic'];
}
return $res;
}
/**
* TODO 热卖排行
* @param int $spuId
* @param int $cateId
* @return array
* @author Qinii
*/
public function getHotRanking(int $spuId, int $cateId)
{
$data = [];
@ -1283,7 +1328,7 @@ class ProductRepository extends BaseRepository
* @author Qinii
* @day 2020-08-05
*/
public function detailAttr($data, $preview = 0)
public function detailAttr($data, $preview = 0, $user = null)
{
$attr = [];
foreach ($data as $key => $item) {
@ -1296,7 +1341,6 @@ class ProductRepository extends BaseRepository
$attr[$key]['attr_values'] = $item['attr_values'];
}
$values = $item['attr_values'];
sort($values);
foreach ($values as $i => $value) {
$arr[] = [
'attr' => $value,
@ -1356,13 +1400,13 @@ class ProductRepository extends BaseRepository
* @author Qinii
* @day 2020-08-05
*/
public function detailAttrValue($data, $userInfo, $productType = 0, $artiveId = null)
public function detailAttrValue($data, $userInfo, $productType = 0, $artiveId = null, $svipInfo = [])
{
$sku = [];
$make_presll = app()->make(ProductPresellSkuRepository::class);
$make_assist = app()->make(ProductAssistSkuRepository::class);
$make_group = app()->make(ProductGroupSkuRepository::class);
foreach ($data as $k => $value) {
foreach ($data as $value) {
$_value = [
'sku' => $value['sku'],
'price' => $value['price'],
@ -1376,6 +1420,7 @@ class ProductRepository extends BaseRepository
];
if($productType == 0 ){
$_value['ot_price'] = $value['ot_price'];
$_value['svip_price'] = $value['svip_price'];
}
if ($productType == 2) {
$_sku = $make_presll->getSearch(['product_presell_id' => $artiveId, 'unique' => $value['unique']])->find();
@ -1485,37 +1530,69 @@ class ProductRepository extends BaseRepository
}
/**
* TODO 商品上下架操作
* @param array $ids
* @param string $status
* @param string $is
* TODO 上下架 / 显示
* @param $id
* @param $status
* @author Qinii
* @day 2022/9/6
* @day 2022/11/12
*/
public function switchShow($ids, string $status,string $is, int $merId)
public function switchShow($id, $status, $field, $merId = 0)
{
$extension_status = systemConfig('extension_status');
$make = app()->make(ProductAttrValueRepository::class);
$productData = $this->dao->getSearch([])->where('product_id','in', $ids)->select();
foreach ($productData as $product) {
if ($merId && $product['mer_id'] != $merId) throw new ValidateException('ID:' . $product['product_id'] . ' 商品不属于您');
if ($status == 1) {
if ($product['product_type'] == 2)
throw new ValidateException('ID:' . $product['product_id'] . ' 商品正在参与预售活动');
if ($product['product_type'] == 3)
throw new ValidateException('ID:' . $product['product_id'] . ' 商品正在参与助力活动');
}
if ($extension_status && $status == 1 && $product->extension_type == 1) {
if (!$make->checkExtensionById($product['product_id']))
throw new ValidateException('设置佣金不能低于系统比例');
}
Queue(ChangeSpuStatusJob::class, ['id' => $product['product_id'], 'product_type' => $product['product_type']]);
$where['product_id'] = $id;
if ($merId) $where['mer_id'] = $merId;
$product = $this->dao->getWhere($where);
if (!$product) throw new ValidateException('数据不存在');
if ($status == 1 && $product['product_type'] == 2)
throw new ValidateException('商品正在参与预售活动');
if ($status == 1 && $product['product_type'] == 3)
throw new ValidateException('商品正在参与助力活动');
$this->dao->update($id,[$field => $status]);
app()->make(SpuRepository::class)->changeStatus($id,0);
}
public function batchSwitchShow($id, $status, $field, $merId = 0)
{
$where['product_id'] = $id;
if ($merId) $where['mer_id'] = $merId;
$products = $this->dao->getSearch([])->where('product_id','in', $id)->select();
if (!$products)
throw new ValidateException('数据不存在');
foreach ($products as $product) {
if ($merId && $product['mer_id'] !== $merId)
throw new ValidateException('商品不属于您');
if ($status == 1 && $product['product_type'] == 2)
throw new ValidateException('ID'.$product->product_id . ' 商品正在参与预售活动');
if ($status == 1 && $product['product_type'] == 3)
throw new ValidateException('ID'.$product->product_id . ' 商品正在参与助力活动');
}
$ids = is_array($ids) ? $ids : explode(',', $ids);
if ($product['product_type']==0){
Db::name('merchant_address_product')->where('product_id','in',$ids)->update(['status'=>$status]);
}
$this->dao->updates($ids,[$is => $status]);
$this->dao->updates($id,[$field => $status]);
Queue::push(ChangeSpuStatusJob::class,['id' => $id,'product_type'=>0]);
}
/**
* TODO 商品审核
* @param $id
* @param $data
* @author Qinii
* @day 2022/11/14
*/
public function switchStatus($id,$data)
{
$product = $this->getSearch([])->find($id);
$this->dao->update($id, $data);
$status = $data['status'];
$product_type = $product->product_type;
$type = self::NOTIC_MSG[$data['status']][$product['product_type']];
$message = '您有1个' . ($product['product_type'] ? '秒杀商品' : '商品') . self::NOTIC_MSG[$data['status']]['msg'];
SwooleTaskService::merchant('notice', [
'type' => $type,
'data' => [
'title' => $status == -2 ? '下架提醒' : '审核结果',
'message' => $message,
'id' => $product['product_id']
]
], $product['mer_id']);
app()->make(SpuRepository::class)->changeStatus($id,$product_type);
}
/**
@ -1526,70 +1603,26 @@ class ProductRepository extends BaseRepository
* @author Qinii
* @day 2022/9/6
*/
public function switchStatus(array $id,array $data, $product_type = 0)
public function batchSwitchStatus(array $id,array $data)
{
$status = $data['status'];
$data['is_used'] = ($status == 1) ? 1 : 0;
$extension_status = systemConfig('extension_status');
$make = app()->make(ProductAttrValueRepository::class);
$productData = $this->getSearch([])->where('product_id','in', $id)->select();
foreach ($productData as $product) {
if ($extension_status && $status == 1 && $product->extension_type == 1) {
if (!$make->checkExtensionById($product['product_id']))
throw new ValidateException('设置佣金不能低于系统比例');
}
switch ($status) {
case 1:
$message = $product_type ? '您有1个秒杀商品审核通过' : '您有1个商品审核通过';
$type = $product_type ? 'product_seckill_success' :'product_success';
break;
case -1:
$message = $product_type ? '您有1个秒杀商品审核失败' : '您有1个商品审核失败';
$type = $product_type ? 'product_seckill_fail' :'product_fail';
break;
case -2:
$message = $product_type ? '您有1个秒杀商品被下架' : '您有1个商品被下架';
$type = $product_type ? 'product_seckill_fail' :'product_fail';
break;
}
$type = self::NOTIC_MSG[$data['status']][$product['product_type']];
$message = '您有1个' . ($product['product_type'] ? '秒杀商品' : '商品') . self::NOTIC_MSG[$data['status']]['msg'];
SwooleTaskService::merchant('notice', [
'type' => $type,
'data' => [
'title' => $status == -2 ? '下架提醒' : '审核结果',
'title' => $data['status'] == -2 ? '下架提醒' : '审核结果',
'message' => $message,
'id' => $product['product_id']
]
], $product['mer_id']);
queue(ChangeSpuStatusJob::class, ['id' => $product['product_id'], 'product_type' => $product['product_type']]);
}
$this->dao->updates($id, $data);
event('product.status',compact('id','data','product_type'));
Queue(ChangeSpuStatusJob::class, ['id' => $id, 'product_type' => $product['product_type']]);
event('product.status',compact('id','data'));
}
/**
* TODO 执行检测所有线上商品
* @author Qinii
* @day 2020-06-24
*/
public function checkProductByExtension()
{
if (systemConfig('extension_status')) {
$where = ['status' => 1, 'is_show' => 1, 'product_type' => 0];
$make = app()->make(ProductAttrValueRepository::class);
$query = $this->dao->search(null, $where)->where('extension_type', 1);
$query->chunk(100, function ($prduct) use ($make) {
foreach ($prduct as $item) {
if (!$make->checkExtensionById($item['product_id'])) {
$item->status = -2;
$item->refusal = '因佣金比例调整,商品佣金低于系统比例';
$item->save();
queue(ChangeSpuStatusJob::class, ['id' => $item['product_id'], 'product_type' => $item['product_type']]);
//app()->make(SpuRepository::class)->changeStatus($item['product_id'],$item['product_type']);
}
}
});
}
}
public function wxQrCode(int $productId, int $productType, User $user)
{
@ -1706,23 +1739,6 @@ class ProductRepository extends BaseRepository
});
}
/**
* TODO 商品验证
* @param $data
* @author Qinii
* @day 2020-08-01
*/
public function check($data, $merId)
{
if ($data['brand_id'] > 0 && !$this->merBrandExists($data['brand_id']))
throw new ValidateException('品牌不存在');
if (!$this->CatExists($data['cate_id']))
throw new ValidateException('平台分类不存在');
if (isset($data['mer_cate_id']) && !$this->merCatExists($data['mer_cate_id'], $merId))
throw new ValidateException('不存在的商户分类');
if ($data['delivery_way'] == 2 && !$this->merShippingExists($merId, $data['temp_id']))
throw new ValidateException('运费模板不存在');
}
public function fictiForm(int $id)
{
@ -2028,7 +2044,7 @@ class ProductRepository extends BaseRepository
$product['slider_image'] = explode(',',$product['slider_image']);
$product['merchant'] = $data['merchant'];
$product['content'] = ['content' => $data['content']];
$settleParams = $this->setAttrValue($data['attrValue'], 0, $productType, 0);
$settleParams = $this->setAttrValue($data, 0, $productType, 0);
$settleParams['attr'] = $this->setAttr($data['attr'], 0);
$product['price'] = $settleParams['data']['price'];
@ -2145,4 +2161,44 @@ class ProductRepository extends BaseRepository
if (!$data) throw new ValidateException('数据不存在');
return app()->make(ProductAttrValueRepository::class)->getSearch(['product_id' => $id])->select();
}
public function checkParams($data,$merId,$id = null)
{
if (!$data['pay_limit']) $data['once_max_count'] = 0;
if ($data['brand_id'] > 0 && !$this->merBrandExists($data['brand_id']))
throw new ValidateException('品牌不存在');
if (!$this->CatExists($data['cate_id']))
throw new ValidateException('平台分类不存在');
if (isset($data['mer_cate_id']) && !$this->merCatExists($data['mer_cate_id'], $merId))
throw new ValidateException('不存在的商户分类');
if ($data['delivery_way'] == 2 && !$this->merShippingExists($merId, $data['temp_id']))
throw new ValidateException('运费模板不存在');
if (isset($data['type']) && $data['type'] && $data['extend']) {
$key = ['email','text','number','date','time','idCard','mobile','image'];
if (count($data['extend']) > 10) throw new ValidateException('附加表单不能超过10条');
$title = [];
foreach ($data['extend'] as $item) {
if (empty($item['title']) )
throw new ValidateException('表单名称不能为空:'.$item['key']);
if (in_array($item['title'],$title))
throw new ValidateException('表单名称不能重复:'.$item['title']);
$title[] = $item['title'];
if (!in_array($item['key'], $key))
throw new ValidateException('表单类型错误:'.$item['key']);
$extend[] = [
'title' => $item['title'],
'key' => $item['key'] ,
'require' => $item['require'],
];
}
}
app()->make(ProductLabelRepository::class)->checkHas($merId,$data['mer_labels']);
$count = app()->make(StoreCategoryRepository::class)->getWhereCount(['store_category_id' => $data['cate_id'],'is_show' => 1]);
if (!$count) throw new ValidateException('平台分类不存在或不可用');
app()->make(StoreProductValidate::class)->check($data);
if ($id) unset($data['type']);
$data['extend'] = $extend ?? [];
//单次限购
return $data;
}
}

View File

@ -15,7 +15,6 @@ use app\common\repositories\store\coupon\StoreCouponRepository;
use app\common\repositories\store\StoreActivityRepository;
use app\common\repositories\user\UserRepository;
use crmeb\jobs\SendSmsJob;
use crmeb\jobs\SendTemplateMessageJob;
use crmeb\jobs\SyncProductTopJob;
use crmeb\services\CopyCommand;
use crmeb\services\RedisCacheService;
@ -32,7 +31,7 @@ class SpuRepository 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,P.ot_price';
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,P.ot_price,svip_price_type,stock,mer_svip_status';
public function __construct(SpuDao $dao)
{
$this->dao = $dao;
@ -44,7 +43,6 @@ class SpuRepository extends BaseRepository
return $this->dao->create($data);
}
public function baseUpdate(array $param, int $productId, int $activityId, $productType = 0)
{
if ($productType == 1) {
@ -147,10 +145,12 @@ class SpuRepository extends BaseRepository
},
'issetCoupon',
]);
$productMake = app()->make(ProductRepository::class);
$count = $query->count();
$list = $query->page($page, $limit)->setOption('field', [])->field($this->productFiled)->select();
$append[] = 'stop_time';
if (app()->make(ProductRepository::class)->getUserIsPromoter($userInfo))
$append = ['stop_time','show_svip_info','svip_price'];
if ($productMake->getUserIsPromoter($userInfo))
$append[] = 'max_extension';
$list->append($append);
$list = $this->getBorderList($list);
@ -285,7 +285,6 @@ class SpuRepository extends BaseRepository
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 ($status == 1 && $productType == 0) {
Queue(SendTemplateMessageJob::class, ['tempCode' => 'PRODUCT_INCREASE', 'id' => $id]);
Queue(SendSmsJob::class, ['tempId' => 'PRODUCT_INCREASE', 'id' => $id]);
}
if ($productType == 0) Queue::push(SyncProductTopJob::class,[]);
@ -474,6 +473,7 @@ class SpuRepository extends BaseRepository
$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);
}
@ -485,7 +485,7 @@ class SpuRepository extends BaseRepository
public function getHotRanking(int $cateId)
{
$RedisCacheService = app()->make(RedisCacheService::class);
$prefix = env('QUEUE_NAME','merchant').'_hot_ranking_';
$prefix = env('queue_name','merchant').'_hot_ranking_';
$ids = $RedisCacheService->handler()->get($prefix.'top_' . intval($cateId));
$ids = $ids ? explode(',', $ids) : [];
if (!count($ids)) {
@ -498,11 +498,8 @@ class SpuRepository extends BaseRepository
$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')->select();
$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')->select();
if ($list) $list = $list->toArray();
// usort($list, function ($a, $b) use ($ids) {
// return array_search($a['spu_id'], $ids) > array_search($b['spu_id'], $ids) ? 1 : -1;
// });
return $list;
}

View File

@ -27,27 +27,26 @@ class StoreDiscountRepository extends BaseRepository
$this->dao = $dao;
}
public function getApilist($where, $id)
public function getApilist($where)
{
$query = $this->dao->getSearch($where)
->with([
'discountsProduct' => [
'product' => [
'attr',
'attrValue',
],
'product' => function($query){
$query->where('status',1)->where('is_show',1)->where('mer_status',1)->where('is_used',1)->with([
'attr',
'attrValue',
]);
},
'productSku' => function($query) {
$query->where('active_type', 10);
},
]
])->order('sort DESC,create_time DESC');
$count = $query->count();
$data = $query->select();
$list = [];
if ($data) {
foreach ($data->toArray() as $item) {
$item['count'] = count($item['discountsProduct']);
if ($item['is_time']) {
$start_time = date('Y-m-d H:i:s',$item['start_time']);
$end_time = date('Y-m-d H:i:s', $item['stop_time']);
@ -58,11 +57,16 @@ class StoreDiscountRepository extends BaseRepository
$discountsProduct = $item['discountsProduct'];
unset($item['discountsProduct']);
$res = activeProductSku($discountsProduct, 'discounts');
$item['max_price'] = $res['price'];
$item['discountsProduct'] = $res['data'];
$list[] = $item;
$item['count'] = count($res['data']);
$count = count(explode(',',$item['product_ids']));
if ((!$item['type'] && $count == $item['count']) || ($item['type'] && $count > 1)) {
$item['max_price'] = $res['price'];
$item['discountsProduct'] = $res['data'];
$list[] = $item;
}
}
}
$count = count($list);
return compact('count', 'list');
}

View File

@ -59,7 +59,7 @@ class StoreServiceLogRepository extends BaseRepository
{
$query = $this->search(['mer_id' => $merId, 'uid' => $uid])->order('service_log_id DESC');
$count = $query->count();
$list = $query->page($page, $limit)->with(['user', 'service'])->select()->append(['send_time','send_date']);
$list = $query->page($page, $limit)->with(['user', 'service'])->select()->append(['send_time', 'send_date']);
if ($page == 1) {
$this->dao->userRead($merId, $uid);
app()->make(StoreServiceUserRepository::class)->read($merId, $uid);
@ -93,7 +93,7 @@ class StoreServiceLogRepository extends BaseRepository
{
$query = $this->search(['mer_id' => $merId, 'uid' => $toUid, 'last_id' => $last_id])->order('service_log_id DESC');
$count = $query->count();
$list = $query->page($page, $limit)->with(['user', 'service'])->select()->append(['send_time','send_date']);
$list = $query->page($page, $limit)->with(['user', 'service'])->select()->append(['send_time', 'send_date']);
if ($page == 1) {
$this->dao->serviceRead($merId, $toUid, $service_id);
app()->make(StoreServiceUserRepository::class)->read($merId, $toUid, true);

View File

@ -28,10 +28,12 @@ class CityRepository extends BaseRepository
* @Date: 2020/5/8
* @return array
*/
public function getFormatList( array $where)
public function getFormatList(array $where)
{
return formatCategory($this->dao->getAll($where)->toArray(), 'city_id','parent_id');
}
}

View File

@ -64,6 +64,8 @@ class CacheRepository extends BaseRepository
const PLATFORM_RULE = 'platform_rule';
//优惠券说明
const COUPON_AGREE = 'sys_coupon_agree';
//付费会员协议
const SYS_SVIP = 'sys_svip';
public function getAgreeList($type)
{
@ -101,6 +103,7 @@ class CacheRepository extends BaseRepository
self::CANCELLATION_PROMPT,
self::PLATFORM_RULE,
self::COUPON_AGREE,
self::SYS_SVIP,
];
}

View File

@ -45,7 +45,11 @@ class RelevanceRepository extends BaseRepository
const SCOPE_TYPE_CATEGORY = 'scope_type_category';
//指定商户
const SCOPE_TYPE_STORE = 'scope_type_store';
//价格说明关联分类
const PRICE_RULE_CATEGORY = 'price_rule_category';
//商品参数关联
const PRODUCT_PARAMES_CATE = 'product_params_cate';
protected $dao;
/**
@ -158,7 +162,6 @@ class RelevanceRepository extends BaseRepository
]);
$count = $query->count();
$list = $query->page($page, $limit)->select()->append(['is_start']);
return compact('count','list');
}
@ -180,7 +183,7 @@ class RelevanceRepository extends BaseRepository
}
]);
$count = $query->count();
$list = $query->page($page, $limit)->select();
$list = $query->page($page, $limit)->select()->append(['is_fans']);
return compact('count','list');
}
@ -192,9 +195,50 @@ class RelevanceRepository extends BaseRepository
* @author Qinii
* @day 10/28/21
*/
public function getUserStartCommunity(int $uid, int $page, int $limit)
public function getUserStartCommunity(array $where, int $page, int $limit)
{
$query = $this->dao->joinUser($uid)->with([
$query = $this->dao->joinUser($where)->with([
'community'=> function($query) use($where){
$query->with([
'author' => function($query){
$query->field('uid,real_name,status,avatar,nickname,count_start');
},
'is_start' => function($query) use ($where) {
$query->where('left_id',$where['uid']);
},
'topic' => function($query) {
$query->where('status', 1)->where('is_del',0);
$query->field('topic_id,topic_name,status,category_id,pic,is_del');
},
'relevance' => [
'spu' => function($query) {
$query->field('spu_id,store_name,image,price,product_type,activity_id,product_id');
}
],
'is_fans' => function($query) use($where){
$query->where('left_id',$where['uid']);
}]);
},
]);
$count = $query->count();
$list = $query->page($page, $limit)->select()->each(function ($item){
$item['time'] = date('m月d日', strtotime($item['create_time']));
return $item;
});
return compact('count','list');
}
/**
* TODO 我点赞过的文章
* @param int $uid
* @return \think\Collection
* @author Qinii
* @day 10/28/21
*/
public function getUserStartCommunityByVideos(array $where, int $page, int $limit)
{
$query = $this->dao->joinUser($where)->with([
'community'=> function($query) {
$query->with(['author'=> function($query) {
$query->field('uid,avatar,nickname');

View File

@ -77,23 +77,37 @@ class ConfigRepository extends BaseRepository
public function getComponent($config, $merId)
{
if ($config['config_type'] == 'image')
$component = Elm::frameImage($config['config_key'], $config['config_name'], '/' . config('admin.' . ($merId ? 'merchant' : 'admin') . '_prefix') . '/setting/uploadPicture?field=' . $config['config_key'] . '&type=1')->modal(['modal' => false])->width('896px')->height('480px')->props(['footer' => false]);
else if ($config['config_type'] == 'images') {
$component = Elm::frameImage($config['config_key'], $config['config_name'], '/' . config('admin.' . ($merId ? 'merchant' : 'admin') . '_prefix') . '/setting/uploadPicture?field=' . $config['config_key'] . '&type=2')->maxLength(5)->modal(['modal' => false])->width('896px')->height('480px')->props(['footer' => false]);
} else if ($config['config_type'] == 'file') {
$component = Elm::uploadFile($config['config_key'], $config['config_name'], rtrim(systemConfig('site_url'), '/') . Route::buildUrl('configUpload', ['field' => 'file'])->build())->headers(['X-Token' => request()->token()]);
} else if (in_array($config['config_type'], ['select', 'checkbox', 'radio'])) {
$options = array_map(function ($val) {
[$value, $label] = explode(':', $val, 2);
return compact('value', 'label');
}, explode("\n", $config['config_rule']));
$component = Elm::{$config['config_type']}($config['config_key'], $config['config_name'])->options($options);
} else if($config['config_type'] == 'switches'){
$component = Elm::{$config['config_type']}($config['config_key'], $config['config_name'])->activeText('开')->inactiveText('关');
} else
$component = Elm::{$config['config_type']}($config['config_key'], $config['config_name']);
switch ($config['config_type']) {
case 'image':
$component = Elm::frameImage($config['config_key'], $config['config_name'], '/' . config('admin.' . ($merId ? 'merchant' : 'admin') . '_prefix') . '/setting/uploadPicture?field=' . $config['config_key'] . '&type=1')->modal(['modal' => false])->width('896px')->height('480px')->props(['footer' => false]);
break;
case 'images':
$component = Elm::frameImage($config['config_key'], $config['config_name'], '/' . config('admin.' . ($merId ? 'merchant' : 'admin') . '_prefix') . '/setting/uploadPicture?field=' . $config['config_key'] . '&type=2')->maxLength(5)->modal(['modal' => false])->width('896px')->height('480px')->props(['footer' => false]);
break;
case 'file':
$component = Elm::uploadFile($config['config_key'], $config['config_name'], rtrim(systemConfig('site_url'), '/') . Route::buildUrl('configUpload', ['field' => 'file'])->build())->headers(['X-Token' => request()->token()]);
break;
case 'select':
//notbreak
case 'checkbox':
//notbreak
case 'radio':
$options = array_map(function ($val) {
[$value, $label] = explode(':', $val, 2);
return compact('value', 'label');
}, explode("\n", $config['config_rule']));
$component = Elm::{$config['config_type']}($config['config_key'], $config['config_name'])->options($options);
break;
case 'switches':
$component = Elm::{$config['config_type']}($config['config_key'], $config['config_name'])->activeText('开')->inactiveText('关');
break;
default:
$component = Elm::{$config['config_type']}($config['config_key'], $config['config_name']);
break;
}
if ($config['required']) $component->required();
$component->appendRule('suffix', [
'type' => 'div',
'style' => ['color' => '#999999'],
@ -101,6 +115,7 @@ class ConfigRepository extends BaseRepository
'innerHTML' => $config['info'],
]
]);
if ($config['config_props'] ?? '') {
$props = @parse_ini_string($config['config_props'], false, INI_SCANNER_TYPED);
if (is_array($props)) {

View File

@ -16,8 +16,14 @@ namespace app\common\repositories\system\config;
use app\common\dao\system\config\SystemConfigValueDao;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\product\ProductRepository;
use app\common\repositories\system\groupData\GroupDataRepository;
use app\common\repositories\system\groupData\GroupRepository;
use crmeb\jobs\SyncProductTopJob;
use crmeb\services\DownloadImageService;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Queue;
/**
* Class ConfigValueRepository
@ -86,11 +92,60 @@ class ConfigValueRepository extends BaseRepository
throw new ValidateException($info['config_name'] . '不能小于0');
$formData[$key] = floatval($formData[$key]);
}
$this->separate($key,$formData[$key],$merId);
}
}
$this->setFormData($formData, $merId);
}
/**
* TODO 需要做特殊处理的配置参数
* @param $key
* @author Qinii
* @day 2022/11/17
*/
public function separate($key,$value,$merId)
{
switch($key) {
case 'mer_svip_status':
//修改商户的会员状态
app()->make(ProductRepository::class)->getSearch([])->where(['mer_id' => $merId,'product_type' => 0])->update([$key => $value]);
break;
// case 'site_ico':
// //修改ico图标
// $stie_ico = systemConfig('site_ico');
// $ico = substr($value,-3);
// if ($stie_ico != $value && $ico != 'ico') {
// $path = app()->make(DownloadImageService::class)->downloadImage($value,'def','favicon.ico',1)['path'];
// $value = public_path().$path;
// if (!is_file($value)) throw new ValidateException('Ico图标文件不存在');
// rename($value, public_path() . 'favicon.ico');
// }
// break;
//热卖排行
case 'hot_ranking_switch':
if ($value) {
Queue::push(SyncProductTopJob::class, []);
}
break;
case 'svip_switch_status':
if ($value == 1) {
$groupDataRepository = app()->make(GroupDataRepository::class);
$groupRepository = app()->make(GroupRepository::class);
$group_id = $groupRepository->getSearch(['group_key' => 'svip_pay'])->value('group_id');
$where['group_id'] = $group_id;
$where['status'] = 1;
$count = $groupDataRepository->getSearch($where)->field('group_data_id,value,sort,status')->count();
if (!$count)
throw new ValidateException('请先添加会员类型');
}
break;
default:
break;
}
return ;
}
public function setFormData(array $formData, int $merId)
{
Db::transaction(function () use ($merId, $formData) {

View File

@ -127,11 +127,13 @@ class FinancialRepository extends BaseRepository
[
'type' => 'span',
'title' => '商户名称:',
'native' => false,
'children' => [$merchant->mer_name]
],
[
'type' => 'span',
'title' => '商户ID:',
'native' => false,
'children' => ["$merId"]
],
// [
@ -142,15 +144,18 @@ class FinancialRepository extends BaseRepository
[
'type' => 'span',
'title' => '提示:',
'native' => false,
'children' => ['最低可提现额度:'.$extract_minimum_line.'元;最低提现金额:'.$extract_minimum_num.'元']
],
[
'type' => 'span',
'title' => '商户余额:',
'native' => false,
'children' => [$merchant->mer_money]
],
[
'type' => 'span',
'native' => false,
'title' => '商户可提现金额:',
'children' => [$_extract]
],

View File

@ -320,4 +320,67 @@ class GroupDataRepository extends BaseRepository
$this->dao->insertAll($insert);
}
}
public function reSetDataForm(int $groupId, ?int $id, ?int $merId)
{
$formData = [];
if (is_null($id)) {
$url = is_null($merId)
? Route::buildUrl('groupDataCreate', compact('groupId'))->build()
: Route::buildUrl('merchantGroupDataCreate', compact('groupId'))->build();
} else {
$data = $this->dao->getSearch([])->find($id);
if (!$data) throw new ValidateException('数据不存在');
$formData = $data->value;
$formData['status'] = $data->status;
$formData['sort'] = $data->sort;
$url = is_null($merId)
? Route::buildUrl('systemUserSvipTypeUpdate', compact('groupId','id'))->build()
: Route::buildUrl('merchantGroupDataUpdate', compact('groupId','id'))->build();
}
$form = Elm::createForm($url);
$rules = [
Elm::input('svip_name', '会员名')->required(),
Elm::radio('svip_type', '会员类别', '2')
->setOptions([
['value' => '1', 'label' => '试用期',],
['value' => '2', 'label' => '有限期',],
['value' => '3', 'label' => '永久期',],
])->control([
[
'value' => '1',
'rule' => [
Elm::number('svip_number', '有效期(天)')->required()->min(0),
]
],
[
'value' =>'2',
'rule' => [
Elm::number('svip_number', '有效期(天)')->required()->min(0),
]
],
[
'value' => '3',
'rule' => [
Elm::input('svip_number1', '有效期(天)','永久期')->disabled(true),
Elm::input('svip_number', '有效期(天)','永久期')->hiddenStatus(true),
]
],
])->appendRule('suffix', [
'type' => 'div',
'style' => ['color' => '#999999'],
'domProps' => [
'innerHTML' =>'试用期每个用户只能购买一次,购买过付费会员之后将不在展示,不可购买',
]
]),
Elm::number('cost_price', '原价')->required(),
Elm::number('price', '优惠价')->required(),
Elm::number('sort', '排序'),
Elm::switches('status', '是否显示')->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
];
$form->setRule($rules);
if ($formData && $formData['svip_type'] == 3) $formData['svip_number'] = '永久期';
return $form->setTitle(is_null($id) ? '添加' : '编辑')->formData($formData);
}
}

View File

@ -83,7 +83,7 @@ class FinancialRecordRepository extends BaseRepository
//平台收入
$income = $this->dao->search($where)->where('financial_type','in',['order','order_presell','presell'])->sum('number');
//平台支出
$expend = $this->dao->search($where)->where('financial_type','in',['brokerage_one','brokerage_two','order_true','refund_charge','presell_true'])->sum('number');
$expend = $this->dao->search($where)->where('financial_type','in',['brokerage_one','brokerage_two','order_true','refund_charge','presell_true','order_platform_coupon','order_svip_coupon'])->sum('number');
$msg = '平台';
}
$data = [
@ -124,6 +124,8 @@ class FinancialRecordRepository extends BaseRepository
$charge_ = $this->dao->search($where)->where('financial_type','in',['order_charge','presell_charge'])->sum('number');
$_charge = $this->dao->search($where)->where('financial_type','refund_charge')->sum('number');
$charge = bcsub($charge_,$_charge,2);
//优惠券费用 ,'order_platform_coupon','order_svip_coupon'
$coupon = $this->dao->search($where)->where('financial_type','in',['order_platform_coupon','order_svip_coupon'])->sum('number');
//充值金额
$bill_where = [
'status' => 1,
@ -184,6 +186,12 @@ class FinancialRecordRepository extends BaseRepository
'count' => $mer_number,
'field' => '个',
'name' => '产生交易的商户数'
],
[
'className' => 'el-icon-s-goods',
'count' => $coupon,
'field' => '元',
'name' => '优惠券金额'
]
];
return compact('stat');
@ -200,6 +208,8 @@ class FinancialRecordRepository extends BaseRepository
{
//商户收入
$count = $this->dao->search($where)->where('financial_type','in',['order','mer_presell'])->sum('number');
//平台优惠券
$coupon = $this->dao->search($where)->where('financial_type','in',['order_platform_coupon','order_svip_coupon'])->sum('number');
//商户余额
$mer_money = app()->make(MerchantRepository::class)->search(['mer_id' => $where['is_mer']])->value('mer_money');
//最低提现额度
@ -217,7 +227,7 @@ class FinancialRecordRepository extends BaseRepository
$order_charge = $this->dao->search($where)->where('financial_type','refund_charge')->sum('number');
$charge = bcsub($refund_true,$order_charge,2);
//商户可提现金额
$bill_order = app()->make(StoreOrderRepository::class)->search(['paid' => 1,'date' => $where['date'],'pay_type' => 0])->sum('pay_price');
// $bill_order = app()->make(StoreOrderRepository::class)->search(['paid' => 1,'date' => $where['date'],'pay_type' => 0])->sum('pay_price');
$merLockMoney = app()->make(UserBillRepository::class)->merchantLickMoney($where['is_mer']);
$stat = [
[
@ -256,6 +266,12 @@ class FinancialRecordRepository extends BaseRepository
'field' => '元',
'name' => '平台手续费'
],
[
'className' => 'el-icon-s-cooperation',
'count' => $coupon,
'field' => '元',
'name' => '平台优惠券补贴'
],
[
'className' => 'el-icon-s-cooperation',
'count' => $merLockMoney,
@ -295,10 +311,9 @@ class FinancialRecordRepository extends BaseRepository
$query = $this->dao->search($where)->field($field)->group("time")->order('create_time DESC');
$count = $query->count();
$list = $query->page($page,$limit)->select()
->each(function ($item) use($where,$make){
$key = $where['is_mer'] ? $where['is_mer'].'_financial_record_list_'.$item['time'] : 'sys_financial_record_list_'.$item['time'];
$list = $query->page($page,$limit)->select()->each(function ($item) use($where){
$key = $where['is_mer'] ? $where['is_mer'].'_financial_record_list_'.$item['time'] : 'sys_financial_record_list_'.$item['time'];
if(($where['type'] == 1 && ($item['time'] == date('Y-m-d',time()))) || ($where['type'] == 2 && ($item['time'] == date('Y-m',time())))){
$income = ($this->countIncome($where['type'],$where,$item['time']))['number'] ;
$expend = ($this->countExpend($where['type'],$where,$item['time']))['number'] ;
@ -352,6 +367,7 @@ class FinancialRecordRepository extends BaseRepository
'data' => [
['订单支付', $income['number_order'].'元', $income['count_order'].'笔'],
['退回优惠券补贴', $income['number_coupon'].'元', $income['count_coupon'].'笔'],
['退回会员优惠券补贴', $income['number_svipcoupon'].'元', $income['count_svipcoupon'].'笔'],
]
];
$data['bill'] = [
@ -369,6 +385,7 @@ class FinancialRecordRepository extends BaseRepository
['佣金', $expend['number_brokerage'] .'元', $expend['count_brokerage'].'笔'],
['返还手续费', $expend['number_charge'] .'元', $expend['count_charge'].'笔'],
['优惠券补贴',$expend['number_coupon'] .'元', $expend['count_coupon'].'笔'],
['会员优惠券补贴',$expend['number_svipcoupon'] .'元', $expend['count_svipcoupon'].'笔'],
]
];
$data['charge'] = [
@ -404,6 +421,7 @@ class FinancialRecordRepository extends BaseRepository
'data' => [
['订单支付', $income['number_order'].'元', $income['count_order'].'笔'],
['优惠券补贴', $income['number_coupon'].'元', $income['count_coupon'].'笔'],
['会员优惠券补贴', $income['number_svipcoupon'].'元', $income['count_svipcoupon'].'笔'],
]
];
$data['expend'] = [
@ -431,6 +449,11 @@ class FinancialRecordRepository extends BaseRepository
$expend['number_coupon'] .'元',
$expend['count_coupon'].'笔'
],
[
'退还会员优惠券补贴',
$expend['number_svipcoupon'] .'元',
$expend['count_svipcoupon'].'笔'
],
]
];
$data['charge'] = [
@ -462,6 +485,13 @@ class FinancialRecordRepository extends BaseRepository
}
[ $data['count_coupon'], $data['number_coupon']] = $this->dao->getDataByType($type, $where, $date, $financialType);
if ($where['is_mer']){
$financialType = ['order_svip_coupon'];
} else {
$financialType = ['refund_svip_coupon'];
}
[ $data['count_svipcoupon'], $data['number_svipcoupon']] = $this->dao->getDataByType($type, $where, $date, $financialType);
$data['count'] = $data['count_order'];
$data['number'] = bcadd($data['number_coupon'],$data['number_order'],2);
@ -495,7 +525,7 @@ class FinancialRecordRepository extends BaseRepository
}
/**
* TODO 平台总支
* TODO 平台总支
* @param $type
* @param $date
* @return array
@ -535,6 +565,9 @@ class FinancialRecordRepository extends BaseRepository
//退回给平台的优惠券金额
$financialType = ['refund_platform_coupon'];
[$data['count_coupon'], $data['number_coupon']] = $this->dao->getDataByType($type, $where, $date, $financialType);
//退回给平台的会员优惠券金额
$financialType = ['refund_svip_coupon'];
[$data['count_svipcoupon'], $data['number_svipcoupon']] = $this->dao->getDataByType($type, $where, $date, $financialType);
//佣金 brokerage_one,brokerage_two - 退回佣金 refund_brokerage_two,refund_brokerage_one
$number = bcsub($data['number_brokerage'],$data['number_refund_brokerage'],3);
@ -543,9 +576,9 @@ class FinancialRecordRepository extends BaseRepository
$number_1 = bcsub($data['number_order_charge'],$data['number_charge'],3);
//退回收入 refund_order + 退回佣金
$number_2 = bcadd($data['number_refund'],$data['number_coupon'],2);
$number_2 = bcadd(bcadd($data['number_refund'],$data['number_coupon'],2),$data['number_svipcoupon'],2);
$data['count'] = $data['count_brokerage'] + $data['count_refund'] + $data['count_order_charge'] + $data['count_refund'] + $data['count_refund_brokerage'];
$data['count'] = $data['count_brokerage'] + $data['count_refund'] + $data['count_order_charge'] + $data['count_refund'] + $data['count_refund_brokerage'] + $data['count_svipcoupon'];
$data['number'] =bcadd(bcadd($number_2,$number,3),$number_1,2);
}else{ //平台的
@ -558,8 +591,12 @@ class FinancialRecordRepository extends BaseRepository
$financialType = ['order_platform_coupon'];
[$data['count_coupon'], $data['number_coupon']] = $this->dao->getDataByType($type, $where, $date, $financialType);
$number = bcadd($data['number_brokerage'],$data['number_order'],3);
$number_1 = bcadd($number,$data['number_coupon'],3);
//付给商户的svip优惠券抵扣金额
$financialType = ['order_svip_coupon'];
[$data['count_svipcoupon'], $data['number_svipcoupon']] = $this->dao->getDataByType($type, $where, $date, $financialType);
$number = bcadd($data['number_brokerage'],$data['number_order'],2);
$number_1 = bcadd(bcadd($number,$data['number_coupon'],2),$data['number_svipcoupon'],2);
$data['count'] = $data['count_brokerage'] + $data['count_order'] + $data['count_charge'];
$data['number'] = bcadd($number_1,$data['number_charge'],2);

View File

@ -15,6 +15,7 @@ namespace app\common\repositories\system\merchant;
use app\common\dao\system\merchant\MerchantAppymentsDao;
use app\common\model\system\merchant\MerchantApplyments;
use app\common\repositories\BaseRepository;
use crmeb\jobs\SendSmsJob;
use crmeb\services\ImageWaterMarkService;
use crmeb\services\SmsService;
use crmeb\services\UploadService;
@ -488,7 +489,6 @@ class MerchantApplymentsRepository extends BaseRepository
public function sendSms(MerchantApplyments $ret,$type)
{
if(!systemConfig('applyments_sms')) return ;
$sms = SmsService::create();
$info = json_decode($ret['info']);
switch ($type)
{
@ -508,11 +508,7 @@ class MerchantApplymentsRepository extends BaseRepository
return ;
break;
}
try{
$sms->send($info->contact_info->mobile_phone, $tmp, ['mer_name' => $info->merchant_shortname]);
} catch (Exception $exception) {
}
Queue::push(SendSmsJob::class,['tempId' => $tmp, 'id' => ['phone'=> $info->contact_info->mobile_phone, 'mer_name' => $info->merchant_shortname]]);
}
/**

View File

@ -113,9 +113,9 @@ class MerchantIntentionRepository extends BaseRepository
$margin = app()->make(MerchantTypeRepository::class)->get($intention['mer_type_id']);
$data['is_margin'] = $margin['is_margin'] ?? -1;
$data['margin'] = $margin['margin'] ?? 0;
$merData = $smsData = [];
$merData = [];
if ($create) {
$password = substr(md5(time() . $intention['phone']), 0, 8);
$password = substr($intention['phone'], -6);
$merData = [
'mer_name' => $intention['mer_name'],
'mer_phone' => $intention['phone'],
@ -132,32 +132,34 @@ class MerchantIntentionRepository extends BaseRepository
'margin' => $margin['margin'] ?? 0
];
if ($data['status'] == 1) {
$data['fail_msg'] = '';
$smsData = [
'date' => date('m月d日', strtotime($intention->create_time)),
'mer' => $intention['mer_name'],
'phone' => $intention['phone'],
'pwd' => $password,
'pwd' => $password ?? '',
'site_name' => systemConfig('site_name'),
];
} else {
$smsData = [
'date' => date('m月d日', strtotime($intention->create_time)),
'mer' => $intention['mer_name'],
'site' => systemConfig('site_name'),
];
}
}
if ($data['status'] == 2) {
$smsData = [
'phone' => $intention['phone'],
'date' => date('m月d日', strtotime($intention->create_time)),
'mer' => $intention['mer_name'],
'site' => systemConfig('site_name'),
];
}
Db::transaction(function () use ($config, $intention, $data, $create,$margin,$merData,$smsData) {
if ($data['status'] == 1) {
$data['fail_mag'] = '';
if ($create) {
$merchant = app()->make(MerchantRepository::class)->createMerchant($merData);
$data['mer_id'] = $merchant->mer_id;
SmsService::create()->send($intention['phone'], 'APPLY_MER_SUCCESS', $smsData);
Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_SUCCESS', 'id' => $smsData]);
}
} else {
SmsService::create()->send($intention['phone'], 'APPLY_MER_FAIL', $smsData);
Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_FAIL', 'id' => $smsData]);
}
$intention->save($data);
});

View File

@ -130,6 +130,8 @@ class MerchantRepository extends BaseRepository
})->requiredNum(),
Elm::select('type_id', '店铺类型')->disabled($is_margin)->options($options)->requiredNum()->col(12)->control($margin),
Elm::cascader('geo_street', '商圈')->options(function () {
$slect=Db::name('geo_area')->where('city_code','510500')
->withAttr('children',function ($value,$data){
@ -248,6 +250,7 @@ class MerchantRepository extends BaseRepository
$account = $data['mer_account'];
$password = $data['mer_password'];
unset($data['mer_account'], $data['mer_password']);
$merchant = $this->dao->create($data);
$make->createMerchantAccount($merchant, $account, $password);
Db::name('merchant_address')->insert(['mer_id'=>$merchant->mer_id,'street_id'=>$data['geo_street']]);
@ -295,7 +298,10 @@ class MerchantRepository extends BaseRepository
if ($status && $item['lat'] && $item['long'] && isset($where['location']['lat'], $where['location']['long'])) {
$distance = getDistance($where['location']['lat'], $where['location']['long'], $item['lat'], $item['long']);
if ($distance < 0.9) {
$distance = max(bcmul($distance, 1000, 0), 1) . 'm';
$distance = max(bcmul($distance, 1000, 0), 1).'m';
if ($distance == '1m') {
$distance = '100m以内';
}
} else {
$distance .= 'km';
}

View File

@ -16,6 +16,9 @@ namespace app\common\repositories\system\notice;
use app\common\dao\system\notice\SystemNoticeConfigDao;
use app\common\repositories\BaseRepository;
use crmeb\exceptions\WechatException;
use crmeb\services\MiniProgramService;
use crmeb\services\WechatService;
use FormBuilder\Factory\Elm;
use think\exception\ValidateException;
use think\facade\Route;
@ -38,7 +41,7 @@ class SystemNoticeConfigRepository extends BaseRepository
{
$query = $this->dao->getSearch($where);
$count = $query->count();
$list = $query->page($page, $limit)->order('create_time DESC')->select();
$list = $query->page($page, $limit)->order('create_time ASC')->select();
return compact('count', 'list');
}
@ -82,6 +85,9 @@ class SystemNoticeConfigRepository extends BaseRepository
['value' => 0, 'label' => '用户'],
['value' => 1, 'label' => '商户'],
])->requiredNum(),
Elm::textarea('sms_content','短信内容'),
Elm::textarea('wechat_content','公众号模板内容'),
Elm::textarea('routine_content','小程序订阅消息内容'),
]);
return $form->setTitle(is_null($id) ? '添加通知' : '编辑通知')->formData($formData);
@ -143,40 +149,130 @@ class SystemNoticeConfigRepository extends BaseRepository
return $this->dao->getNoticeStatusByKey($key, 'notice_routine');
}
public function getSmsTemplate(string $key)
{
$temp = $this->dao->getWhere(['const_key' => $key]);
if ($temp && $temp['notice_sms'] == 1) {
return systemConfig('sms_use_type') == 2 ? $temp['sms_ali_tempid'] : $temp['sms_tempid'];
}
return '';
}
/**
* TODO 编辑阿里云短信模板ID
* TODO 编辑消息模板ID
* @param $id
* @return \FormBuilder\Form
* @author Qinii
* @day 6/9/22
*/
public function getTemplateIdForm($id)
public function changeForm($id)
{
$formData = $this->dao->get($id);
if ($formData['notice_sms'] == -1)
throw new ValidateException('此项无短信消息');
if (!$formData) throw new ValidateException('数据不存在');
$form = Elm::createForm(Route::buildUrl('systemNoticeConfigSetChangeTempId', ['id' => $id])->build());
$children = [];
$value = '';
if ($formData->notice_sms != -1) {
$value = 'sms';
if (systemConfig('sms_use_type') == 2) {
$sms = [
'type' => 'el-tab-pane',
'props' => [
'label' => '阿里云短信',
'name' => 'sms'
],
'children' =>[
Elm::input('title','通知类型', $formData->notice_title)->disabled(true),
Elm::input('info','场景说明', $formData->notice_info)->disabled(true),
Elm::input('sms_ali_tempid','短信模板ID'),
Elm::input('notice_info','短信说明')->disabled(true),
Elm::textarea('sms_content','短信内容')->disabled(true),
Elm::switches('notice_sms', '是否开启', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
]
];
} else {
$sms = [
'type' => 'el-tab-pane',
'props' => [
'label' => '一号通短信',
'name' => 'sms'
],
'children' =>[
Elm::input('title','通知类型', $formData->notice_title)->disabled(true),
Elm::input('info','场景说明', $formData->notice_info)->disabled(true),
Elm::input('sms_tempid','短信模板ID'),
Elm::input('notice_info','短信说明')->disabled(true),
Elm::textarea('sms_content','短信内容')->disabled(true),
Elm::switches('notice_sms', '是否开启', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
]
];
}
$children[] = $sms;
}
if ($formData->notice_wechat != -1 && $formData->wechatTemplate ) {
if (!$value) $value = 'wechat';
$children[] = [
'type' => 'el-tab-pane',
'props' => [
'label' => '模板消息',
'name' => 'wechat'
],
'children' =>[
Elm::input('title1','通知类型', $formData->wechatTemplate->name)->disabled(true),
Elm::input('info1','场景说明', $formData->notice_info)->disabled(true),
Elm::input('wechat_tempkey','模板消息编号', $formData->wechatTemplate->tempkey)->disabled(true),
Elm::input('wechat_tempid','模板消息ID', $formData->wechatTemplate->tempid),
Elm::textarea('wechat_content','模板消息内容', $formData->wechatTemplate->content)->disabled(true),
Elm::switches('notice_wechat', '是否开启', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
]
];
}
if ($formData->notice_routine != -1 && $formData->routineTemplate) {
if (!$value) $value = 'routine';
$children[] = [
'type' => 'el-tab-pane',
'props' => [
'label' => '订阅消息',
'name' => 'routine'
],
'children' =>[
Elm::input('title2','通知类型', $formData->routineTemplate->name)->disabled(true),
Elm::input('info2','场景说明', $formData->notice_info)->disabled(true),
Elm::input('routine_tempkey','订阅消息编号', $formData->routineTemplate->tempkey)->disabled(true),
Elm::input('routine_tempid','订阅消息ID', $formData->routineTemplate->tempid),
Elm::textarea('routine_content','订阅消息内容', $formData->routineTemplate->content)->disabled(true),
Elm::switches('notice_routine', '是否开启', $formData->notice_routine)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
]
];
}
$form->setRule([
Elm::input('notice_title','消息名称')->disabled(true),
Elm::input('aliyun_temp_id','阿里云模板ID'),
Elm::input('notice_info','消息说明'),
Elm::textarea('sms_content','短信内容')->disabled(true),
Elm::switches('status','状态',1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
[
'type' => 'el-tabs',
'native' => true,
'props' => [
'value' => $value
],
'children' => $children
]
]);
return $form->setTitle( '编辑短信ID')->formData($formData->toArray());
return $form->setTitle( '编辑消息模板')->formData($formData->toArray());
}
public function getSmsTemplate(string $key)
public function save($id, $data)
{
$temp = $this->dao->getWhere(['const_key' => $key]);
if ($temp && $temp['notice_sms'] == 1 && systemConfig('sms_use_type') == 2) {
return $temp['aliyun_temp_id'];
} else {
return '';
}
$result = $this->dao->get($id);
if (isset($data['routine_tempid'])) {
$result->routineTemplate->tempid = $data['routine_tempid'];
$result->routineTemplate->save();
unset($data['routine_tempid']);
}
if (isset($data['wechat_tempid'])) {
$result->wechatTemplate->tempid = $data['wechat_tempid'];
$result->wechatTemplate->save();
unset($data['wechat_tempid']);
}
if (!empty($data)) $this->dao->update($id,$data);
}
}

View File

@ -11,10 +11,14 @@
namespace app\common\repositories\system\serve;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\AddShortUrlResponseBody\data;
use app\common\dao\system\serve\ServeOrderDao;
use app\common\model\system\serve\ServeOrder;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\product\ProductCopyRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use app\common\repositories\user\UserRepository;
use crmeb\services\CombinePayService;
use crmeb\services\PayService;
use think\exception\ValidateException;
use think\facade\Cache;
@ -29,6 +33,15 @@ class ServeOrderRepository extends BaseRepository
{
$this->dao = $dao;
}
//复制商品
const TYPE_COPY_PRODUCT = 1;
//电子面单
const TYPE_DUMP = 2;
//保证金 margin
const TYPE_MARGIN = 10;
//同城配送delivery
const TYPE_DELIVERY = 20;
/**
* TODO 购买一号通 支付
@ -100,9 +113,7 @@ class ServeOrderRepository extends BaseRepository
public function delivery($merId, $data)
{
$key = 'Delivery_'.$merId.'_'.md5(date('YmdH',time()).$data['price']);
$arr = [
'price' => $data['price']
];
$arr = ['price' => $data['price']];
$param = [
'status' => 0,
'is_del' => 0,
@ -125,11 +136,11 @@ class ServeOrderRepository extends BaseRepository
$param = $res['param'];
if(!$result = Cache::store('file')->get($key)){
$order_sn = $this->setOrderSn();
$order_sn = $this->setOrderSn(null);
$param['order_sn'] = $order_sn;
$param['body'] = $order_sn;
$type = $data['pay_type'] == 1 ? 'weixinQr' : 'alipayQr';
$service = new PayService($type,$param);
$payType = $data['pay_type'] == 1 ? 'weixinQr' : 'alipayQr';
$service = new PayService($payType,$param);
$code = $service->pay(null);
$endtime = time() + 1800 ;
@ -148,29 +159,28 @@ class ServeOrderRepository extends BaseRepository
public function paySuccess($data)
{
$dat = Cache::store('file')->get($data['order_sn']);
$get = $this->dao->getWhere(['order_sn' => $data['order_sn']]);
if(!$get){
Db::transaction(function () use($data, $dat){
$key = $dat['key'];
unset($dat['attach'],$dat['body'],$dat['key']);
$dat['status'] = 1;
$this->dao->create($dat);
$this->payAfter($dat);
$dat = Cache::store('file')->get($data['order_sn']);
$key = $dat['key'];
unset($dat['attach'],$dat['body'],$dat['key']);
$dat['status'] = 1;
$dat['pay_time'] = date('y_m-d H:i:s', time());
Db::transaction(function () use($data, $dat,$key){
$res = $this->dao->create($dat);
$this->payAfter($dat,$res);
Cache::store('file')->delete($data['order_sn']);
Cache::store('file')->delete($key);
});
}
}
public function payAfter($dat)
public function payAfter($dat, $ret = null)
{
$info = json_decode($dat['order_info']);
switch ($dat['type']) {
case 1:
case self::TYPE_COPY_PRODUCT:
app()->make(ProductCopyRepository::class)->add([
'type' => 'pay_copy',
'num' => $info->num,
@ -178,15 +188,10 @@ class ServeOrderRepository extends BaseRepository
'message' => '购买复制商品套餐' ,
],$dat['mer_id']);
break;
case 2:
app()->make(ProductCopyRepository::class)->add([
'type' => 'pay_dump',
'num' => $info->num,
'info' => $dat['order_info'],
'message' => '购买电子面单套餐',
],$dat['mer_id']);
case self::TYPE_DUMP:
app()->make(ProductCopyRepository::class)->add(['type' => 'pay_dump', 'num' => $info->num, 'info' => $dat['order_info'], 'message' => '购买电子面单套餐',],$dat['mer_id']);
break;
case 10:
case self::TYPE_MARGIN:
$res = app()->make(MerchantRepository::class)->get($dat['mer_id']);
if (bccomp($res['margin'] , $dat['pay_price'], 2) === 0) {
$res->ot_margin = $res['margin'];
@ -196,7 +201,7 @@ class ServeOrderRepository extends BaseRepository
}
$res->save();
break;
case 20:
case self::TYPE_DELIVERY:
$res = app()->make(MerchantRepository::class)->get($dat['mer_id']);
if ($res) {
$res->delivery_balance = bcadd($res->delivery_balance, $dat['pay_price'],2);
@ -204,7 +209,6 @@ class ServeOrderRepository extends BaseRepository
} else {
Log::info('同城配送充值异常 '. json_encode($dat));
}
break;
default:
break;
@ -212,11 +216,11 @@ class ServeOrderRepository extends BaseRepository
return ;
}
public function setOrderSn()
public function setOrderSn($profix)
{
list($msec, $sec) = explode(' ', microtime());
$msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
$orderId = 'cs' . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
$orderId = ($profix ?:'cs') . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
return $orderId;
}
@ -233,5 +237,4 @@ class ServeOrderRepository extends BaseRepository
$list = $query->page($page, $limit)->select();
return compact('count','list');
}
}

View File

@ -26,6 +26,31 @@ use think\facade\Route;
class MemberinterestsRepository extends BaseRepository
{
const TYPE_FREE = 1;
//付费会员
const TYPE_SVIP = 2;
const HAS_TYPE_PRICE = 1;
const HAS_TYPE_SIGN = 2;
const HAS_TYPE_PAY = 3;
const HAS_TYPE_SERVICE = 4;
const HAS_TYPE_MEMBER = 5;
const HAS_TYPE_COUPON = 6;
//签到收益
const INTERESTS_TYPE = [
1 => ['label'=> '会员特价', 'msg' => ''],
2 => ['label'=> '签到返利' , 'msg' => '积分倍数' ],
3 => ['label'=> '消费返利' , 'msg' => '积分倍数' ],
4 => ['label'=> '专属客服' , 'msg' => '' ],
5 => ['label'=> '经验翻倍' , 'msg' => '经验翻倍' ],
6 => ['label'=> '会员优惠券', 'msg' => ''],
];
public function __construct(MemberInterestsDao $dao)
{
@ -40,19 +65,22 @@ class MemberinterestsRepository extends BaseRepository
return compact('count','list');
}
public function form(?int $id = null)
public function getSvipInterestVal($has_type)
{
return max(((float)$this->dao->query(['status' => 1])->where('has_type', $has_type)->where('type', 2)->value('value')) ?: 0, 0);
}
public function form(?int $id = null, $type = self::TYPE_FREE)
{
$formData = [];
if ($id) {
$form = Elm::createForm(Route::buildUrl('systemUserMemberInterestsUpdate', ['id' => $id])->build());
$data = $this->dao->get($id);
if (!$data) throw new ValidateException('数据不存在');
$form = Elm::createForm(Route::buildUrl('systemUserMemberInterestsUpdate', ['id' => $id])->build());
$formData = $data->toArray();
} else {
$form = Elm::createForm(Route::buildUrl('systemUserMemberInterestsCreate')->build());
}
$rules = [
Elm::input('name', '权益名称')->required(),
Elm::input('info', '权益简介')->required(),
@ -61,8 +89,8 @@ class MemberinterestsRepository extends BaseRepository
->modal(['modal' => false])
->width('896px')
->height('480px'),
Elm::select('brokerage_level', '会员级别')->options(function () {
$options = app()->make(UserBrokerageRepository::class)->options(['type' => 1])->toArray();
Elm::select('brokerage_level', '会员级别')->options(function () use($type){
$options = app()->make(UserBrokerageRepository::class)->options(['type' => $type])->toArray();
return $options;
}),
];
@ -70,18 +98,52 @@ class MemberinterestsRepository extends BaseRepository
return $form->setTitle(is_null($id) ? '添加权益' : '编辑权益')->formData($formData);
}
public function getInterestsByLevel(int $level, int $type)
public function getInterestsByLevel(int $type, $level = 0)
{
return [];
if (systemConfig('member_interests_status')) return [];
$list = $this->dao->getSearch(['type' => $type])->select();
foreach ($list as $item) {
$item['status'] = 0;
if ($item['brokerage_level'] <= $level) {
$item['status'] = 1;
if ($type == self::TYPE_FREE) {
$list = $this->dao->getSearch(['type' => $type])->select();
foreach ($list as $item) {
$item['status'] = 0;
if ($item['brokerage_level'] <= $level) {
$item['status'] = 1;
}
}
} else {
$list = $this->dao->getSearch(['type' => $type,'status' => 1])->select();
}
return $list;
}
public function svipForm(int $id)
{
$data = $this->dao->get($id);
if (!$data) throw new ValidateException('数据不存在');
$form = Elm::createForm(Route::buildUrl('systemUserSvipInterestsUpdate', ['id' => $id])->build());
$formData = $data->toArray();
$rules = [
Elm::select('has_type', '权益名称')->options(function(){
foreach (self::INTERESTS_TYPE as $k => $v) {
$res[] = ['value' => $k, 'label' => $v['label']];
}
return $res;
})->disabled(true),
Elm::input('name', '展示名称')->required(),
Elm::input('info', '权益简介')->required(),
Elm::frameImage('pic', '未开通图标', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=pic&type=1')
->value($formData['pic'] ?? '')->required()
->modal(['modal' => false])
->width('896px')
->height('480px'),
Elm::frameImage('on_pic', '已开通图标', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=on_pic&type=1')
->value($formData['on_pic'] ?? '')->required()
->modal(['modal' => false])
->width('896px')
->height('480px'),
Elm::input('link', '跳转内部链接'),
];
$msg = self::INTERESTS_TYPE[$formData['has_type']]['msg'];
if ($msg) $rules[] = Elm::number('value',$msg,0);
$form->setRule($rules);
return $form->setTitle('编辑会员权益')->formData($formData);
}
}

View File

@ -17,12 +17,8 @@ namespace app\common\repositories\user;
use app\common\dao\BaseDao;
use app\common\dao\user\UserBillDao;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\store\order\StoreRefundOrderRepository;
use app\common\repositories\store\product\ProductRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use crmeb\jobs\SendTemplateMessageJob;
use think\exception\ValidateException;
use crmeb\jobs\SendSmsJob;
use think\facade\Queue;
use think\Model;
@ -132,8 +128,7 @@ class UserBillRepository extends BaseRepository
$data['pm'] = $pm;
$bill = $this->dao->create($data);
if($category == 'now_money'){
$tempData = ['tempCode' => 'USER_BALANCE_CHANGE','id' => $bill->bill_id];
Queue::push(SendTemplateMessageJob::class,$tempData);
Queue::push(SendSmsJob::class,['tempId' => 'USER_BALANCE_CHANGE','id' => $bill->bill_id]);
}
return $bill;
}

View File

@ -177,6 +177,13 @@ class UserBrokerageRepository extends BaseRepository
];
$inc = systemConfig($type) > 0 ? systemConfig($type) : 0;
$user = app()->make(UserRepository::class)->getWhere(['uid' => $uid],'*',['member']);
$svip_status = $user->is_svip > 0 && systemConfig('svip_switch_status') == '1';
if ($svip_status) {
$svipRate = app()->make(MemberinterestsRepository::class)->getSvipInterestVal(MemberinterestsRepository::HAS_TYPE_MEMBER);
if ($svipRate > 0) {
$inc = bcmul($svipRate, $inc, 0);
}
}
$this->checkMemberValue($user, $inc);
$make->incBill($user->uid, 'sys_members', $type, [
'number' => $inc,

View File

@ -15,7 +15,7 @@ namespace app\common\repositories\user;
use app\common\repositories\BaseRepository;
use app\common\dao\user\UserExtractDao as dao;
use app\common\repositories\wechat\WechatUserRepository;
use crmeb\jobs\SendTemplateMessageJob;
use crmeb\jobs\SendSmsJob;
use crmeb\services\SwooleTaskService;
use crmeb\services\WechatService;
use think\exception\ValidateException;
@ -135,7 +135,6 @@ class UserExtractRepository extends BaseRepository
public function switchStatus($id,$data)
{
$extract = $this->dao->getWhere(['extract_id' => $id]);
$user = app()->make(UserRepository::class)->get($extract['uid']);
if(!$user) throw new ValidateException('用户不存在');
@ -168,10 +167,7 @@ class UserExtractRepository extends BaseRepository
event('user.extractStatus',compact('id','userExtract'));
});
Queue::push(SendTemplateMessageJob::class,[
'tempCode' => 'EXTRACT_NOTICE',
'id' =>$id
]);
Queue::push(SendSmsJob::class,['tempId' => 'EXTRACT_NOTICE', 'id' =>$id]);
}
public function createSn()

View File

@ -43,7 +43,7 @@ class UserMerchantRepository extends BaseRepository
$query = $this->dao->search($where);
$count = $query->count();
$make = app()->make(UserLabelRepository::class);
$list = $query->setOption('field', [])->field('A.uid,A.user_merchant_id,B.avatar,B.nickname,B.user_type,A.last_pay_time,A.first_pay_time,A.label_id,A.create_time,A.last_time,A.pay_num,A.pay_price')
$list = $query->setOption('field', [])->field('A.uid,A.user_merchant_id,B.avatar,B.nickname,B.user_type,A.last_pay_time,A.first_pay_time,A.label_id,A.create_time,A.last_time,A.pay_num,A.pay_price,B.phone,B.is_svip,B.svip_endtime')
->page($page, $limit)->order('A.user_merchant_id DESC')->select()->each(function ($item) use ($where, $make) {
return $item->label = count($item['label_id']) ? $make->labels($item['label_id'], $where['mer_id']) : [];
});

View File

@ -0,0 +1,184 @@
<?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\user;
use app\common\dao\user\LabelRuleDao;
use app\common\dao\user\UserOrderDao;
use app\common\repositories\BaseRepository;
use app\common\repositories\system\groupData\GroupDataRepository;
use crmeb\jobs\SendSmsJob;
use crmeb\services\PayService;
use FormBuilder\Factory\Elm;
use think\facade\Db;
use think\facade\Log;
use think\facade\Queue;
/**
* Class LabelRuleRepository
* @package app\common\repositories\user
* @author xaboy
* @day 2020/10/20
* @mixin LabelRuleDao
*/
class UserOrderRepository extends BaseRepository
{
//付费会员
const TYPE_SVIP = 'S-';
/**
* LabelRuleRepository constructor.
* @param LabelRuleDao $dao
*/
public function __construct(UserOrderDao $dao)
{
$this->dao = $dao;
}
public function getList(array $where, $page, $limit)
{
$query = $this->dao->search($where);
$count = $query->count();
$list = $query->with([
'user' => function($query){
$query->field('uid,nickname,avatar,phone,is_svip,svip_endtime');
}
])->order('create_time DESC')->page($page, $limit)->select()->toArray();
return compact('count', 'list');
}
/**
* TODO 获取订单号
* @return string
* @author Qinii
* @day 2022/11/12
*/
public function setOrderSn()
{
list($msec, $sec) = explode(' ', microtime());
$msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
$orderId = 'wxs' . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
return $orderId;
}
/**
* @param $data
* @return mixed
* @author xaboy
* @day 2020/10/21
*/
public function add($res, $user, $params)
{
$order_sn = $this->setOrderSn();
$data = [
'title' => $res['value']['svip_name'],
'link_id' => $res->group_data_id,
'order_sn' => $order_sn,
'pay_price' => $res['value']['price'],
'order_info' => json_encode($res['value'],JSON_UNESCAPED_UNICODE),
'uid' => $user->uid,
'order_type' => self::TYPE_SVIP.$res['value']['svip_type'],
'pay_type' => $res['value']['price'] == 0 ? 'free' : $params['pay_type'],
'status' => 1,
'other' => $user->is_svip == -1 ? 'first' : '',
];
$body = [
'order_sn' => $order_sn,
'pay_price' => $data['pay_price'],
'attach' => 'user_order',
'body' =>'付费会员'
];
$type = $params['pay_type'];
if (in_array($type, ['weixin', 'alipay'], true) && $params['is_app']) {
$type .= 'App';
}
if ($params['return_url'] && $type === 'alipay') $body['return_url'] = $params['return_url'];
$info = $this->dao->create($data);
if ($data['pay_price']){
try {
$service = new PayService($type,$body);
$config = $service->pay($user);
return app('json')->status($type, $config + ['order_id' => $info->order_id]);
} catch (\Exception $e) {
return app('json')->status('error', $e->getMessage(), ['order_id' => $info->order_id]);
}
} else {
$res = $this->paySuccess($data);
return app('json')->status('success', ['order_id' => $info->order_id]);
}
}
public function paySuccess($data)
{
/*
array (
'order_sn' => 'wxs167090166498470921',
'data' =>
EasyWeChat\Support\Collection::__set_state(array(
'items' =>
array (
'appid' => 'wx4409eaedbd62b213',
'attach' => 'user_order',
'bank_type' => 'OTHERS',
'cash_fee' => '1',
'fee_type' => 'CNY',
'is_subscribe' => 'N',
'mch_id' => '1288093001',
'nonce_str' => '6397efa100165',
'openid' => 'oOdvCvjvCG0FnCwcMdDD_xIODRO0',
'out_trade_no' => 'wxs167090166498470921',
'result_code' => 'SUCCESS',
'return_code' => 'SUCCESS',
'sign' => '125C56DE030A461E45D421E44C88BC30',
'time_end' => '20221213112118',
'total_fee' => '1',
'trade_type' => 'JSAPI',
'transaction_id' => '4200001656202212131458556229',
),
)),
*/
$res = $this->dao->getWhere(['order_sn' => $data['order_sn']]);
$type = explode('-',$res['order_type'])[0].'-';
// 付费会员充值
if ($type == self::TYPE_SVIP) {
return Db::transaction(function () use($data, $res) {
$res->paid = 1;
$res->pay_time = date('y_m-d H:i:s', time());
$res->save();
return $this->payAfter($res, $res);
});
}
}
public function payAfter($data, $ret)
{
$info = json_decode($data['order_info']);
$user = app()->make(UserRepository::class)->get($ret['uid']);
$day = $info->svip_type == 3 ? 0 : $info->svip_number;
$endtime = ($user['svip_endtime'] && $user['is_svip'] != 0) ? $user['svip_endtime'] : date('Y-m-d H:i:s',time());
$svip_endtime = date('Y-m-d H:i:s',strtotime("$endtime +$day day" ));
$user->is_svip = $info->svip_type;
$user->svip_endtime = $svip_endtime;
$user->save();
$ret->status = 1;
$ret->pay_time = date('Y-m-d H:i:s',time());
$ret->end_time = $svip_endtime;
$ret->save();
$date = $info->svip_type == 3 ? '终身会员' : $svip_endtime;
Queue::push(SendSmsJob::class,['tempId' => 'SVIP_PAY_SUCCESS','id' => ['phone' => $user->phone, 'date' => $date]]);
return ;
}
}

View File

@ -13,17 +13,12 @@
namespace app\common\repositories\user;
use app\common\dao\user\UserRechargeDao;
use app\common\model\user\User;
use app\common\model\user\UserRecharge;
use app\common\repositories\BaseRepository;
use crmeb\jobs\SendTemplateMessageJob;
use crmeb\services\MiniProgramService;
use crmeb\jobs\SendSmsJob;
use crmeb\services\PayService;
use crmeb\services\WechatService;
use EasyWeChat\Support\Collection;
use Exception;
use think\facade\Db;
use think\facade\Queue;
@ -132,10 +127,7 @@ class UserRechargeRepository extends BaseRepository
$recharge->user->save();
$recharge->save();
});
Queue::push(SendTemplateMessageJob::class,[
'tempCode' => 'USER_BALANCE_CHANGE',
'id' =>$orderId
]);
Queue::push(SendSmsJob::class,['tempId' => 'USER_BALANCE_CHANGE', 'id' =>$orderId]);
event('user.recharge',compact('recharge'));
}
}

View File

@ -345,7 +345,7 @@ class UserRepository extends BaseRepository
['label' => '增加', 'value' => 1],
['label' => '减少', 'value' => 0],
])->requiredNum(),
Elm::number('now_money', '金额')->required()->min(0)
Elm::number('now_money', '金额')->required()->min(0)->max(999999)
])->setTitle('修改用户余额');
}
@ -356,7 +356,7 @@ class UserRepository extends BaseRepository
['label' => '增加', 'value' => 1],
['label' => '减少', 'value' => 0],
])->requiredNum(),
Elm::number('now_money', '积分')->required()->min(0)
Elm::number('now_money', '积分')->required()->min(0)->max(999999)
])->setTitle('修改用户积分');
}
@ -1368,4 +1368,74 @@ class UserRepository extends BaseRepository
app()->make(CommunityRepository::class)->destoryByUid($uid);
});
}
public function svipForm(int $id)
{
$formData = $this->dao->get($id);
if (!$formData) throw new ValidateException('数据不存在');
$form = Elm::createForm(Route::buildUrl('systemUserSvipUpdate', ['id' => $id])->build());
$form->setRule([
Elm::switches('is_svip', '付费会员', $formData->is_svip > 0 ? 1 : 0)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
Elm::radio('type', '修改类型', 1)->options([
['label' => '增加', 'value' => 1],
['label' => '减少', 'value' => 0],
])->requiredNum(),
Elm::number('add_time', '付费会员期限(天)')->required()->min(1),
Elm::input('end_time', '当前有效期期限', $formData->is_svip > 0 ? $formData->svip_endtime : 0)->disabled(true),
]);
return $form->setTitle( '编辑付费会员期限' );
}
/**
* TODO 设置付费会员
* @param $id
* @param $data
* @author Qinii
* @day 2022/11/22
*/
public function svipUpdate($id, $data,$adminId)
{
$user = app()->make(UserRepository::class)->get($id);
if (!$user) throw new ValidateException('用户不存在');
if ($user['is_svip'] < 1 && ($data['is_svip'] == 0 || !$data['type']))
throw new ValidateException('该用户还不是付费会员');
if ($user['is_svip'] == 3 && $data['is_svip'] == 1)
throw new ValidateException('该用户已是永久付费会员');
if ($data['is_svip']) {
$day = ($data['type'] == 1 ? '+ ' : '- ').$data['add_time'];
$endtime = ($user['svip_endtime'] && $user['is_svip'] != 0) ? $user['svip_endtime'] : date('Y-m-d H:i:s',time());
$is_svip = 1;
$svip_endtime = date('Y-m-d H:i:s',strtotime("$endtime $day day" ));
//结束时间小于当前 就关闭付费会员
if (strtotime($svip_endtime) <= time()) {
$is_svip = 0;
}
} else {
$is_svip = 0;
$svip_endtime = date('Y-m-d H:i:s', time());
}
$make = app()->make(UserOrderRepository::class);
$res = [
'title' => $data['is_svip'] == 0 ? '平台取消会员资格' : ($data['type'] ? '平台赠送' : '平台扣除'),
'link_id' => 0,
'order_sn' => $make->setOrderSn(),
'pay_price' => 0,
'order_info' => json_encode($data,JSON_UNESCAPED_UNICODE),
'uid' => $id,
'order_type' => UserOrderRepository::TYPE_SVIP . $is_svip,
'pay_type' => 'sys',
'status' => 1,
'pay_time' => date('Y-m-d H:i:s',time()),
'admin_id' => $adminId,
'end_time' => $svip_endtime,
'other' => $user->is_svip == -1 ? 'first' : '',
];
Db::transaction(function () use($user, $res, $is_svip, $svip_endtime,$make) {
$make->create($res);
$user->is_svip = $is_svip;
$user->svip_endtime = $svip_endtime;
$user->save();
});
}
}

View File

@ -87,33 +87,36 @@ class UserSignRepository extends BaseRepository
* 计算用户剩余积分
*
*/
return Db::transaction(function() use($uid){
$yesterday = date("Y-m-d",strtotime("-1 day"));
$sign_num = ($this->getSign($uid,$yesterday) ?: 0) + 1;
//签到规则计算
$sign_task = $this->getDay($sign_num);
$integral = $sign_task['sign_integral'];
$user_make = app()->make(UserRepository::class);
$user = $user_make->get($uid);
$integral_ = $user['integral'] + $sign_task['sign_integral'];
$data = [
'uid' => $uid,
'sign_num' => $sign_num,
'number' => $sign_task['sign_integral'],
'integral' => $integral_,
'title' => '签到',
];
$yesterday = date("Y-m-d",strtotime("-1 day"));
$sign_num = ($this->getSign($uid,$yesterday) ?: 0) + 1;
//签到规则计算
$sign_task = $this->getDay($sign_num);
$user = app()->make(UserRepository::class)->get($uid);
$integral = $sign_task['sign_integral'];
if ($user->is_svip > 0) {
$makeInteres = app()->make(MemberinterestsRepository::class);
$integral = $integral * $makeInteres->getSvipInterestVal($makeInteres::HAS_TYPE_SIGN);;
}
$user_make = app()->make(UserRepository::class);
$user = $user_make->get($uid);
$integral_ = $user['integral'] + $integral;
$data = [
'uid' => $uid,
'sign_num' => $sign_num,
'number' => $integral,
'integral' => $integral_,
'title' => '签到',
];
//增加记录
$arr = [
'status' => 1,
'mark' => '签到,获得积分'. $integral,
'number' => $integral,
'balance'=> $integral_,
];
return Db::transaction(function() use($uid,$data,$user_make,$sign_task,$arr,$integral){
$ret = $this->dao->create($data);
//增加记录
$arr = [
'status' => 1,
'mark' => '签到,获得积分'. $sign_task['sign_integral'],
'number' => $sign_task['sign_integral'],
'balance'=> $integral_,
];
$user_make->incIntegral($uid,$sign_task['sign_integral'],'签到'.$sign_task['sign_day'],'sign_integral',$arr);
$user_make->incIntegral($uid,$integral,'签到'.$sign_task['sign_day'],'sign_integral',$arr);
app()->make(UserBrokerageRepository::class)->incMemberValue($uid, 'member_sign_num', $ret->sign_id);
return compact('integral');
});

View File

@ -123,9 +123,10 @@ class WechatUserRepository extends BaseRepository
$wechatUser = $this->dao->unionIdByWechatUser($routineInfo['unionid']);
if (!$wechatUser)
$wechatUser = $this->dao->routineIdByWechatUser($routineOpenid);
return Db::transaction(function () use ($createUser, $routineInfo, $wechatUser) {
if ($wechatUser) {
$routineInfo['nickname'] = $wechatUser['nickname'];
$routineInfo['headimgurl'] = $wechatUser['headimgurl'];
$wechatUser->save($routineInfo);
} else {
$wechatUser = $this->dao->create($routineInfo);

View File

@ -44,12 +44,12 @@ class Install //extends BaseController
* sql文件
* @var App
*/
public $sqlFile;
public $sqlFile = 'crmeb_merchant.sql';
/**
* 配置文件
* @var App
*/
public $configFile;
public $configFile = '.env';
public $env;
public $installHost;
public $_url;
@ -67,8 +67,6 @@ class Install //extends BaseController
}
$this->app = $app;
$this->request = $this->app->request;
$this->sqlFile = 'crmeb_merchant.sql';
$this->configFile = '.env';
$this->env = [];
$this->installHost = $this->request->domain();
if (substr($this->installHost, 0, 5) == 'https'){

View File

@ -34,14 +34,21 @@ class Community extends BaseController
$this->repository = $repository;
}
public function title()
{
$where['is_del'] = 0;
return app('json')->success($this->repository->title($where));
}
/**
* @return mixed
* @author Qinii
*/
public function lst()
{
$where = $this->request->params(['keyword','status','username','category_id','topic_id','is_show']);
$where = $this->request->params(['keyword','status','username','category_id','topic_id','is_show','is_type']);
$where['order'] = 'start';
$where['is_del'] = 0;
[$page, $limit] = $this->getPage();
return app('json')->success($this->repository->getList($where, $page, $limit));
}
@ -121,5 +128,4 @@ class Community extends BaseController
return app('json')->success('修改成功');
}
}

View File

@ -17,6 +17,7 @@ use crmeb\basic\BaseController;
use app\common\repositories\store\ExcelRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use app\common\repositories\store\order\StoreOrderRepository as repository;
use crmeb\services\ExcelService;
use think\App;
class Order extends BaseController
@ -142,6 +143,12 @@ class Order extends BaseController
return app('json')->success($data);
}
public function status($id)
{
[$page, $limit] = $this->getPage();
return app('json')->success($this->repository->getOrderStatus($id, $page, $limit));
}
/**
* TODO 快递查询
* @param $id
@ -175,8 +182,9 @@ class Order extends BaseController
$where['verify_date'] = $where['date'];
unset($where['date']);
}
app()->make(ExcelRepository::class)->create($where, $this->request->adminId(), 'order',0);
return app('json')->success('开始导出数据');
[$page, $limit] = $this->getPage();
$data = app()->make(ExcelService::class)->order($where, $page, $limit);
return app('json')->success($data);
}
}

Some files were not shown because too many files have changed in this diff Show More