Merge pull request 'preview' (#58) from preview into master

Reviewed-on: #58
This commit is contained in:
mkm 2023-11-05 10:03:44 +08:00
commit e79bfc8635
3567 changed files with 216781 additions and 131326 deletions

View File

@ -29,6 +29,7 @@ class StoreCartDao extends BaseDao
const SOURCE_STORE_CLOUD = 101; //店铺内云商品
const SOURCE_CLOUD = 102; //云仓内店铺商品
const CITY_CLOUD = 103; //市级云仓商品
const SOURCE_COMMUNITY_RESALE = 201; //转售商品
const SOURCE_COMMUNITY_ENTRUST = 202; //委托商品
@ -78,7 +79,7 @@ class StoreCartDao extends BaseDao
$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,credit_buy')->with(['type_name']);
$query->field('mer_id,mer_name,mer_state,mer_avatar,is_trader,type_id,credit_buy')->with(['type_names']);
}
])->select();
@ -116,15 +117,18 @@ class StoreCartDao extends BaseDao
->append(['bc_extension_one', 'bc_extension_two']);
},
'merchant' => function (Relation $query) use ($uid) {
$query->field('mer_id,mer_name,mer_state,mer_avatar,delivery_way,commission_rate,category_id,credit_buy,settle_cycle,interest_rate')->with(['coupon' => function ($query) use ($uid) {
$query->where('uid', $uid);
},
'config' => function ($query) {
$query->whereIn('config_key', ['mer_integral_status', 'mer_integral_rate', 'mer_store_stock', 'mer_take_status', 'mer_take_name', 'mer_take_phone', 'mer_take_address', 'mer_take_location', 'mer_take_day', 'mer_take_time']);
},
'merchantCategory'
]);
}])->whereIn('cart_id', $ids)->order('product_type DESC,cart_id DESC')->select();
$query->field('mer_id,mer_name,mer_state,mer_avatar,delivery_way,commission_rate,category_id,credit_buy,settle_cycle,interest_rate')
->with([
'coupon' => function ($query) use ($uid) {
$query->where('uid', $uid);
},
'config' => function ($query) {
$query->whereIn('config_key', ['mer_integral_status', 'mer_integral_rate', 'mer_store_stock', 'mer_take_status', 'mer_take_name', 'mer_take_phone', 'mer_take_address', 'mer_take_location', 'mer_take_day', 'mer_take_time']);
},
'merchantCategory'
]);
}])
->whereIn('cart_id', $ids)->order('product_type DESC,cart_id DESC')->select();
}
/**

View File

@ -1,160 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\dao\store\order;
use app\common\dao\BaseDao;
use app\common\model\BaseModel;
use app\common\model\store\order\StoreCart;
use app\common\model\user\UserAddress;
use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\model\Relation;
class StoreCartDao extends BaseDao
{
protected function getModel(): string
{
return StoreCart::class;
}
public function test()
{
return StoreCart::getDB()->with(['product' => function (Relation $query) {
$query->where('store_name', '儿童节礼物');
}])->select();
}
/**
* @param array $ids
* @param $uid
* @param int|null $merId
* @return array
* @author xaboy
* @day 2020/6/5
*/
public function validIntersection(array $ids, $uid, int $merId = null): array
{
return StoreCart::getDB()->whereIn('cart_id', $ids)
->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})
->where('is_del', 0)->where('is_fail', 0)->where('is_pay', 0)->where('uid', $uid)->column('cart_id');
}
/**
* @Author:Qinii
* @Date: 2020/6/1
* @param int $uid
* @return mixed
*/
public function getAll(int $uid)
{
$query = ($this->getModel())::where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0])
->with([
'product' => function ($query) {
$query->field('product_id,image,store_name,is_show,status,is_del,unit_name,price,mer_status,is_used,product_type,once_max_count,once_min_count,pay_limit,mer_svip_status,svip_price_type');
},
'productAttr' => function ($query) {
$query->field('product_id,stock,price,unique,sku,image,svip_price');
},
'merchant' => function ($query) {
$query->field('mer_id,mer_name,mer_state,mer_avatar,is_trader,type_id')->with(['type_name']);
}
])->select();
return $query;
}
public function cartIbByData(array $ids, int $uid, ?UserAddress $address)
{
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,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) {
$query->where(function ($query) use ($cityIds) {
foreach ($cityIds as $v) {
$query->whereOr('city_id', 'like', "%/{$v}/%");
}
$query->whereOr('city_id', '0');
})->order('shipping_template_region_id DESC')->withLimit(1);
}, 'undelives' => function ($query) use ($cityIds) {
foreach ($cityIds as $v) {
$query->whereOr('city_id', 'like', "%/{$v}/%");
}
}, 'free' => function (Relation $query) use ($cityIds) {
foreach ($cityIds as $v) {
$query->whereOr('city_id', 'like', "%/{$v}/%");
}
$query->order('shipping_template_free_id DESC')->withLimit(1);
}]]);
}
},
'productAttr' => function (Relation $query) {
$query->field('image,extension_one,extension_two,product_id,stock,price,unique,sku,volume,weight,ot_price,cost,svip_price')
->append(['bc_extension_one', 'bc_extension_two']);
},
'merchant' => function (Relation $query) use ($uid) {
$query->field('mer_id,mer_name,mer_state,mer_avatar,delivery_way,commission_rate,category_id')->with(['coupon' => function ($query) use ($uid) {
$query->where('uid', $uid);
},
'config' => function ($query) {
$query->whereIn('config_key', ['mer_integral_status', 'mer_integral_rate', 'mer_store_stock', 'mer_take_status', 'mer_take_name', 'mer_take_phone', 'mer_take_address', 'mer_take_location', 'mer_take_day', 'mer_take_time']);
},
'merchantCategory'
]);
}])->whereIn('cart_id', $ids)->order('product_type DESC,cart_id DESC')->select();
}
/**
* @param array $cartIds
* @param int $uid
* @author Qinii
*/
public function batchDelete(array $cartIds, int $uid)
{
return ($this->getModel()::getDB())->where('uid', $uid)->whereIn('cart_id', $cartIds)->delete();
}
/**
* @param int $uid
* @return mixed
* @author Qinii
*/
public function getCartCount(int $uid)
{
$data = ($this->getModel()::getDB())->where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0])->field('SUM(cart_num) as count')->select();
$data[0]['count'] = $data[0]['count'] ? $data[0]['count'] : 0;
return $data;
}
/**
* @param $source
* @param array|null $ids
* @author xaboy
* @day 2020/8/31
*/
public function getSourcePayInfo($source, ?array $ids = null)
{
return StoreCart::getDB()->alias('A')->where('A.source', $source)->where('A.is_pay', 1)->when($ids, function ($query, $ids) {
$query->whereIn('A.source_id', $ids);
})->leftJoin('StoreOrderProduct B', 'A.cart_id = B.cart_id')
->field('sum(B.product_num) as pay_num,sum(B.product_price) as pay_price,A.source_id')->group('A.source_id')->select();
}
}

View File

@ -139,7 +139,11 @@ class StoreOrderDao extends BaseDao
$query->whereIn('order_id', $where['order_ids']);
})
->when(isset($where['order_id']) && $where['order_id'] !== '', function ($query) use ($where) {
$query->where('order_id', $where['order_id']);
if(is_array($where['order_id'])){
$query->whereIn('order_id',$where['order_id']);
}else{
$query->where('order_id', $where['order_id']);
}
})
->when(isset($where['take_order']) && $where['take_order'] != '', function ($query) use ($where) {
$query->where('order_type', 1)->whereNotNull('verify_time');

View File

@ -246,7 +246,7 @@ class Merchant extends BaseModel
return $this->hasOne(MerchantType::class, 'mer_type_id', 'type_id');
}
public function typeName()
public function typeNames()
{
return $this->merchantType()->bind(['type_name']);
}

View File

@ -1,234 +0,0 @@
<?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\system\merchant;
use app\common\dao\store\product\ProductDao;
use app\common\model\BaseModel;
use app\common\model\store\coupon\StoreCouponProduct;
use app\common\model\store\coupon\StoreCouponUser;
use app\common\model\store\product\Product;
use app\common\model\store\product\Spu;
use app\common\model\system\config\SystemConfigValue;
use app\common\model\system\financial\Financial;
use app\common\model\system\serve\ServeOrder;
use app\common\repositories\store\StoreActivityRepository;
class Merchant extends BaseModel
{
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tablePk(): string
{
return 'mer_id';
}
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tableName(): string
{
return 'merchant';
}
public function getDeliveryWayAttr($value)
{
if (!$value) return [];
return explode(',',$value);
}
public function product()
{
return $this->hasMany(Product::class, 'mer_id', 'mer_id');
}
public function config()
{
return $this->hasMany(SystemConfigValue::class, 'mer_id', 'mer_id');
}
public function showProduct()
{
return $this->hasMany(Product::class, 'mer_id', 'mer_id')
->where((new ProductDao())->productShow())
->field('mer_id,product_id,store_name,image,price,is_show,status,is_gift_bag,is_good')
->order('is_good DESC,sort DESC');
}
/**
* TODO 商户列表下的推荐
* @return \think\Collection
* @author Qinii
* @day 4/20/22
*/
public function getAllRecommendAttr()
{
$list = Product::where('mer_id', $this['mer_id'])
->where((new ProductDao())->productShow())
->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()->append(['show_svip_info']);
if ($list) {
$data = [];
$make = app()->make(StoreActivityRepository::class);
foreach ($list as $item) {
$spu_id = Spu::where('product_id',$item->product_id)->where('product_type' ,0)->value('spu_id');
$act = $make->getActivityBySpu(StoreActivityRepository::ACTIVITY_TYPE_BORDER,$spu_id,$item['cate_id'],$item['mer_id']);
$item['border_pic'] = $act['pic'] ?? '';
$data[] = $item;
}
return $data;
}
return [];
}
public function getCityRecommendAttr()
{
$list = Product::where('mer_id', $this['mer_id'])
->where((new ProductDao())->productShow())
->whereLike('delivery_way',"%1%")
->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();
if ($list) {
$data = [];
$make = app()->make(StoreActivityRepository::class);
foreach ($list as $item) {
$spu_id = Spu::where('product_id',$item->product_id)->where('product_type' ,0)->value('spu_id');
$act = $make->getActivityBySpu(StoreActivityRepository::ACTIVITY_TYPE_BORDER,$spu_id,$item['cate_id'],$item['mer_id']);
$item['border_pic'] = $act['pic'] ?? '';
$data[] = $item;
}
return $data;
}
return [];
}
public function recommend()
{
return $this->hasMany(Product::class, 'mer_id', 'mer_id')
->where((new ProductDao())->productShow())
->where('is_good', 1)
->field('mer_id,product_id,store_name,image,price,is_show,status,is_gift_bag,is_good,sales,create_time')
->order('is_good DESC,sort DESC,create_time DESC')
->limit(3);
}
public function coupon()
{
$time = date('Y-m-d H:i:s');
return $this->hasMany(StoreCouponUser::class, 'mer_id', 'mer_id')->where('start_time', '<', $time)->where('end_time', '>', $time)
->where('is_fail', 0)->where('status', 0)->order('coupon_price DESC, coupon_user_id ASC')
->with(['product' => function ($query) {
$query->field('coupon_id,product_id');
}, 'coupon' => function ($query) {
$query->field('coupon_id,type');
}]);
}
public function getServicesTypeAttr()
{
return merchantConfig($this->mer_id,'services_type');
}
public function marginOrder()
{
return $this->hasOne(ServeOrder::class, 'mer_id','mer_id')->where('type', 10)->order('create_time DESC');
}
public function refundMarginOrder()
{
return $this->hasOne(Financial::class, 'mer_id', 'mer_id')
->where('type',1)
->where('status', -1)
->order('create_time DESC')
->limit(1);
}
public function merchantCategory()
{
return $this->hasOne(MerchantCategory::class, 'merchant_category_id', 'category_id');
}
public function merchantType()
{
return $this->hasOne(MerchantType::class, 'mer_type_id', 'type_id');
}
public function typeName()
{
return $this->merchantType()->bind(['type_name']);
}
public function getMerCommissionRateAttr()
{
return $this->commission_rate > 0 ? $this->commission_rate : bcmul($this->merchantCategory->commission_rate, 100, 4);
}
public function getOpenReceiptAttr()
{
return merchantConfig($this->mer_id, 'mer_open_receipt');
}
public function admin()
{
return $this->hasOne(MerchantAdmin::class, 'mer_id', 'mer_id')->where('level', 0);
}
public function searchKeywordAttr($query, $value)
{
$query->whereLike('mer_name|mer_keyword', "%{$value}%");
}
public function getFinancialAlipayAttr($value)
{
return $value ? json_decode($value) : $value;
}
public function getFinancialWechatAttr($value)
{
return $value ? json_decode($value) : $value;
}
public function getFinancialBankAttr($value)
{
return $value ? json_decode($value) : $value;
}
public function getMerCertificateAttr()
{
return merchantConfig($this->mer_id, 'mer_certificate');
}
public function getIssetCertificateAttr()
{
return count(merchantConfig($this->mer_id, 'mer_certificate') ?: []) > 0;
}
public function searchMerIdsAttr($query, $value)
{
$query->whereIn('mer_id',$value);
}
}

View File

@ -31,6 +31,7 @@ use crmeb\services\QrcodeService;
use FormBuilder\Factory\Elm;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Log;
use think\facade\Route;
class CommunityRepository extends BaseRepository
@ -639,6 +640,9 @@ class CommunityRepository extends BaseRepository
if ($value) {
$attrValue = ProductAttrValue::where('unique', $value['product_attr_unique'])->find();
if($attrValue){
if($attrValue['mer_id']<=0){
throw new ValidateException('商户id不能为0');
}
$insert[] = [
'community_id' => $id,
'purchase_record_id' => 0,
@ -696,6 +700,9 @@ class CommunityRepository extends BaseRepository
if ($value) {
$attrValue = ProductAttrValue::where('unique', $value['product_attr_unique'])->find();
if($attrValue){
if($attrValue['mer_id']<=0){
throw new ValidateException('商户id不能为0');
}
$insert[] = [
'community_id' => $id,
'purchase_record_id' => 0,//$purchaseRecord['id'],
@ -749,6 +756,9 @@ class CommunityRepository extends BaseRepository
$cartRepo = app()->make(StoreCartRepository::class);
$cartIds = [];
foreach ($community['resale'] as $item) {
if($item['mer_id']<=0){
throw new ValidateException('商户id不能为0');
}
$data = [
'uid' => $uid,
'mer_id' => $item['mer_id'],
@ -769,7 +779,8 @@ class CommunityRepository extends BaseRepository
return $cartIds;
} catch (\Exception $exception) {
StoreCart::rollback();
throw new ValidateException('下单出错');
Log::error('加入购物车出错' . $exception->getMessage().'line'.$exception->getLine());
throw new ValidateException( $exception->getMessage());
}
}
@ -798,6 +809,9 @@ class CommunityRepository extends BaseRepository
$cartRepo = app()->make(StoreCartRepository::class);
$cartIds = [];
foreach ($community['entrust'] as $item) {
if($item['mer_id']<=0){
throw new ValidateException('商户id不能为0');
}
$data = [
'uid' => $uid,
'mer_id' => $item['mer_id'],
@ -818,6 +832,7 @@ class CommunityRepository extends BaseRepository
return $cartIds;
} catch (\Exception $exception) {
StoreCart::rollback();
Log::error('加入购物车出错' . $exception->getMessage().'line'.$exception->getLine());
throw new ValidateException('下单出错');
}
}

View File

@ -65,7 +65,13 @@ class StoreCartRepository extends BaseRepository
$item['product'] = $product_make->getFailProduct($item['product_id']);
$fail[] = $item;
} else {
$merchantData = $item['merchant']->append(['openReceipt'])->toArray();
//商户信息
if ($item['merchant']){
$merchantData = $item['merchant']->append(['openReceipt'])->toArray();
} else {
throw new ValidateException('商户不存在');
// $merchantData = ['mer_id' => 0];
}
unset($item['merchant']);
$coupon_make = app()->make(StoreCouponRepository::class);
if (!isset($arr[$item['mer_id']])) {
@ -98,9 +104,9 @@ class StoreCartRepository extends BaseRepository
* @param int $id
* @return mixed
*/
public function getOne(int $id,int $uid)
public function getOne(int $id, int $uid)
{
$where = [$this->dao->getPk() => $id,'is_del'=>0,'is_fail'=>0,'is_new'=>0,'is_pay'=>0,'uid' => $uid];
$where = [$this->dao->getPk() => $id, 'is_del' => 0, 'is_fail' => 0, 'is_new' => 0, 'is_pay' => 0, 'uid' => $uid];
return ($this->dao->getWhere($where));
}
@ -110,9 +116,9 @@ class StoreCartRepository extends BaseRepository
* @param $uid
* @author Qinii
*/
public function getCartByProductSku($sku,$uid,$product_type=0)
public function getCartByProductSku($sku, $uid, $product_type = 0)
{
$where = ['is_del'=>0,'is_fail'=>0,'is_new'=>0,'is_pay'=>0,'uid' => $uid,'product_type' => $product_type,'product_attr_unique' => $sku];
$where = ['is_del' => 0, 'is_fail' => 0, 'is_new' => 0, 'is_pay' => 0, 'uid' => $uid, 'product_type' => $product_type, 'product_attr_unique' => $sku];
return ($this->dao->getWhere($where));
}
@ -120,10 +126,10 @@ class StoreCartRepository extends BaseRepository
public function getProductById($productId)
{
$where = [
'is_del' =>0,
'is_new'=>0,
'is_pay'=>0,
'product_id'=>$productId
'is_del' => 0,
'is_new' => 0,
'is_pay' => 0,
'product_id' => $productId
];
return $this->dao->getWhereCount($where);
}

View File

@ -63,6 +63,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$svip_integral_rate = $svip_status ? app()->make(MemberinterestsRepository::class)->getSvipInterestVal(MemberinterestsRepository::HAS_TYPE_PAY) : 0;
//订单活动类型
$order_type = 0;
$source = 2;
//虚拟订单
$order_model = 0;
//虚拟订单自定义数据
@ -84,7 +85,10 @@ class StoreOrderCreateRepository extends StoreOrderRepository
throw new ValidateException('[超出限购总数:'. $cart['product']['once_max_count'].']'.mb_substr($cart['product']['store_name'],0,10).'...');
}
}
if ($cart['product_type'] > 0) $order_type = $cart['product_type'];
if ($cart['product_type'] > 0){
$order_type = $cart['product_type'];
$source = $cart['source'];
}
if ($cart['product_type']<=97 &&$cart['product_type'] > 0 && (($cart['product_type'] != 10 && count($merchantCart['list']) != 1) || count($merchantCartList) != 1)) {
throw new ValidateException('活动商品必须单独购买');
}
@ -900,7 +904,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$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;
@ -908,6 +911,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$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',
'source',
'order_model',
'order_extend',
'order_total_postage',
@ -1105,6 +1109,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$_order = [
'cartInfo' => $merchantCart,
'activity_type' => $orderInfo['order_type'],
'source' => $orderInfo['source']??2,
'commission_rate' => (float)$rate,
'order_type' => $merchantCart['order']['isTake'] ? 1 : 0,
'is_virtual' => $order_model ? 1 : 0,
@ -1309,7 +1314,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository
];
foreach ($cartInfo['list'] as $cart) {
$productPrice = $cart['true_price'];
$extension_one = $cart['extension_one'];
$extension_two = $cart['extension_two'];

View File

@ -11,6 +11,7 @@
// +----------------------------------------------------------------------
namespace app\common\repositories\store\order;
use app\common\dao\store\order\StoreCartDao;
use app\common\dao\store\order\StoreOrderDao;
use app\common\model\store\order\StoreGroupOrder;
use app\common\model\store\order\StoreOrder;
@ -142,20 +143,26 @@ class StoreOrderRepository extends BaseRepository
throw new ValidateException('未开启余额支付');
if ($user['now_money'] < $groupOrder['pay_price'])
throw new ValidateException('余额不足,请更换支付方式');
Db::transaction(function () use ($user, $groupOrder) {
$user->now_money = bcsub($user->now_money, $groupOrder['pay_price'], 2);
$user->save();
$userBillRepository = app()->make(UserBillRepository::class);
$userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', [
'link_id' => $groupOrder['group_order_id'],
'status' => 1,
'title' => '购买商品',
'number' => $groupOrder['pay_price'],
'mark' => '余额支付支付' . floatval($groupOrder['pay_price']) . '元购买商品',
'balance' => $user->now_money
]);
$this->paySuccess($groupOrder);
});
Db::startTrans();
try{
$user->now_money = bcsub($user->now_money, $groupOrder['pay_price'], 2);
$user->save();
$userBillRepository = app()->make(UserBillRepository::class);
$userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', [
'link_id' => $groupOrder['group_order_id'],
'status' => 1,
'title' => '购买商品',
'number' => $groupOrder['pay_price'],
'mark' => '余额支付支付' . floatval($groupOrder['pay_price']) . '元购买商品',
'balance' => $user->now_money
]);
$this->paySuccess($groupOrder);
Db::commit();
}catch (Exception $e) {
Db::rollback();
throw new ValidateException('余额支付失败');
}
return app('json')->status('success', '余额支付成功', ['order_id' => $groupOrder['group_order_id']]);
}
@ -471,7 +478,8 @@ class StoreOrderRepository extends BaseRepository
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);
// event('order.paySuccess', compact('groupOrder'));
$groupOrder=$groupOrder->toArray();
event('order.paySuccess', compact('groupOrder'));
//店内扫码支付
if (isset($groupOrder['micro_pay']) && $groupOrder['micro_pay'] == 1) {
$order = $this->dao->search(['uid' => $groupOrder->uid])->where('group_order_id', $groupOrder->group_order_id)->find();
@ -550,10 +558,13 @@ class StoreOrderRepository extends BaseRepository
// 更新调货价格
} else if ($cart['product_type'] == '98') {
if ($cart['source_id'] > 0) {
$price = Db::name('resale')->where('community_id', $cart['source_id'])->where('product_attr_unique', $cart['product_attr_unique'])->where('status', 0)->value('price');
if ($price) {
return $price;
} else {
$resale_find = Db::name('resale')->where('community_id', $cart['source_id'])->where('product_attr_unique', $cart['product_attr_unique'])->find();
if ($resale_find &&$resale_find['status']==0) {
return $resale_find['price'];
}else if($resale_find['status']==1){
throw new ValidateException('商品已转售');
}
else {
throw new ValidateException('转售商品数据异常');
}
} else {
@ -945,7 +956,7 @@ class StoreOrderRepository extends BaseRepository
$param['StoreOrder.paid'] = 1;
break; // 已支付
case 20:
$param['StoreOrder.status'] = 2;
$param['StoreOrder.status'] =[2,3];
break; // 已收货的商品才可以继续导入
default:
unset($param['StoreOrder.is_del']);
@ -1757,7 +1768,8 @@ class StoreOrderRepository extends BaseRepository
if ($status == 1) {
$query = $this->dao->search($where)->where($this->getOrderType($status))->whereRaw("(StoreOrder.paid=0 and StoreOrder.pay_type!=8) or (StoreOrder.paid=1 and StoreOrder.pay_type=8 and StoreOrder.status=2)")->where('StoreOrder.is_del', 0);
} else {
$query = $this->dao->search($where)->where($this->getOrderType($status))->where('StoreOrder.is_del', 0);
$arr=$this->getOrderType($status);
$query = $this->dao->search($where)->where($arr)->where('StoreOrder.is_del', 0);
}
$count = $query->count();

View File

@ -312,7 +312,7 @@ class ProductRepository extends BaseRepository
}
$res = $this->dao->get($id);
$data['svip_price_type'] = $res['svip_price_type'];
$settleParams = $this->setAttrValue($data, $id, 0, 1);
$settleParams = $this->setAttrValue($data, $id, 0, 1,$merId);
$settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId);
$settleParams['attr'] = $this->setAttr($data['attr'], $id);
$data['price'] = $settleParams['data']['price'];
@ -487,6 +487,7 @@ class ProductRepository extends BaseRepository
'pay_limit' => $data['pay_limit'] ?? 0,
'svip_price_type' => $data['svip_price_type'] ?? 0,
'source_product_id' => $data['source_product_id'] ?? 0,
'source_library_id' => $data['source_library_id'] ?? 0,
];
$result['bar_code'] = $data['attrValue'][0]['bar_code'] ?? '';
if (isset($data['mer_id']))
@ -563,6 +564,9 @@ class ProductRepository extends BaseRepository
*/
public function setAttrValue(array $data, int $productId, int $productType, int $isUpdate = 0,int $merId = 0)
{
if($merId<=0){
throw new ValidateException('添加商品商户id不能为0');
}
$extension_status = systemConfig('extension_status');
if ($isUpdate) {
$product = app()->make(ProductAttrValueRepository::class)->search(['product_id' => $productId])->select()->toArray();
@ -1170,7 +1174,7 @@ class ProductRepository extends BaseRepository
'attrValue',
'oldAttrValue',
'merchant' => function ($query) {
$query->with(['type_name'])->append(['isset_certificate','services_type']);
$query->with(['type_names'])->append(['isset_certificate','services_type']);
},
'seckillActive' => function ($query) {
$query->field('start_day,end_day,start_time,end_time,product_id');
@ -2325,19 +2329,20 @@ class ProductRepository extends BaseRepository
*/
public function stockIn($merId, $params)
{
/**感觉有问题 最好在优化一下结构 */
Db::startTrans();
try {
$supplierMerId = 0;
$model = new PurchaseRecord();
$stockIn = $params['number'] ?? 0;
$price = $params['price'] ?? 0;
if($stockIn==0){
$stockIn=1;
}
if (empty($params['product_id']) && !empty($params['order_product_id'])) {
//有商品无规格或者无商品无规格,导入商品和规格
$product = $this->getWhere(['source_product_id' => $params['order_product_id'], 'mer_id' => $merId]);
$sku = ProductAttrValue::where('product_id', $params['order_product_id'])->where('unique', $params['order_unique'])->value('sku');
$attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->where('sku', $sku)->find();
if (!empty($product)) {
$stockIn = $params['number'] ?? 0;
$price = $params['price'] ?? 0;
$attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->find();
if (!empty($params['order_id'])) {
//采购、委托订单导入
$orderMerId = StoreOrder::where('order_id', $params['order_id'])->value('mer_id');
@ -2349,9 +2354,7 @@ class ProductRepository extends BaseRepository
}
}
if( $orderProduct->is_imported == 1){
if($stockIn==0){
$stockIn=1;
}
ProductAttrValue::where('mer_id', $merId)
->where('product_id', $product['product_id'])
->update(['stock'=>$attrValue->stock + $stockIn]);
@ -2383,6 +2386,8 @@ class ProductRepository extends BaseRepository
} else {
$productId = $this->import($params['order_product_id'], request()->userInfo());
$product = $this->get($productId);
$attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $productId)->find();
}
} else {
//有商品有规格

View File

@ -147,7 +147,7 @@ class SpuRepository extends BaseRepository
$query->with([
'merchant' => function ($query) {
$query->field($this->merchantFiled)->with(['type_name']);
$query->field($this->merchantFiled)->with(['type_names']);
},
'issetCoupon',
'product.attrValue',
@ -209,7 +209,7 @@ class SpuRepository extends BaseRepository
$count = $query->fetchSql(false)->count();
$query->with([
'merchant' => function ($query) {
$query->field($this->merchantFiled)->with(['type_name']);
$query->field($this->merchantFiled)->with(['type_names']);
},
'issetCoupon'
]);

View File

@ -1,531 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\repositories\store\product;
use app\common\repositories\store\coupon\StoreCouponProductRepository;
use app\common\repositories\store\coupon\StoreCouponRepository;
use app\common\repositories\store\StoreActivityRepository;
use app\common\repositories\user\UserRepository;
use crmeb\jobs\SendSmsJob;
use crmeb\jobs\SyncProductTopJob;
use crmeb\services\CopyCommand;
use crmeb\services\RedisCacheService;
use think\exception\ValidateException;
use think\facade\Log;
use app\common\repositories\BaseRepository;
use app\common\dao\store\product\SpuDao;
use app\common\repositories\store\StoreCategoryRepository;
use app\common\repositories\store\StoreSeckillActiveRepository;
use app\common\repositories\user\UserVisitRepository;
use think\facade\Queue;
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,svip_price_type,stock,mer_svip_status';
public function __construct(SpuDao $dao)
{
$this->dao = $dao;
}
public function create(array $param, int $productId, int $activityId, $productType = 0)
{
$data = $this->setparam($param, $productId, $activityId, $productType);
return $this->dao->create($data);
}
public function baseUpdate(array $param, int $productId, int $activityId, $productType = 0)
{
if ($productType == 1) {
$make = app()->make(StoreSeckillActiveRepository::class);
$activityId = $make->getSearch(['product_id' => $productId])->value('seckill_active_id');
}
$where = [
'product_id' => $productId,
'activity_id' => $activityId,
'product_type' => $productType,
];
$ret = $this->dao->getSearch($where)->find();
if (!$ret) {
return $this->create($param, $productId, $activityId, $productType);
} else {
$data = $this->setparam($param, $productId, $activityId, $productType);
$value = $data['mer_labels'];
if (!empty($value)) {
if (!is_array($value)) {
$data['mer_labels'] = ',' . $value . ',';
} else {
$data['mer_labels'] = ',' . implode(',', $value) . ',';
}
}
return $this->dao->update($ret->spu_id, $data);
}
}
public function setparam(array $param, $productId, $activityId, $productType)
{
$data = [
'product_id' => $productId,
'product_type' => $productType ?? 0,
'activity_id' => $activityId,
'store_name' => $param['store_name'],
'keyword' => $param['keyword'] ?? '',
'image' => $param['image'],
'price' => $param['price'],
'status' => 0,
'rank' => $param['rank'] ?? 0,
'temp_id' => $param['temp_id'],
'sort' => $param['sort'] ?? 0,
'mer_labels' => $param['mer_labels'] ?? '',
];
if (isset($param['mer_id'])) $data['mer_id'] = $param['mer_id'];
return $data;
}
/**
* TODO 修改排序
* @param $productId
* @param $activityId
* @param $productType
* @param $data
* @author Qinii
* @day 1/19/21
*/
public function updateSort($productId, $activityId, $productType, $data)
{
$where = [
'product_id' => $productId,
'activity_id' => $activityId,
'product_type' => $productType,
];
$ret = $this->dao->getSearch($where)->find();
if ($ret) $this->dao->update($ret['spu_id'], $data);
}
/**
* TODO 移动端列表
* @param $where
* @param $page
* @param $limit
* @param $userInfo
* @return array
* @author Qinii
* @day 12/18/20
*/
public function getApiSearch($where, $page, $limit, $userInfo = null)
{
if (isset($where['keyword']) && !empty($where['keyword'])) {
if (preg_match('/^(\/@[1-9]{1}).*\*\//', $where['keyword'])) {
$command = app()->make(CopyCommand::class)->getMassage($where['keyword']);
if (!$command || in_array($command['type'], [30, 40])) return ['count' => 0, 'list' => []];
if ($userInfo && $command['uid']) app()->make(UserRepository::class)->bindSpread($userInfo, $command['uid']);
$where['spu_id'] = $command['id'];
unset($where['keyword']);
} else {
app()->make(UserVisitRepository::class)->searchProduct($userInfo ? $userInfo['uid'] : 0, $where['keyword'], (int)($where['mer_id'] ?? 0));
}
}
$where['spu_status'] = 1;
$where['mer_status'] = 1;
$query = $this->dao->search($where);
$query->with([
'merchant' => function ($query) {
$query->field($this->merchantFiled)->with(['type_name']);
},
'issetCoupon',
]);
$productMake = app()->make(ProductRepository::class);
$count = $query->count();
$list = $query->page($page, $limit)->setOption('field', [])->field($this->productFiled)->select();
$append = ['stop_time','svip_price','show_svip_info','is_svip_price'];
if ($productMake->getUserIsPromoter($userInfo))
$append[] = 'max_extension';
$list->append($append);
$list = $this->getBorderList($list);
return compact('count', 'list');
}
public function getBorderList($list)
{
$make = app()->make(StoreActivityRepository::class);
foreach ($list as $item) {
$act = $make->getActivityBySpu(StoreActivityRepository::ACTIVITY_TYPE_BORDER,$item['spu_id'],$item['cate_id'],$item['mer_id']);
$item['border_pic'] = $act['pic'] ?? '';
}
return $list;
}
/**
* TODO 修改状态
* @param array $data
* @author Qinii
* @day 12/18/20
*/
public function changeStatus(int $id, int $productType)
{
$make = app()->make(ProductRepository::class);
$where = [];
$status = 1;
try {
switch ($productType) {
case 0:
$where = [
'activity_id' => 0,
'product_id' => $id,
'product_type' => $productType,
];
break;
case 1:
$_make = app()->make(StoreSeckillActiveRepository::class);
$res = $_make->getSearch(['product_id' => $id])->find();
$endday = strtotime($res['end_day']);
if ($res['status'] == -1 || $endday < time()) $status = 0;
$where = [
'activity_id' => $res['seckill_active_id'],
'product_id' => $id,
'product_type' => $productType,
];
break;
case 2:
$_make = app()->make(ProductPresellRepository::class);
$res = $_make->getWhere([$_make->getPk() => $id]);
$endttime = strtotime($res['end_time']);
if ($endttime <= time()) {
$status = 0;
} else {
if (
$res['product_status'] !== 1 ||
$res['status'] !== 1 ||
$res['action_status'] !== 1 ||
$res['is_del'] !== 0 ||
$res['is_show'] !== 1
) {
$status = 0;
}
}
$where = [
'activity_id' => $id,
'product_id' => $res['product_id'],
'product_type' => $productType,
];
break;
case 3:
$_make = app()->make(ProductAssistRepository::class);
$res = $_make->getWhere([$_make->getPk() => $id]);
$endttime = strtotime($res['end_time']);
if ($endttime <= time()) {
$status = 0;
} else {
if (
$res['product_status'] !== 1 ||
$res['status'] !== 1 ||
$res['is_show'] !== 1 ||
$res['action_status'] !== 1 ||
$res['is_del'] !== 0
) {
$status = 0;
}
}
$where = [
'activity_id' => $id,
'product_id' => $res['product_id'],
'product_type' => $productType,
];
break;
case 4:
$_make = app()->make(ProductGroupRepository::class);
$wher = $_make->actionShow();
$wher[$_make->getPk()] = $id;
$res = $_make->getWhere([$_make->getPk() => $id]);
$endttime = strtotime($res['end_time']);
if ($endttime <= time()) {
$status = 0;
} else {
if (
$res['product_status'] !== 1 ||
$res['status'] !== 1 ||
$res['is_show'] !== 1 ||
$res['action_status'] !== 1 ||
$res['is_del'] !== 0
) {
$status = 0;
}
}
$where = [
'activity_id' => $id,
'product_id' => $res['product_id'],
'product_type' => $productType,
];
break;
default:
break;
}
$ret = $make->getWhere(['product_id' => $where['product_id']]);
if (!$ret || $ret['status'] !== 1 || $ret['mer_status'] !== 1 || $ret['is_del']) $status = 0;
if (in_array($productType, [0, 1]) && ($ret['is_show'] !== 1 || $ret['is_used'] !== 1)) $status = 0;
$result = $this->dao->getSearch($where)->find();
if (!$result && $ret) $result = $this->create($ret->toArray(), $where['product_id'], $where['activity_id'], $productType);
if ($result) $this->dao->update($result['spu_id'], ['status' => $status]);
if ($status == 1 && $productType == 0) {
Queue(SendSmsJob::class, ['tempId' => 'PRODUCT_INCREASE', 'id' => $id]);
}
if ($productType == 0) Queue::push(SyncProductTopJob::class,[]);
} catch (\Exception $exception) {
Log::info($exception->getMessage());
}
}
/**
* TODO 平台编辑商品同步修改
* @param int $id
* @param int $productId
* @param int $productType
* @param array $data
* @author Qinii
* @day 12/18/20
*/
public function changRank(int $id, int $productId, int $productType, array $data)
{
$where = [
'product_id' => $productId,
'product_type' => $productType,
'activity_id' => $id,
];
$res = $this->dao->getWhere($where);
if (!$res && $id) $this->changeStatus($id, $productType);
$res = $this->dao->getWhere($where);
if ($res) {
$res->store_name = $data['store_name'];
$res->rank = $data['rank'];
$res->star = $data['star'] ?? 1;
$res->save();
}
}
/**
* TODO 同步各类商品到spu表
* @param array|null $productType
* @author Qinii
* @day 12/25/20
*/
public function updateSpu(?array $productType)
{
if (!$productType) $productType = [0, 1, 2, 3, 4];
$_product_make = app()->make(ProductRepository::class);
$data = [];
foreach ($productType as $value) {
$ret = $_product_make->activitSearch($value);
$data = array_merge($data, $ret);
}
$this->dao->findOrCreateAll($data);
}
/**
* TODO 获取活动商品的一级分类
* @param $type
* @return mixed
* @author Qinii +0
* @day 1/12/21
*/
public function getActiveCategory($type)
{
$pathArr = $this->dao->getActivecategory($type);
$path = [];
foreach ($pathArr as $item) {
$path[] = explode('/', $item)[1];
}
$path = array_unique($path);
$cat = app()->make(StoreCategoryRepository::class)->getSearch(['ids' => $path])->field('store_category_id,cate_name')->select();
return $cat;
}
public function getSpuData($id, $productType, $merId)
{
try {
switch ($productType) {
case 0:
$where = [
'activity_id' => 0,
'product_id' => $id,
'product_type' => $productType,
];
break;
case 1:
$_make = app()->make(StoreSeckillActiveRepository::class);
$res = $_make->getSearch(['product_id' => $id])->find();
$where = [
'activity_id' => $res['seckill_active_id'],
'product_id' => $id,
'product_type' => $productType,
];
break;
case 2:
$_make = app()->make(ProductPresellRepository::class);
$res = $_make->getWhere([$_make->getPk() => $id]);
$where = [
'activity_id' => $id,
'product_id' => $res['product_id'],
'product_type' => $productType,
];
break;
case 3:
$_make = app()->make(ProductAssistRepository::class);
$res = $_make->getWhere([$_make->getPk() => $id]);
$where = [
'activity_id' => $id,
'product_id' => $res['product_id'],
'product_type' => $productType,
];
break;
case 4:
$_make = app()->make(ProductGroupRepository::class);
$where[$_make->getPk()] = $id;
$res = $_make->getWhere([$_make->getPk() => $id]);
$where = [
'activity_id' => $id,
'product_id' => $res['product_id'],
'product_type' => $productType,
];
break;
default:
$where = [
'activity_id' => 0,
'product_id' => $id,
'product_type' => 0,
];
break;
}
} catch (\Exception $e) {
throw new ValidateException('数据不存在');
}
if ($merId) $where['mer_id'] = $merId;
$result = $this->dao->getSearch($where)->find();
if (!$result) throw new ValidateException('数据不存在');
return $result;
}
public function setLabels($id, $productType, $data, $merId = 0)
{
$field = isset($data['sys_labels']) ? 'sys_labels' : 'mer_labels';
if ($data[$field]) app()->make(ProductLabelRepository::class)->checkHas($merId, $data[$field]);
$ret = $this->getSpuData($id, $productType, $merId);
$value = $data[$field] ? $data[$field] : '';
$ret->$field = $value;
$ret->save();
}
public function batchLabels($ids, $data,$merId)
{
$ids = is_array($ids) ? $ids : explode(',',$ids);
foreach ($ids as $id) {
$this->setLabels($id,0,$data,$merId);
}
}
public function getApiSearchByCoupon($where, $page, $limit, $userInfo)
{
$coupon = app()->make(StoreCouponRepository::class)->search(null, [
'status' => 1,
'coupon_id' => $where['coupon_id']
])->find();
$data['coupon'] = $coupon;
if ($coupon) {
switch ($coupon['type']) {
case 0:
$where['mer_id'] = $coupon['mer_id'];
break;
case 1:
$where['product_ids'] = app()->make(StoreCouponProductRepository::class)->search([
'coupon_id' => $where['coupon_id']
])->column('product_id');
break;
case 11:
$ids = app()->make(StoreCouponProductRepository::class)->search([
'coupon_id' => $where['coupon_id']
])->column('product_id');
$where['cate_pid'] = $ids;
break;
case 10:
break;
case 12:
$ids = app()->make(StoreCouponProductRepository::class)->search([
'coupon_id' => $where['coupon_id']
])->column('product_id');
$where['mer_ids'] = $ids;
break;
}
$where['is_coupon'] = 1;
$where['order'] = 'star';
$where['common'] = 1;
$where['svip'] = ($coupon['send_type'] == StoreCouponRepository::GET_COUPON_TYPE_SVIP) ? 1 : '';
$product = $this->getApiSearch($where, $page, $limit, $userInfo);
}
$data['count'] = $product['count'] ?? 0;
$data['list'] = $product['list'] ?? [];
return $data;
}
public function getHotRanking(int $cateId)
{
$RedisCacheService = app()->make(RedisCacheService::class);
$prefix = env('queue_name','merchant').'_hot_ranking_';
$ids = $RedisCacheService->handler()->get($prefix.'top_' . intval($cateId));
$ids = $ids ? explode(',', $ids) : [];
if (!count($ids)) {
return [];
}
$ids = array_map('intval', $ids);
$where['mer_status'] = 1;
$where['status'] = 1;
$where['is_del'] = 0;
$where['product_type'] = 0;
$where['order'] = 'sales';
$where['spu_ids'] = $ids;
$list = $this->dao->search($where)->setOption('field',[])->field('spu_id,S.image,S.price,S.product_type,P.product_id,P.sales,S.status,S.store_name,P.ot_price,P.cost')->select();
if ($list) $list = $list->toArray();
return $list;
}
/**
* TODO
* @param $where
* @param $page
* @param $limit
* @return array
* @author Qinii
* @day 2022/9/22
*/
public function makinList($where,$page, $limit)
{
$where['spu_status'] = 1;
$where['mer_status'] = 1;
$query = $this->dao->search($where);
$query->with([
'merchant' ,
'issetCoupon',
]);
$count = $query->count();
$list = $query->page($page, $limit)->setOption('field', [])->field($this->productFiled)->select();
return compact('count','list');
}
}

View File

@ -312,7 +312,7 @@ class MerchantRepository extends BaseRepository
if ($where['keyword'] !== '') {
app()->make(UserVisitRepository::class)->searchMerchant($userInfo ? $userInfo['uid'] : 0, $where['keyword']);
}
$query = $this->dao->search($where)->with(['type_name']);
$query = $this->dao->search($where)->with(['type_names']);
$count = $query->count();
$status = systemConfig('mer_location');
/** @var MerchantTakeRepository $repository */
@ -369,11 +369,8 @@ class MerchantRepository extends BaseRepository
*/
public function detail($id, $userInfo)
{
$merchant = $this->dao->apiGetOne($id)->hidden([
"real_name", "mer_phone", "reg_admin_id", "sort", "is_del", "is_audit", "is_best", "mer_state", "bank", "bank_number", "bank_name", 'update_time',
'financial_alipay', 'financial_bank', 'financial_wechat', 'financial_type','mer_take_phone'
]);
$merchant->append(['type_name', 'isset_certificate', 'services_type']);
$merchant = $this->dao->apiGetOne($id);
$merchant->append(['type_names', 'isset_certificate', 'services_type']);
$merchant['care'] = false;
if ($userInfo)
$merchant['care'] = $this->getCareByUser($id, $userInfo->uid);

View File

@ -1,621 +0,0 @@
<?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\system\merchant;
use app\common\dao\system\merchant\MerchantDao;
use app\common\model\store\order\StoreOrder;
use app\common\model\store\product\ProductReply;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\coupon\StoreCouponRepository;
use app\common\repositories\store\coupon\StoreCouponUserRepository;
use app\common\repositories\store\product\ProductCopyRepository;
use app\common\repositories\store\product\ProductRepository;
use app\common\repositories\store\product\SpuRepository;
use app\common\repositories\store\shipping\ShippingTemplateRepository;
use app\common\repositories\store\StoreCategoryRepository;
use app\common\repositories\system\attachment\AttachmentRepository;
use app\common\repositories\user\UserBillRepository;
use app\common\repositories\user\UserRelationRepository;
use app\common\repositories\user\UserVisitRepository;
use app\common\repositories\wechat\RoutineQrcodeRepository;
use crmeb\jobs\ClearMerchantStoreJob;
use crmeb\services\QrcodeService;
use crmeb\services\UploadService;
use crmeb\services\WechatService;
use FormBuilder\Exception\FormBuilderException;
use FormBuilder\Factory\Elm;
use FormBuilder\Form;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Queue;
use think\facade\Route;
use think\Model;
/**
* Class MerchantRepository
* @package app\common\repositories\system\merchant
* @mixin MerchantDao
* @author xaboy
* @day 2020-04-16
*/
class MerchantRepository extends BaseRepository
{
/**
* MerchantRepository constructor.
* @param MerchantDao $dao
*/
public function __construct(MerchantDao $dao)
{
$this->dao = $dao;
}
/**
* @param array $where
* @param $page
* @param $limit
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-04-16
*/
public function lst(array $where, $page, $limit)
{
$query = $this->dao->search($where);
$count = $query->count($this->dao->getPk());
$list = $query->page($page, $limit)->setOption('field', [])
->with([
'admin' => function ($query) {
$query->field('mer_id,account');
},
'merchantCategory',
'merchantType'
])
->field('sort, mer_id, mer_name, real_name, mer_phone, mer_address, mark, status, create_time,is_best,is_trader,type_id,category_id,copy_product_num,export_dump_num,is_margin,margin,mer_avatar')->select();
return compact('count', 'list');
}
public function count($where)
{
$where['status'] = 1;
$valid = $this->dao->search($where)->count();
$where['status'] = 0;
$invalid = $this->dao->search($where)->count();
return compact('valid', 'invalid');
}
/**
* @param int|null $id
* @param array $formData
* @return Form
* @throws FormBuilderException
* @author xaboy
* @day 2020-04-16
*/
public function form(?int $id = null, array $formData = [])
{
$form = Elm::createForm(is_null($id) ? Route::buildUrl('systemMerchantCreate')->build() : Route::buildUrl('systemMerchantUpdate', ['id' => $id])->build());
$is_margin = 0;
if ($formData && $formData['is_margin'] == 10) $is_margin = 1;
/** @var MerchantCategoryRepository $make */
$make = app()->make(MerchantCategoryRepository::class);
$merchantTypeRepository = app()->make(MerchantTypeRepository::class);
$options = $merchantTypeRepository->getOptions();
$margin = $merchantTypeRepository->getMargin();
$config = systemConfig(['broadcast_room_type', 'broadcast_goods_type']);
$rule = [
Elm::input('mer_name', '商户名称')->required(),
Elm::select('category_id', '商户分类')->options(function () use ($make) {
return $make->allOptions();
})->requiredNum(),
Elm::select('type_id', '店铺类型')->disabled($is_margin)->options($options)->requiredNum()->col(12)->control($margin),
Elm::input('mer_account', '商户账号')->required()->disabled(!is_null($id))->required(!is_null($id)),
Elm::password('mer_password', '登录密码')->required()->disabled(!is_null($id))->required(!is_null($id)),
Elm::input('real_name', '商户姓名'),
Elm::input('mer_phone', '商户手机号')->col(12)->required(),
Elm::number('commission_rate', '手续费(%)')->col(12),
Elm::input('mer_keyword', '商户关键字')->col(12),
Elm::input('mer_address', '商户地址'),
Elm::input('sub_mchid', '微信分账商户号'),
Elm::textarea('mark', '备注'),
Elm::number('sort', '排序', 0)->precision(0)->max(99999),
$id ? Elm::hidden('status', 1) : Elm::switches('status', '是否开启', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(12),
Elm::switches('is_bro_room', '直播间审核', $config['broadcast_room_type'] == 1 ? 0 : 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(12),
Elm::switches('is_audit', '产品审核', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(12),
Elm::switches('is_bro_goods', '直播间商品审核', $config['broadcast_goods_type'] == 1 ? 0 : 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(12),
Elm::switches('is_best', '是否推荐')->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(12),
Elm::switches('is_trader', '是否自营')->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(12),
];
$form->setRule($rule);
return $form->setTitle(is_null($id) ? '添加商户' : '编辑商户')->formData($formData);
}
/**
* @param array $formData
* @return Form
* @throws FormBuilderException
* @author xaboy
* @day 2020/6/25
*/
public function merchantForm(array $formData = [])
{
$form = Elm::createForm(Route::buildUrl('merchantUpdate')->build());
$rule = [
Elm::textarea('mer_info', '店铺简介')->required(),
Elm::input('service_phone', '服务电话')->required(),
Elm::frameImage('mer_banner', '店铺Banner(710*200px)', '/' . config('admin.merchant_prefix') . '/setting/uploadPicture?field=mer_banner&type=1')->modal(['modal' => false])->width('896px')->height('480px')->props(['footer' => false]),
Elm::frameImage('mer_avatar', '店铺头像(120*120px)', '/' . config('admin.merchant_prefix') . '/setting/uploadPicture?field=mer_avatar&type=1')->modal(['modal' => false])->width('896px')->height('480px')->props(['footer' => false]),
Elm::switches('mer_state', '是否开启', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(12),
];
$form->setRule($rule);
return $form->setTitle('编辑店铺信息')->formData($formData);
}
/**
* @param $id
* @return Form
* @throws FormBuilderException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-04-16
*/
public function updateForm($id)
{
$data = $this->dao->get($id)->toArray();
/** @var MerchantAdminRepository $make */
$make = app()->make(MerchantAdminRepository::class);
$data['mer_account'] = $make->merIdByAccount($id);
$data['mer_password'] = '***********';
if($data['category_id'] == 0){
$data['category_id'] = '';
}
if($data['type_id'] == 0){
$data['type_id'] = '';
}
return $this->form($id, $data);
}
/**
* @param array $data
* @author xaboy
* @day 2020-04-17
*/
public function createMerchant(array $data)
{
if ($this->fieldExists('mer_name', $data['mer_name']))
throw new ValidateException('商户名已存在');
if ($data['mer_phone'] && isPhone($data['mer_phone']))
throw new ValidateException('请输入正确的手机号');
$merchantCategoryRepository = app()->make(MerchantCategoryRepository::class);
$adminRepository = app()->make(MerchantAdminRepository::class);
if (!$data['category_id'] || !$merchantCategoryRepository->exists($data['category_id']))
throw new ValidateException('商户分类不存在');
if ($adminRepository->fieldExists('account', $data['mer_account']))
throw new ValidateException('账号已存在');
/** @var MerchantAdminRepository $make */
$make = app()->make(MerchantAdminRepository::class);
$margin = app()->make(MerchantTypeRepository::class)->get($data['type_id']);
$data['is_margin'] = $margin['is_margin'] ?? -1;
$data['margin'] = $margin['margin'] ?? 0;
return Db::transaction(function () use ($data, $make) {
$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);
app()->make(ShippingTemplateRepository::class)->createDefault($merchant->mer_id);
app()->make(ProductCopyRepository::class)->defaulCopyNum($merchant->mer_id);
return $merchant;
});
}
/**
* @Author:Qinii
* @Date: 2020/5/30
* @param $where
* @param $page
* @param $limit
* @return array
*/
public function getList($where, $page, $limit, $userInfo)
{
$field = 'care_count,is_trader,type_id,mer_id,mer_banner,mini_banner,mer_name, mark,mer_avatar,product_score,service_score,postage_score,sales,status,is_best,create_time,long,lat,is_margin';
$where['status'] = 1;
$where['mer_state'] = 1;
$where['is_del'] = 0;
if (isset($where['location'])) {
$data = @explode(',', (string)$where['location']);
if (2 != count(array_filter($data ?: []))) {
unset($where['location']);
} else {
$where['location'] = [
'lat' => (float)$data[0],
'long' => (float)$data[1],
];
}
}
if ($where['keyword'] !== '') {
app()->make(UserVisitRepository::class)->searchMerchant($userInfo ? $userInfo['uid'] : 0, $where['keyword']);
}
$query = $this->dao->search($where)->with(['type_name']);
$count = $query->count();
$status = systemConfig('mer_location');
$list = $query->page($page, $limit)->setOption('field', [])->field($field)->select()
->each(function ($item) use ($status, $where) {
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';
if ($distance == '1m') {
$distance = '100m以内';
}
} else {
$distance .= 'km';
}
$item['distance'] = $distance;
}
$item['recommend'] = isset($where['delivery_way']) ? $item['CityRecommend'] : $item['AllRecommend'];
return $item;
});
return compact('count', 'list');
}
/**
* @Author:Qinii
* @Date: 2020/5/30
* @param int $id
* @return array|Model|null
*/
public function merExists(int $id)
{
return ($this->dao->get($id));
}
/**
* @Author:Qinii
* @Date: 2020/5/30
* @param $id
* @param $userInfo
* @return array|Model|null
*/
public function detail($id, $userInfo)
{
$merchant = $this->dao->apiGetOne($id)->hidden([
"real_name", "mer_phone", "reg_admin_id", "sort", "is_del", "is_audit", "is_best", "mer_state", "bank", "bank_number", "bank_name", 'update_time',
'financial_alipay', 'financial_bank', 'financial_wechat', 'financial_type','mer_take_phone'
]);
$merchant->append(['type_name', 'isset_certificate', 'services_type']);
$merchant['care'] = false;
if ($userInfo)
$merchant['care'] = $this->getCareByUser($id, $userInfo->uid);
return $merchant;
}
/**
* @Author:Qinii
* @Date: 2020/5/30
* @param int $merId
* @param int $userId
* @return bool
*/
public function getCareByUser(int $merId, int $userId)
{
if (app()->make(UserRelationRepository::class)->getWhere(['type' => 10, 'type_id' => $merId, 'uid' => $userId]))
return true;
return false;
}
/**
* @Author:Qinii
* @Date: 2020/5/30
* @param $merId
* @param $where
* @param $page
* @param $limit
* @param $userInfo
* @return mixed
*/
public function productList($merId, $where, $page, $limit, $userInfo)
{
return app()->make(ProductRepository::class)->getApiSearch($merId, $where, $page, $limit, $userInfo);
}
/**
* @Author:Qinii
* @Date: 2020/5/30
* @param int $id
* @return mixed
*/
public function categoryList(int $id)
{
return app()->make(StoreCategoryRepository::class)->getApiFormatList($id, 1);
}
public function wxQrcode($merId)
{
$siteUrl = systemConfig('site_url');
$name = md5('mwx' . $merId . date('Ymd')) . '.jpg';
$attachmentRepository = app()->make(AttachmentRepository::class);
$imageInfo = $attachmentRepository->getWhere(['attachment_name' => $name]);
if (isset($imageInfo['attachment_src']) && strstr($imageInfo['attachment_src'], 'http') !== false && curl_file_exist($imageInfo['attachment_src']) === false) {
$imageInfo->delete();
$imageInfo = null;
}
if (!$imageInfo) {
$codeUrl = rtrim($siteUrl, '/') . '/pages/store/home/index?id=' . $merId; //二维码链接
if (systemConfig('open_wechat_share')) {
$qrcode = WechatService::create(false)->qrcodeService();
$codeUrl = $qrcode->forever('_scan_url_mer_' . $merId)->url;
}
$imageInfo = app()->make(QrcodeService::class)->getQRCodePath($codeUrl, $name);
if (is_string($imageInfo)) throw new ValidateException('二维码生成失败');
$imageInfo['dir'] = tidy_url($imageInfo['dir'], null, $siteUrl);
$attachmentRepository->create(systemConfig('upload_type') ?: 1, -2, $merId, [
'attachment_category_id' => 0,
'attachment_name' => $imageInfo['name'],
'attachment_src' => $imageInfo['dir']
]);
$urlCode = $imageInfo['dir'];
} else $urlCode = $imageInfo['attachment_src'];
return $urlCode;
}
public function routineQrcode($merId)
{
$name = md5('smrt' . $merId . date('Ymd')) . '.jpg';
return tidy_url(app()->make(QrcodeService::class)->getRoutineQrcodePath($name, 'pages/store/home/index', 'id=' . $merId), 0);
}
public function copyForm(int $id)
{
$form = Elm::createForm(Route::buildUrl('systemMerchantChangeCopy', ['id' => $id])->build());
$form->setRule([
Elm::input('copy_num', '复制次数', $this->dao->getCopyNum($id))->disabled(true)->readonly(true),
Elm::radio('type', '修改类型', 1)
->setOptions([
['value' => 1, 'label' => '增加'],
['value' => 2, 'label' => '减少'],
]),
Elm::number('num', '修改数量', 0)->required()
]);
return $form->setTitle('修改复制商品次数');
}
public function delete($id)
{
Db::transaction(function () use ($id) {
$this->dao->update($id, ['is_del' => 1]);
app()->make(MerchantAdminRepository::class)->deleteMer($id);
Queue::push(ClearMerchantStoreJob::class, ['mer_id' => $id]);
});
}
/**
* TODO 清理删除商户但没有删除的商品数据
* @author Qinii
* @day 5/15/21
*/
public function clearRedundancy()
{
$ret = (int)$this->dao->search(['is_del' => 1])->value('mer_id');
if (!$ret) return;
try {
app()->make(ProductRepository::class)->clearMerchantProduct($ret);
app()->make(StoreCouponRepository::class)->getSearch([])->where('mer_id', $ret)->update(['is_del' => 1, 'status' => 0]);
app()->make(StoreCouponUserRepository::class)->getSearch([])->where('mer_id', $ret)->update(['is_fail' => 1, 'status'=>2]);
} catch (\Exception $exception) {
throw new ValidateException($exception->getMessage());
}
}
public function addLockMoney(int $merId, string $orderType, int $orderId, float $money)
{
if ($money <= 0) return;
if (systemConfig('mer_lock_time')) {
app()->make(UserBillRepository::class)->incBill($merId, 'mer_lock_money', $orderType, [
'link_id' => ($orderType === 'order' ? 1 : 2) . $orderId,
'mer_id' => $merId,
'status' => 0,
'title' => '商户冻结余额',
'number' => $money,
'mark' => '商户冻结余额',
'balance' => 0
]);
} else {
$this->dao->addMoney($merId, $money);
}
}
public function checkCrmebNum(int $merId, string $type)
{
$merchant = $this->dao->get($merId);
switch ($type) {
case 'copy':
if (!systemConfig('copy_product_status')) {
throw new ValidateException('复制商品未开启');
}
if (!$merchant['copy_product_num']) {
throw new ValidateException('复制商品剩余次数不足');
}
break;
case 'dump':
if (!systemConfig('crmeb_serve_dump')) {
throw new ValidateException('电子面单未开启');
}
if (!$merchant['export_dump_num']) {
throw new ValidateException('电子面单剩余次数不足');
}
break;
}
return true;
}
public function subLockMoney(int $merId, string $orderType, int $orderId, float $money)
{
if ($money <= 0) return;
$make = app()->make(UserBillRepository::class);
$bill = $make->search(['category' => 'mer_lock_money', 'type' => $orderType, 'mer_id' => $merId, 'link_id' => ($orderType === 'order' ? 1 : 2) . $orderId, 'status' => 0])->find();
if (!$bill) {
$this->dao->subMoney($merId, $money);
} else {
$make->decBill($merId, 'mer_refund_money', $orderType, [
'link_id' => ($orderType === 'order' ? 1 : 2) . $orderId,
'mer_id' => $merId,
'status' => 1,
'title' => '商户冻结余额退款',
'number' => $money,
'mark' => '商户冻结余额退款',
'balance' => 0
]);
}
}
public function computedLockMoney(StoreOrder $order)
{
Db::transaction(function () use ($order) {
$money = 0;
$make = app()->make(UserBillRepository::class);
$bill = $make->search(['category' => 'mer_lock_money', 'type' => 'order', 'link_id' => '1' . $order->order_id, 'status' => 0])->find();
if ($bill) {
$money = bcsub($bill->number, $make->refundMerchantMoney($bill->link_id, $bill->type, $bill->mer_id), 2);
if ($order->presellOrder) {
$presellBill = $make->search(['category' => 'mer_lock_money', 'type' => 'presell', 'link_id' => '2' . $order->presellOrder->presell_order_id, 'status' => 0])->find();
if ($presellBill) {
$money = bcadd($money, bcsub($presellBill->number, $make->refundMerchantMoney($presellBill->link_id, $presellBill->type, $presellBill->mer_id), 2), 2);
$presellBill->status = 1;
$presellBill->save();
}
}
$bill->status = 1;
$bill->save();
}
if ($money > 0) {
app()->make(UserBillRepository::class)->incBill($order->uid, 'mer_computed_money', 'order', [
'link_id' => $order->order_id,
'mer_id' => $order->mer_id,
'status' => 0,
'title' => '商户待解冻余额',
'number' => $money,
'mark' => '交易完成,商户待解冻余额' . floatval($money) . '元',
'balance' => 0
]);
}
});
}
public function checkMargin($merId, $typeId)
{
$merchant = $this->dao->get($merId);
$is_margin = 0;
$margin = 0;
if ($merchant['is_margin'] == 10) {
$margin = $merchant['margin'];
$is_margin = $merchant['is_margin'];
} else {
$marginData = app()->make(MerchantTypeRepository::class)->get($typeId);
if ($marginData) {
$is_margin = $marginData['is_margin'];
$margin = $marginData['margin'];
}
}
return compact('is_margin', 'margin');
}
public function setMarginForm(int $id)
{
$merchant = $this->dao->get($id);
if ($merchant->is_margin !== 10) {
throw new ValidateException('商户无保证金可扣');
}
$form = Elm::createForm(Route::buildUrl('systemMarginSet')->build());
$form->setRule([
Elm::input('mer_name', '商户名称', $merchant->mer_name)->disabled(true),
Elm::input('mer_id', '商户ID', $merchant->mer_id)->disabled(true),
Elm::input('margin', '商户剩余保证金', $merchant->margin)->disabled(true),
Elm::number('number', '保证金扣除金额', 0)->max($merchant->margin)->precision(2)->required(),
Elm::text('mark', '保证金扣除原因')->required(),
]);
return $form->setTitle('扣除保证金');
}
/**
* TODO
* @param $data
* @return \think\response\Json
* @author Qinii
* @day 2/7/22
*/
public function setMargin($data)
{
$merechant = $this->dao->get($data['mer_id']);
if ($merechant->is_margin !== 10) {
throw new ValidateException('商户未支付保证金或已申请退款');
}
if ($data['number'] < 0) {
throw new ValidateException('扣除保证金额不能小于0');
}
if (bccomp($merechant->margin, $data['number'], 2) == -1) {
throw new ValidateException('扣除保证金额不足');
}
$data['balance'] = bcsub($merechant->margin, $data['number'], 2);
Db::transaction(function () use ($merechant, $data) {
$merechant->margin = $data['balance'];
$merechant->save();
app()->make(UserBillRepository::class)->bill(0, 'mer_margin', $data['type'], 0, $data);
});
}
public function changeDeliveryBalance($merId,$number)
{
$merechant = $this->dao->get($merId);
if (bccomp($merechant->delivery_balance, $number, 2) == -1) {
throw new ValidateException('余额不足,请先充值(配送费用:'.$number.'元)');
}
Db::transaction(function () use ($merechant, $number) {
$merechant->delivery_balance = bcsub($merechant->delivery_balance, $number, 2);
$merechant->save();
});
}
}

View File

@ -0,0 +1,166 @@
<?php
namespace app\controller\admin;
use crmeb\basic\BaseController;
use think\facade\Db;
use think\facade\Log;
use crmeb\services\UploadService;
use think\api\Client;
class ProductLibrary extends BaseController
{
public function lst()
{
[$page, $limit] = $this->getPage();
$param = $this->request->param();
$where = ['is_del' => 0];
$list = Db::name('product_library')->where($where)->page($page)->limit($limit)->order('id desc')->select();
$count = Db::name('product_library')->count();
return app('json')->success(['list' => $list, 'count' => $count]);
}
public function add()
{
$param = $this->request->param();
$data['store_name'] = $param['store_name'];
$data['store_info'] = $param['store_info'];
$data['keyword'] = $param['keyword'];
$data['bar_code'] = $param['bar_code'];
$data['is_used'] = 1;
$data['status'] = 1;
$data['cate_id'] = $param['cate_id'];
$data['unit_name'] = $param['unit_name'];
$data['price'] = $param['price'];
$data['cost'] = $param['cost'];
$data['ot_price'] = $param['ot_price'];
$data['stock'] = $param['stock'];
$data['create_time'] = date('Y-m-d H:i:s');
$data['image'] = $param['image'];
$data['slider_image'] = $param['slider_image'];
$data['images'] = $param['images'];
$res = Db::name('product_library')->insert($data);
if ($res) {
return app('json')->success('添加成功');
} else {
return app('json')->fail('添加失败');
}
}
public function edit()
{
$param = $this->request->param();
$data['store_name'] = $param['store_name'];
$data['store_info'] = $param['store_info'];
$data['keyword'] = $param['keyword'];
$data['bar_code'] = $param['bar_code'];
$data['is_used'] = 1;
$data['status'] = 1;
$data['cate_id'] = $param['cate_id'];
$data['unit_name'] = $param['unit_name'];
$data['price'] = $param['price'];
$data['cost'] = $param['cost'];
$data['ot_price'] = $param['ot_price'];
$data['stock'] = $param['stock'];
$data['create_time'] = date('Y-m-d H:i:s');
$data['image'] = $param['image'];
$data['slider_image'] = $param['slider_image'];
$data['images'] = $param['images'];
$res = Db::name('product_library')->where('id', $param['id'])->update($data);
if ($res) {
return app('json')->success('修改成功');
} else {
return app('json')->fail('修改失败');
}
}
public function del()
{
$param = $this->request->param();
$res = Db::name('product_library')->where('id', $param['id'])->update(['is_del' => 1]);
if ($res) {
return app('json')->success('删除成功');
} else {
return app('json')->fail('删除失败');
}
}
public function caiji($code = '')
{
if ($code == '') {
return app('json')->fail('编码不能为空');
}
$first_char = substr($code, 0, 1);
if($first_char!=0){
$codes='0'.$code;
}else{
$codes=$code;
}
$client = new Client("b1eb52b9-0379-4c56-b795-47d90a73ca6a");
$result = $client->barcodeQuery()
->withCode($codes)
->request();
try {
if ($result['code'] == 0) {
$upload = UploadService::create();
$dir = 'def/' . date('Y-m-d');
$param = $result['data'];
$data['store_name'] = $param['goodsName'];
$data['store_info'] = '';
$data['keyword'] = '';
$data['bar_code'] = $code;
$data['is_used'] = 1;
$data['status'] = 1;
$data['cate_id'] = 0;
$data['unit_name'] = '';
$data['spec'] =$param['spec'];
$data['trademark'] =$param['trademark'];
$data['goods_type'] =$param['goodsType'];
$data['ycg'] =$param['ycg'];
$data['note'] =$param['note'];
$data['manu_address'] =$param['manuAddress'];
$data['price'] = $param['price']??0;
$data['cost'] = 0;
$data['ot_price'] = 0;
$data['stock'] = 9999999;
$data['create_time'] = date('Y-m-d H:i:s');
$data['images'] = '';
if ($param['img'] != '') {
$oss = $upload->to($dir)->stream(file_get_contents($param['img']));
$data['image'] = $oss->filePath;
} else {
$data['image'] = 'https://lihai001.oss-cn-chengdu.aliyuncs.com/uploads/20230130/00ebcfdf75684f5494c0193075055d1.png';
$data['slider_image'] = 'https://lihai001.oss-cn-chengdu.aliyuncs.com/uploads/20230130/00ebcfdf75684f5494c0193075055d1.png';
}
$arr=[];
foreach($param['imgList'] as $k=>$v){
$oss=$upload->to($dir)->stream(file_get_contents($v));
$arr[] = $oss->filePath;
}
if(count($arr)>0){
$data['slider_image'] =implode(',',$arr);
}else{
$data['slider_image']=$data['image'];
}
$data['images'] = '';
$res = Db::name('product_library')->insert($data);
if ($res) {
return app('json')->success('添加成功');
} else {
throw new \think\exception\ValidateException('添加失败');
}
} else {
Log::error('商品采集错误:' . $result['message']);
throw new \think\exception\ValidateException($result['message']);
}
} catch (\Exception $e) {
throw new \think\exception\ValidateException($e->getMessage());
}
}
}

View File

@ -496,7 +496,7 @@ class Common extends BaseController
//获取云店铺
public function get_cloud_shop($street_code){
//更新查询镇级供应链店铺
$typeTownSupplyChainId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeTownSupplyChain'])->value('mer_type_id');
// $typeTownSupplyChainId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeTownSupplyChain'])->value('mer_type_id');
/*
$find=DB::name('merchant')
->alias('m')

View File

@ -51,7 +51,7 @@ class MerchantIntention extends BaseController
if (($this->userInfo->phone ?? false) && ($this->userInfo->phone != ($data['phone'] ?? ''))) {
throw new ValidateException('联系电话和注册手机不一致');
}
$intentionInfo = Db::name('merchant_intention')->where('social_credit_code', $data['social_credit_code'])->where('status', '<>', 2)->find();
if ($intentionInfo) {
throw new ValidateException('此统一社会信用代码已申请商户');
@ -87,7 +87,7 @@ class MerchantIntention extends BaseController
'organization_code' => $data['social_credit_code'] ?? '',
'master_name' => $data['name'],
'master_phone' => $data['phone'],
'images' => !empty($data['images'])?json_encode($data['images']):'',
'images' => !empty($data['images']) ? json_encode($data['images']) : '',
'city' => $areaInfo['city_code'] ?? '',
'area' => $data['area_id'] ?? '',
'street' => $data['street_id'] ?? '',
@ -108,7 +108,7 @@ class MerchantIntention extends BaseController
$status = $this->request->post('status', 0);
if ($this->userInfo) $data['uid'] = $this->userInfo->uid;
if ($status == 1) {
Db::name('merchant')->where('uid', $this->userInfo->uid)->update(['mer_settlement_agree_status'=>1]);
Db::name('merchant')->where('uid', $this->userInfo->uid)->update(['mer_settlement_agree_status' => 1]);
}
return app('json')->success('操作成功');
}
@ -116,14 +116,14 @@ class MerchantIntention extends BaseController
public function businessApply()
{
$data = $this->request->params([
'phone',
'phone',
'mer_name',
'company_name',
'address',
'name',
'code',
'images',
'merchant_category_id',
'address',
'name',
'code',
'images',
'merchant_category_id',
'mer_type_id',
'social_credit_code',
'area_id',
@ -141,7 +141,7 @@ class MerchantIntention extends BaseController
if (empty($data['bank_username']) || empty($data['bank_opening']) || empty($data['bank_front']) || empty($data['bank_back']) || empty($data['cardno_front']) || empty($data['cardno_back'])) {
return app('json')->fail('请完善银行卡及身份信息');
}
if (!systemConfig('mer_intention_open')) {
return app('json')->fail('未开启商户入驻');
}
@ -150,10 +150,10 @@ class MerchantIntention extends BaseController
if (empty($merInfo)) {
return app('json')->fail('请申请商户入驻申请!');
}
if (!empty($merInfo['business_status']) && ($merInfo['business_status']==1)) {
if (!empty($merInfo['business_status']) && ($merInfo['business_status'] == 1)) {
return app('json')->fail('商户交易已申请,正在审核中!');
}
if (!empty($merInfo['business_status']) && ($merInfo['business_status']==2)) {
if (!empty($merInfo['business_status']) && ($merInfo['business_status'] == 2)) {
return app('json')->fail('商户交易申请已通过');
}
$intenInfo = Db::name('merchant_intention')->where('mer_intention_id', $merInfo['mer_intention_id'] ?? 0)->where('type', 1)->find();
@ -191,7 +191,7 @@ class MerchantIntention extends BaseController
'organization_code' => $intenInfo['social_credit_code'] ?? '',
'master_name' => $intenInfo['name'],
'master_phone' => $intenInfo['phone'],
'images' => !empty($intenInfo['images'])?json_encode(explode(',', $intenInfo['images'])):'',
'images' => !empty($intenInfo['images']) ? json_encode(explode(',', $intenInfo['images'])) : '',
'city' => $areaInfo['city_code'] ?? '',
'area' => $merInfo['area_id'] ?? '',
'street' => $merInfo['street_id'] ?? '',
@ -210,7 +210,7 @@ class MerchantIntention extends BaseController
Db::name('merchant_intention')->where('mer_intention_id', $intentionId)->delete();
throw new ValidateException('供销平台商户交易申请失败,' . $res['msg']);
}
Db::name('merchant')->where('uid', $this->userInfo->uid)->where('status', 1)->update(['business_status'=>1]);
Db::name('merchant')->where('uid', $this->userInfo->uid)->where('status', 1)->update(['business_status' => 1]);
return app('json')->success('申请成功');
}
@ -234,7 +234,7 @@ class MerchantIntention extends BaseController
if (!empty($resData) && is_string($resData)) {
Log::info("商户申请反馈信息" . $resData);
$resInfo = json_decode($resData, true);
if(!empty($resInfo['code']) && $resInfo['code'] == 1){
if (!empty($resInfo['code']) && $resInfo['code'] == 1) {
$rtnData['ok'] = true;
} else {
$rtnData['msg'] = $resInfo['msg'];
@ -291,7 +291,7 @@ class MerchantIntention extends BaseController
'organization_code' => $data['social_credit_code'] ?? '',
'master_name' => $data['name'],
'master_phone' => $data['phone'],
'images' => !empty($data['images'])?json_encode($data['images']):'',
'images' => !empty($data['images']) ? json_encode($data['images']) : '',
'city' => $areaInfo['city_code'] ?? '',
'area' => $data['area_id'] ?? '',
'street' => $data['street_id'] ?? '',
@ -310,7 +310,7 @@ class MerchantIntention extends BaseController
{
[$page, $limit] = $this->getPage();
$type = $this->request->get('type', 1);
$data = $this->repository->getList(['uid' => $this->userInfo->uid, 'type'=>$type], $page, $limit);
$data = $this->repository->getList(['uid' => $this->userInfo->uid, 'type' => $type], $page, $limit);
return app('json')->success($data);
}
@ -329,14 +329,14 @@ class MerchantIntention extends BaseController
protected function checkParams()
{
$data = $this->request->params([
'phone',
'phone',
'mer_name',
'company_name',
'address',
'name',
'code',
'images',
'merchant_category_id',
'address',
'name',
'code',
'images',
'merchant_category_name',
'mer_type_id',
'social_credit_code',
'area_id',
@ -351,9 +351,18 @@ class MerchantIntention extends BaseController
if (!env('APP_DEBUG')) {
if (!$check) throw new ValidateException('验证码不正确');
}
if (!app()->make(MerchantCategoryRepository::class)->get($data['merchant_category_id'])) throw new ValidateException('商户分类不存在');
if ($data['mer_type_id'] && !app()->make(MerchantTypeRepository::class)->exists($data['mer_type_id']))
// if (!app()->make(MerchantCategoryRepository::class)->get($data['merchant_category_id'])) throw new ValidateException('商户分类不存在');
if ($data['mer_type_id'] && !app()->make(MerchantTypeRepository::class)->exists($data['mer_type_id'])) {
throw new ValidateException('店铺类型不存在');
}
if ($data['merchant_category_name'] == '') {
throw new ValidateException('商户分类,不能为空');
}
$merchant_category_id=Db::name('merchant_category')->where('category_name',$data['merchant_category_name'])->value('merchant_category_id');
if(!$merchant_category_id){
throw new ValidateException('没有对应的商户分类,请联系工作人员添加');
}
$data['merchant_category_id']=$merchant_category_id;
unset($data['code']);
return $data;
}
@ -392,4 +401,3 @@ class MerchantIntention extends BaseController
return app('json')->success($lst);
}
}

View File

@ -93,8 +93,12 @@ class StoreCart extends BaseController
case 99: //委托商品
$result = app()->make(ProductRepository::class)->cartCheck($data,$this->request->userInfo());
[$source, $sourceId, $pid] = explode(':', $this->request->param('source', '0'), 3) + ['', '', ''];
$data['source'] = (in_array($source, [0, 1]) && $pid == $data['product_id']) ? $source : 0;
if ($data['source'] > 0) $data['source_id'] = intval($sourceId);
if($source==StoreCartDao::CITY_CLOUD){
$data['source'] = $source;
}else{
$data['source'] = (in_array($source, [0, 1]) && $pid == $data['product_id']) ? $source : 0;
if ($data['source'] > 0) $data['source_id'] = intval($sourceId);
}
break;
case 1: //秒杀商品
$result = app()->make(ProductRepository::class)->cartSeckillCheck($data,$this->request->userInfo());

View File

@ -95,7 +95,6 @@ class StoreOrder extends BaseController
if (!is_array($receipt)) throw new ValidateException('发票信息有误');
$validate->check($receipt);
}
$uid = $this->request->uid();
// halt(count($cartId), count($cartRepository->validIntersection($cartId, $uid)));
if (!($count = count($cartId)) || $count != count($cartRepository->validIntersection($cartId, $uid)))
@ -305,6 +304,9 @@ class StoreOrder extends BaseController
return app('json')->success(['qrcode' => $this->repository->wxQrcode($id, $order->verify_code)]);
}
/**
* 生成二维码
*/
public function logisticsCode($id)
{
$storeInfo = Db::name('store_service')->where('uid', $this->request->uid())->find();

View File

@ -0,0 +1,118 @@
<?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\controller\api\store\order;
use app\common\model\store\order\StoreGroupOrder;
use app\common\repositories\delivery\DeliveryOrderRepository;
use app\common\repositories\store\order\StoreOrderCreateRepository;
use app\common\repositories\store\order\StoreOrderReceiptRepository;
use app\validate\api\UserReceiptValidate;
use crmeb\basic\BaseController;
use app\common\repositories\store\order\StoreCartRepository;
use app\common\repositories\store\order\StoreGroupOrderRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\user\UserAddressRepository;
use think\exception\ValidateException;
use crmeb\services\ExpressService;
use crmeb\services\LockService;
use think\facade\Db;
use think\App;
use think\facade\Log;
/**代发订单
* Class StoreOrder
* @package app\controller\api\store\order
* @author xaboy
* @day 2020/6/10
*/
class StoreOrderBehalf extends BaseController
{
/**
* @var StoreOrderRepository
*/
protected $repository;
/**
* StoreOrder constructor.
* @param App $app
* @param StoreOrderRepository $repository
*/
public function __construct(App $app, StoreOrderRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
}
/**
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author xaboy
* @day 2020/6/10
*/
public function lst()
{
[$page, $limit] = $this->getPage();
$status = $this->request->param('status',1);
$uid = $this->request->userInfo()['uid'];
$mer_id = Db::name('store_service')->where('uid', $uid)->where('is_del', 0)->value('mer_id');
if ($mer_id) {
$column = Db::name('store_order_behalf')->where('mer_id', $mer_id)->where('status', $status)->page($page)->limit($limit)->column('order_id');
if ($column) {
$where['order_id'] = $column;
return app('json')->success($this->repository->getList($where, 1, 100));
}
}
return app('json')->success([]);
}
/**
* @param $id
* @return mixed
* @author xaboy
* @day 2020/6/10
*/
public function detail($id)
{
$order = $this->repository->getDetail((int)$id, $this->request->uid());
if (!$order)
return app('json')->fail('订单不存在');
if ($order->order_type == 1) {
$order->append(['take', 'refund_status']);
}
return app('json')->success($order->toArray());
}
/**
* 生成二维码
*/
public function logisticsCode($id)
{
$status = $this->request->param('status',1);
$order_id = $this->request->param('order_id',0);
$uid = $this->request->userInfo()['uid'];
$mer_id = Db::name('store_service')->where('uid', $uid)->where('is_del', 0)->value('mer_id');
if ($mer_id) {
$order_id = Db::name('store_order_behalf')->where('mer_id', $mer_id)->where('status', $status)->where('order_id',$order_id)->value('order_id');
if ($order_id) {
$order = $this->repository->getWhere(['order_id' => $id,'is_del' => 0]);
return app('json')->success(['qrcode' => $this->repository->logisticsQrcode($id, $order->order_sn)]);
}
}
return app('json')->fail('信息有误:请联系官方人员');
}
}

View File

@ -44,51 +44,83 @@ class CloudWarehouse extends BaseController
* 指定类型的云仓商品列表
* @return mixed
*/
public function index()
{
// 除了市级供应链都可以查询
$typeIdArray = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeTownSupplyChain'])->column('mer_type_id');
$params = $this->request->params(['category_id', 'street_code', 'order', ['product_type', 0], 'keyword','page_num']);
$search = [
'street_id' => $params['street_code'],
'type_id' => $typeIdArray ?? [],
'status' => 1,
'is_del' => 0,
'mer_state' => 1,
];
if (!empty($params['category_id'])) {
$search['category_id'] = $params['category_id'];
}
$merchantIds = $this->merchantDao->search($search)->column('mer_id');
[$page, $limit] = $this->getPage();
if(isset($params['page_num'])&&$params['page_num']!=''){
$page=$params['page_num'];
}
if (empty($merchantIds)) {
return app('json')->success(['count' => 0, 'list' => []]);
}
// 隐藏镇级云仓
// $typeCloudWarehouseId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeCloudWarehouse'])->value('mer_type_id');
// $entryWhere = [
// 'street_id' => $params['street_code'],
// 'type_id' => $typeCloudWarehouseId,
// 'status' => 1,
// 'is_del' => 0,
// 'mer_state' => 1,
// ];
// if (!empty($params['category_id'])) {
// $entryWhere['category_id'] = $params['category_id'];
// }
// $where['entry_mer_id'] = $this->merchantDao->search($entryWhere)->value('mer_id');
// public function index()
// {
// // 除了市级供应链都可以查询
// $typeIdArray = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypePlatform'])->column('mer_type_id');
// $params = $this->request->params(['category_id', 'street_code', 'order', ['product_type', 0], 'keyword','page_num']);
// $search = [
// // 'street_id' => $params['street_code'],
// 'type_id' => $typeIdArray ?? [],
// 'status' => 1,
// 'is_del' => 0,
// 'mer_state' => 1,
// ];
// if (!empty($params['category_id'])) {
// $search['category_id'] = $params['category_id'];
// }
// $merchantIds = $this->merchantDao->search($search)->column('mer_id');
// [$page, $limit] = $this->getPage();
// if(isset($params['page_num'])&&$params['page_num']!=''){
// $page=$params['page_num'];
// }
// if (empty($merchantIds)) {
// return app('json')->success(['count' => 0, 'list' => []]);
// }
// // 隐藏镇级云仓
// // $typeCloudWarehouseId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeCloudWarehouse'])->value('mer_type_id');
// // $entryWhere = [
// // 'street_id' => $params['street_code'],
// // 'type_id' => $typeCloudWarehouseId,
// // 'status' => 1,
// // 'is_del' => 0,
// // 'mer_state' => 1,
// // ];
// // if (!empty($params['category_id'])) {
// // $entryWhere['category_id'] = $params['category_id'];
// // }
// // $where['entry_mer_id'] = $this->merchantDao->search($entryWhere)->value('mer_id');
$where['entry_mer_id'] = 0;
$where['keyword'] = $params['keyword'];
$where['mer_ids'] = $merchantIds;
$where['product_type'] = $params['product_type'];
$where['is_gift_bag'] = 0;
$where['order'] = $params['order'] ?: 'sort';
$products = $this->spuRepository->getApiCloudSearch($where, $page, $limit, false);
return app('json')->success($products);
}
// $where['entry_mer_id'] = 0;
// $where['keyword'] = $params['keyword'];
// $where['mer_ids'] = $merchantIds;
// $where['product_type'] = $params['product_type'];
// $where['is_gift_bag'] = 0;
// $where['order'] = $params['order'] ?: 'sort';
// $products = $this->spuRepository->getApiCloudSearch($where, $page, $limit, false);
// return app('json')->success($products);
// }
/**
* 云仓商品列表
* @return mixed
*/
public function index($street_code,$page_num=1,$category_id=0){
if($category_id==0){
return app('json')->fail('分类id不能为0');
}
$cloud_product=Db::name('cloud_product')->where('street_code',$street_code)->where('category_id',$category_id)->where('status',1)->page($page_num)->column('product_id');
if(!$cloud_product){
return app('json')->success(['count'=>0,'list'=>[]]);
}
$where=[
'is_show'=>1,
'is_used'=>1,
'status'=>1,
'is_del'=>0,
'mer_status'=>1,
];
$count=Db::name('cloud_product')->where('street_code',$street_code)->where('status',1)->count();
$select=Db::name('store_product')->whereIn('product_id',$cloud_product)->where($where)
->withAttr('merchant',function($value,$data){
return Db::name('merchant')->where('mer_id',$data['mer_id'])->field('mer_id,mer_name')->find();
})
->withAttr('sku',function($value,$data){
$find= Db::name('store_product_attr_value')->where('mer_id',$data['mer_id'])->where('product_id',$data['product_id'])->find();
return[''=>$find];
})
// ->field('product_id,mer_id,store_name,bar_code,price,stock,product_type,image')
->select();
return app('json')->success(['count'=>$count,'list'=>$select]);
}
}

View File

@ -3,25 +3,45 @@ namespace app\controller\api\store\product;
use app\common\dao\system\merchant\MerchantDao;
use app\common\model\system\merchant\Merchant;
use app\common\repositories\store\product\ProductRepository;
use app\controller\admin\ProductLibrary;
use think\facade\Db;
use crmeb\basic\BaseController;
use Exception;
class StoreMicro extends BaseController
{
function seach_bar_code($mer_id,$code='',$name=''){
$category_id=Db::name('merchant')->where('mer_id',$mer_id)->value('category_id');
$typePlatformId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypePlatform'])->value('mer_type_id');
$platformMerId = app()->make(MerchantDao::class)->getValidMerchant(['category_id' => $category_id, 'type_id' => $typePlatformId], 'mer_id')->value('mer_id');
$productWhere = ['is_show' => 1, 'status' => 1, 'mer_status' => 1, 'is_del' => 0];
function seach_bar_code($code='',$name=''){
$where = ['is_used' => 1, 'status' => 1, 'is_del' => 0];
$field = 'id,store_name,bar_code,manu_address,price,stock,image,slider_image,spec,trademark,manu_name,manu_address,note';
if($code!=''){
if (strlen($code) != 13) {
return app('json')->success('条形码长度不正确');
$res=Db::name('product_library')->where('bar_code',$code)->where($where)->field($field)
->withAttr('slider_image',function($value,$data){
return $value?explode(',',$value):[];
})
->find();
if($res==null){
$ProductLibrary = app()->make(ProductLibrary::class);
try{
$ProductLibrary->caiji($code);
$res=Db::name('product_library')->where('bar_code',$code)->where($where)->field($field)
->withAttr('slider_image',function($value,$data){
return $value?explode(',',$value):[];
})
->find();
}catch(Exception $e){
return app('json')->fail('编码:'.$code.'。'.$e->getMessage());
}
}
$product_id_arr=Db::name('store_product_attr_value')->where('mer_id',$platformMerId)->where('bar_code',$code)->column('product_id');
$product_id_arr=implode(',',$product_id_arr);
$find=Db::name('store_product')->where('product_id',$product_id_arr)->where($productWhere)->select();
$find[]=$res;
}else{
$find=Db::name('store_product')->where('mer_id',$platformMerId)->where('store_name','like','%'.$name.'%')->where($productWhere)->select();
if($name==''){
return app('json')->fail('参数不能为空');
}
$find=Db::name('product_library')->where('store_name','like','%'.$name.'%')->where($where)->field($field)
->withAttr('slider_image',function($value,$data){
return $value?explode(',',$value):[];
})
->select();
}
if (count($find)==0){
if($code!=''){
@ -49,48 +69,129 @@ class StoreMicro extends BaseController
//提交导入商品id
public function ProductImport(){
$product_id = $this->request->param('id', 0);
$id = $this->request->param('id', 0);
$price = $this->request->param('price', 0);
$stock = $this->request->param('stock', 0);
$store_name = $this->request->param('store_name', '');
$user = $this->request->userInfo();
$where = ['is_used' => 1, 'status' => 1, 'is_del' => 0];
try {
/** @var ProductRepository $productRepository */
$productRepository = app()->make(ProductRepository::class);
$a = $productRepository->import($product_id, $user);
$mer_id = Db::name('store_service')->where('uid', $user['uid'])->where('status', 1)->value('mer_id');
if ($mer_id == 0) {
return app('json')->fail('商户不存在');
}
$mer= Db::name('merchant')->where('mer_id', $mer_id)->find();
$category_name= Db::name('merchant_category')->where('merchant_category_id', $mer['category_id'])->value('category_name');
$store_category_id= Db::name('store_category')->where(['cate_name'=>$category_name,'level'=>2,'mer_id'=>0])->value('store_category_id');
if(!$store_category_id){
return app('json')->fail('没有对应的分类,请联系工作人员添加');
}
$find=Db::name('product_library')->where('id',$id)->where($where)->find();
if ($find) {
$exist = Db::name('store_product')->where('source_library_id', $id)->where('mer_id', $mer_id)->find();
if ($exist) {
// return app('json')->fail('已经导入过该商品了');
}
$find['attrValue']=[
['image'=>$find['image'],'price'=>$price,'cost'=>$find['cost'],'ot_price'=>$find['ot_price'],
'svip_price'=>0,'stock'=>$stock,'bar_code'=>$find['bar_code'],'weight'=>0,'volume'=>0,'detail'=>''
]];
if($mer['type_id']==12){
$product_type=98;
}else{
$product_type=0;
}
$find['store_name'] =$store_name??$find['store_name'];
$find['content'] =['image'=>explode(',',$find['images'])];
$find['slider_image'] =explode(',',$find['slider_image']);
$find['is_show'] = 1;
$find['mer_id'] = $mer_id;
$find['temp_id'] = "";
$find['give_coupon_ids'] = [];
$find['params'] = [];
$find['extend'] = [];
$find['param_temp_id'] = [];
$find['mer_labels'] = [];
$find['delivery_way'] = [0 => "2",1=>'1'];
$find["guarantee_template_id"] = "";
$find['product_type'] = $product_type;
$find['mer_cate_id'] = [0 => 0];
$find['is_used'] = 1;
$find['status'] = 1;
$find['mer_status'] = 1;
$find['source_product_id'] = 0;
$find['source_library_id'] = $find['id'];
$find['spec_type'] = 0;
$find['delivery_free'] = 0;
$find['cate_id'] = $store_category_id;
$find['svip_price_type'] = 0;
$find['svip_price'] =0;
unset($find['create_time'], $find['id']);
}
$a= app()->make( ProductRepository::class)->create($find,$product_type,1);
if($a){
return app('json')->success(['data'=>['product_id'=>$a],'msg'=>'导入成功']);
}else{
return app('json')->fail('导入失败');
}
} catch (\Exception $e) {
return app('json')->fail($e->getMessage());
}
if($a){
return app('json')->success(['data'=>$a,'msg'=>'导入成功']);
}else{
return app('json')->fail('导入失败');
}
}
public function eadtProduct(){
$product_id = $this->request->param('id', 0);
if ($product_id==0) return app('json')->fail('商品id不能为空');
$price = $this->request->param('price', 0);
if ($price==0) return app('json')->fail('价格不能为空');
$stock = $this->request->param('stock', 0);
if ($stock==0) return app('json')->fail('库存不能为空');
$user = $this->request->userInfo();
$mer_id =Db::name('store_service')->where('uid',$user['uid'])->where('status',1)->value('mer_id');
if ($mer_id==0) return app('json')->fail('商户id不能为空');
$data = [
'price'=>$price,
'stock'=>$stock,
];
Db::startTrans();
$id = $this->request->param('id', 0);
$image = $this->request->param('image', '');
$slider_image = $this->request->param('slider_image', '');
if ($slider_image=='') return app('json')->fail('轮播图不能为空');
if ($image=='') return app('json')->fail('首屏图不能为空');
try {
Db::name('store_product')->where('mer_id',$mer_id)->where('product_id',$product_id)->update($data);
Db::name('store_product_attr_value')->where('mer_id',$mer_id)->where('product_id',$product_id)->update($data);
// 提交事务
Db::commit();
return app('json')->success(['data'=>'','msg'=>'更新成功']);
$res=Db::name('product_library')->where('id',$id)->update(['image'=>$image,'slider_image'=>$slider_image]);
if($res){
return app('json')->success('更新成功');
}else{
return app('json')->fail('更新失败');
}
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return app('json')->fail($e->getMessage());
}
}
/**
* 待审核添加
*/
public function add()
{
$param = $this->request->param();
$uid=$this->request->userInfo()['uid'];
$mer_id=Db::name('store_service')->where(['uid'=>$uid,'status'=>1,'is_del'=>0,'is_goods'=>1])->value('mer_id');
$data['store_name'] = $param['store_name'];
$data['bar_code'] = $param['bar_code'];
$data['store_info'] = '';
$data['keyword'] = '';
$data['cate_id'] = 0;
$data['unit_name'] = '';
$data['is_used'] = 1;
$data['status'] = 1;
$data['price'] = $param['price'];
$data['stock'] = $param['stock'];
$data['create_time'] = date('Y-m-d H:i:s');
$data['image'] = $param['image'];
$data['slider_image'] = $param['slider_image'];
$data['images'] = $param['images'];
$data['mer_id'] = $mer_id;
$data['product_library_id'] = $param['product_library_id'];
$res = Db::name('product_library_examine')->insert($data);
if ($res) {
return app('json')->success('添加成功,等待审核');
} else {
return app('json')->fail('添加失败');
}
}
}

View File

@ -14,6 +14,7 @@ namespace app\controller\api\user;
use crmeb\basic\BaseController;
use app\common\repositories\user\UserBillRepository;
use app\common\repositories\system\RelevanceRepository;
use think\App;
use think\exception\HttpResponseException;
use think\exception\ValidateException;
@ -97,26 +98,42 @@ class Zhibo extends BaseController
[$page, $limit] = $this->getPage();
$token = request()->header('x-token');
$params = $this->request->params(['type']);
if (empty($params['type'])) {
return app('json')->fail('类型不能为空');
}
$user = $this->request->userInfo();
$where = [];
$queryBuilder = Db::name('user_bill')->alias('ub')->leftJoin('user_zhibo_order uzo','uzo.order_id = ub.link_id')->leftJoin('user u','u.uid = uzo.uid');
if ($params['type'] == 1) {
// 送出的礼物
$where['ub.pm'] = 0;
$where['ub.type'] = 'zhibo_reward';
$where['ub.type'] = 'zhibo_reward_dec';
$where['uzo.uid'] = $user['uid'];
$queryBuilder = $queryBuilder->where($where);
} elseif ($params['type'] == 2){
// 收到的礼物
$where['ub.pm'] = 1;
$where['ub.type'] = 'zhibo_reward';
$where['ub.type'] = 'zhibo_reward_inc';
$where['uzo.master_id'] = $user['uid'];
$queryBuilder = $queryBuilder->where($where);
} else {
return app('json')->fail('类型错误');
$whereUser['ub.pm'] = 0;
$whereUser['ub.type'] = 'zhibo_reward_dec';
$whereUser['uzo.uid'] = $user['uid'];
$whereMaster['ub.pm'] = 1;
$whereMaster['ub.type'] = 'zhibo_reward_inc';
$whereMaster['uzo.master_id'] = $user['uid'];
$queryBuilder = $queryBuilder->where(function ($query) use($whereUser) {
$query->where($whereUser);
});
$queryBuilder = $queryBuilder->whereOr(function ($query) use($whereMaster) {
$query->where($whereMaster);
});
}
$count = Db::name('user_bill')->alias('ub')->leftJoin('user_zhibo_order uzo','uzo.order_id = ub.link_id')->where($where)->count();
$list = Db::name('user_bill')->alias('ub')->leftJoin('user_zhibo_order uzo','uzo.order_id = ub.link_id')->where($where)->limit(($page-1) * $limit, $limit)->field([
$count = $queryBuilder->fetchSql(false)->count();
$list = $queryBuilder->limit(($page-1) * $limit, $limit)->setOption('field',[])->field([
'uzo.uid',
'uzo.master_id',
'u.nickname',
'u.avatar',
'uzo.order_id',
'uzo.live_stream_id',
'uzo.live_name',
@ -127,6 +144,29 @@ class Zhibo extends BaseController
'ub.title',
'uzo.create_time'
])->select();
return app('json')->success(compact('count', 'list'));
}
//用户送礼收礼汇总
public function rewardAmount()
{
$liveStreamId = $this->request->param('live_stream_id', 0);
$gift_num = Db::name('user_zhibo_order')->where('live_stream_id', $liveStreamId)->sum('gift_num');
$gift_amount = Db::name('user_zhibo_order')->where('live_stream_id', $liveStreamId)->sum('amount');
return app('json')->success(compact('gift_num', 'gift_amount'));
}
// 获取主播粉丝关注数
public function fansNum()
{
$params = $this->request->params(['master_id']);
if (empty($params['master_id'])) {
return app('json')->fail('主播用户id不能为空');
}
$data['fan_num'] = app()->make(RelevanceRepository::class)->getUserFans(intval($params['master_id']), 1, 1, 1);
$data['focus_num'] = app()->make(RelevanceRepository::class)->getUserFocus(intval($params['master_id']), 1, 1, 1);
return app('json')->success($data);
}
}

View File

@ -66,6 +66,7 @@ return [
'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class],
// 'community_address'=>[\app\listener\CommunityAddress::class],
'order.paySuccessOrder'=>[\app\listener\paySuccessOrder::class],
'order.paySuccess'=>[\app\listener\paySuccess::class],
'pay_success_margin'=>[\app\listener\paySuccessMargin::class],
'order.sendGoodsCode'=>[\app\listener\SendGoodsCode::class],
'product.create'=>[\app\listener\ProductCreate::class],

View File

@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace app\listener;
use app\common\model\system\merchant\Merchant;
use app\common\repositories\store\product\ProductRepository;
use think\facade\Db;
/**
* 备份数据请勿删除
*/
class ProductCreate
{
public function handle($event)
{
$product = $event['product'];
$data = $event['data'];
$contentType = $event['conType'];
$merchant = Db::name('merchant')->where('status', 1)->where('is_del', 0)->where('mer_id', $product['mer_id'])->find();
if (empty($merchant)) {
return false;
}
// 根据支持同步到云商的商户进行同步操作
$syncMerArray = Db::name('MerchantType')->where('is_sync_prod', 1)->column('mer_type_id');
if (!in_array($merchant['type_id'], $syncMerArray)) {
return false;
}
$typeCloudWarehouseId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeCloudWarehouse'])->value('mer_type_id');
$typePlatformId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypePlatform'])->value('mer_type_id');
if ($merchant['type_id'] == $typePlatformId || $merchant['type_id'] == $typeCloudWarehouseId) {
return false;
}
//查询市级云仓
$cityMerchant = Db::name('merchant')->where('status', 1)->where('mer_state', 1)->where('category_id', $merchant['category_id'])->where('type_id', Merchant::TypePlatform)->find();
if ($cityMerchant == null) {
return false;
}
$product_id = Db::name('store_product')->where('mer_id', $cityMerchant['mer_id'])->where('bar_code', $product['bar_code'])->value('product_id');
if ($product_id) {
return false;
}
$data['mer_id'] = $cityMerchant['mer_id'];
$data['status'] = $cityMerchant['is_audit'] ? 0 : 1;
$data['mer_status'] = ($cityMerchant['is_del'] || !$cityMerchant['mer_state'] || !$cityMerchant['status']) ? 0 : 1;
$data['rate'] = 3;
// $typeSupplyChainId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeSupplyChain'])->value('mer_type_id');
// $productType = $cityMerchant['type_id'] == $typeSupplyChainId ? 98 : 0;
$productType =0;
$data['update_time'] = date('Y-m-d H:i:s');
app()->make(ProductRepository::class)->create($data, $productType, $contentType);
}
}

View File

@ -1,57 +1,65 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
namespace app\listener;
use app\common\model\system\merchant\Merchant;
use app\common\repositories\store\product\ProductRepository;
use think\facade\Db;
use think\facade\Log;
class ProductCreate
{
public function handle($event)
{
Log::error(json_encode($event));
$product = $event['product'];
$data = $event['data'];
$contentType = $event['conType'];
// $data = $event['data'];
// $contentType = $event['conType'];
//查询当前商品的店铺
$merchant = Db::name('merchant')->where('status', 1)->where('is_del', 0)->where('mer_id', $product['mer_id'])->find();
if (empty($merchant)) {
return false;
}
$typeCloudWarehouseId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeCloudWarehouse'])->value('mer_type_id');
$typePlatformId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypePlatform'])->value('mer_type_id');
if ($merchant['type_id'] == $typePlatformId || $merchant['type_id'] == $typeCloudWarehouseId) {
if($merchant['type_id']!=Merchant::TypeTownSupplyChain){
return false;
}
// 根据支持同步到云商的商户进行同步操作
$syncMerArray = Db::name('MerchantType')->where('is_sync_prod', 1)->column('mer_type_id');
if (!in_array($merchant['type_id'], $syncMerArray)) {
// $syncMerArray = Db::name('MerchantType')->where('is_sync_prod', 1)->column('mer_type_id');
// if (!in_array($merchant['type_id'], $syncMerArray)) {
// return false;
// }
// $typeCloudWarehouseId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeCloudWarehouse'])->value('mer_type_id');
// $typePlatformId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypePlatform'])->value('mer_type_id');
// if ($merchant['type_id'] == $typePlatformId || $merchant['type_id'] == $typeCloudWarehouseId) {
// return false;
// }
//查询市级供应链
$cityMerchant = Db::name('merchant')->where('status', 1)->where('mer_state', 1)->where('category_id', $merchant['category_id'])->where('type_id', Merchant::TypeSupplyChain)->find();
if ($cityMerchant == null) {
return false;
}
//市级云仓
$cityMerchant = Db::name('merchant')->where('status', 1)->where('mer_state', 1)->where('category_id', $merchant['category_id'])->where('type_id', $typePlatformId)->find();
if ($cityMerchant) {
$where = ['mer_id' => $cityMerchant['mer_id'], 'is_del' => 0];
if ($product['bar_code'] != '' && in_array($product['product_type'], [0, 98]) && $product['spec_type'] == 0) {
$where['bar_code'] = $product['bar_code'];
} else {
$where['store_name'] = $product['store_name'];
}
$exist = Db::name('store_product')->where($where)->find();
if (!$exist) {
$data['mer_id'] = $cityMerchant['mer_id'];
$data['status'] = $cityMerchant['is_audit'] ? 0 : 1;
$data['mer_status'] = ($cityMerchant['is_del'] || !$cityMerchant['mer_state'] || !$cityMerchant['status']) ? 0 : 1;
$data['rate'] = 3;
$typeSupplyChainId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeSupplyChain'])->value('mer_type_id');
$productType = $cityMerchant['type_id'] == $typeSupplyChainId ? 98 : 0;
$data['update_time'] = date('Y-m-d H:i:s');
app()->make(ProductRepository::class)->create($data, $productType, $contentType);
}
//查询市级供应链商品
$product_id = Db::name('store_product')->where('mer_id', $cityMerchant['mer_id'])->where('bar_code', $product['bar_code'])->value('product_id');
if (!$product_id) {
return false;
}
//添加到云仓
$datas=[
'product_id'=>$product_id,
'mer_id'=>$merchant['mer_id'],
'source_mer_id'=>$cityMerchant['mer_id'],
'street_code'=>$merchant['street_id'],
'type_id'=>$merchant['type_id'],
'category_id'=>$merchant['category_id'],
'weight'=>1,
'status'=>1,
'create_time'=>date('Y-m-d H:i:s'),
];
Db::name('cloud_product')->insert($datas);
}
}

View File

@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
namespace app\listener;
use app\common\dao\store\order\StoreCartDao;
use app\common\dao\system\merchant\MerchantDao;
use app\common\model\system\merchant\Merchant;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\system\merchant\FinancialRecordRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use crmeb\utils\DingTalk;
use think\facade\Db;
use think\facade\Log;
/**
* 支付后逻辑
*/
class paySuccess
{
public $totalAmount;
public $event;
public $finance = [];
public $streetId;
public $financeSn;
public $index = 1;
public $remain;
public function handle($event)
{
try{
$orderList = $event['groupOrder']['orderList'];
foreach ($orderList as $k => $order) {
$merchant = Merchant::find($order['mer_id']);
//添加到代发订单表里
if($merchant['type_id']==Merchant::TypeSupplyChain){
$codes=explode(',',$order['user_address_code']);
if(count($codes)>4){
$merchant_two= Db::name('merchant')->where('street_id',$codes[3])->where('type_id',17)->where('category_id',$merchant['category_id'])->find();
if($merchant_two){
$datas=[
'master_mer_id'=>$order['mer_id'],
'mer_id'=>$merchant_two['mer_id'],
'order_id'=>$order['order_id'],
'status'=>1
];
Db::name('store_order_behalf')->insert($datas);
}
}
}
}
}catch(\Exception $e){
Log::error($e->getMessage().'lien:'.$e->getLine());
}
}
}

View File

@ -12,7 +12,9 @@ use app\common\repositories\system\merchant\MerchantRepository;
use crmeb\utils\DingTalk;
use think\facade\Db;
use think\facade\Log;
/**
* 支付后逻辑
*/
class paySuccessOrder
{
@ -26,6 +28,7 @@ class paySuccessOrder
public function handle($event)
{
Log::info('支付后逻辑22323233');
$this->event = $event;
$this->finance = [];
$this->index = 1;

View File

@ -23,7 +23,7 @@ class MerchantIntentionValidate extends Validate
'phone|手机号' => 'require|mobile',
'name|姓名' => 'require',
'mer_name|姓名' => 'require|max:32',
'merchant_category_id|商户分类' => 'require',
'merchant_category_name|商户分类' => 'require',
'mer_type_id|店铺类型' => 'integer',
'code|验证码' => 'require',
'images|资质' => 'array',

View File

@ -49,15 +49,16 @@
"phpoffice/phpspreadsheet": "^1.14",
"riverslei/payment": "^5.1",
"lizhichao/word": "^2.1",
"joypack/tencent-map": "^1.0",
"obs/esdk-obs-php": "^3.21",
"ucloud/ufile-php-sdk": "^1.0",
"swoole/ide-helper": "^4.8",
"alibabacloud/dysmsapi-20170525": "2.0.9",
"fastknife/ajcaptcha": "^1.1",
"vlucas/phpdotenv": "^5.3",
"overtrue/pinyin": "4.1.0",
"jpush/jpush": "^3.6"
"jpush/jpush": "^3.6",
"guzzlehttp/guzzle": "^6.5",
"topthink/think-api": "1.0.27",
"intervention/image": "^2.7"
},
"require-dev": {
"symfony/var-dumper": "^4.2",

3395
composer.lock generated

File diff suppressed because it is too large Load Diff

BIN
composer.phar Normal file

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 86 KiB

After

Width:  |  Height:  |  Size: 86 KiB

View File

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 82 KiB

View File

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 77 KiB

View File

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 80 KiB

View File

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 58 KiB

View File

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 84 KiB

View File

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

View File

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

View File

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

View File

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

View File

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB

View File

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 60 KiB

View File

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

View File

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View File

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

View File

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 79 KiB

View File

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

View File

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 59 KiB

View File

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

View File

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 82 KiB

View File

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

View File

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

View File

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 58 KiB

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