代购接口
This commit is contained in:
parent
080e3e4846
commit
f6a74428b8
160
app/common/dao/store/order/StoreCartDaoDg.php
Normal file
160
app/common/dao/store/order/StoreCartDaoDg.php
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
<?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\StoreCartDg as 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 StoreCartDaoDg 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();
|
||||||
|
}
|
||||||
|
}
|
335
app/common/model/store/order/StoreCartDg.php
Normal file
335
app/common/model/store/order/StoreCartDg.php
Normal file
@ -0,0 +1,335 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: CRMEB Team <admin@crmeb.com>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
namespace app\common\model\store\order;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\BaseModel;
|
||||||
|
use app\common\model\store\product\Product;
|
||||||
|
use app\common\model\store\product\ProductAssistSet;
|
||||||
|
use app\common\model\store\product\ProductAttr;
|
||||||
|
use app\common\model\store\product\ProductAttrValue;
|
||||||
|
use app\common\model\store\product\ProductGroup;
|
||||||
|
use app\common\model\store\product\ProductPresell;
|
||||||
|
use app\common\model\store\product\ProductPresellSku;
|
||||||
|
use app\common\model\store\product\ProductSku;
|
||||||
|
use app\common\model\store\product\Spu;
|
||||||
|
use app\common\model\store\product\StoreDiscounts;
|
||||||
|
use app\common\model\system\merchant\Merchant;
|
||||||
|
use app\common\repositories\store\order\StoreOrderProductRepository;
|
||||||
|
use app\common\repositories\store\order\StoreOrderRepository;
|
||||||
|
use app\common\repositories\store\product\ProductAssistSkuRepository;
|
||||||
|
use app\common\repositories\store\product\ProductAttrValueRepository;
|
||||||
|
use app\common\repositories\store\product\ProductGroupSkuRepository;
|
||||||
|
use app\common\repositories\store\product\ProductPresellSkuRepository;
|
||||||
|
use app\common\repositories\store\product\ProductSkuRepository;
|
||||||
|
use app\common\repositories\store\StoreSeckillActiveRepository;
|
||||||
|
use function Symfony\Component\String\b;
|
||||||
|
|
||||||
|
class StoreCartDg extends BaseModel
|
||||||
|
{
|
||||||
|
|
||||||
|
public static function tablePk(): ?string
|
||||||
|
{
|
||||||
|
return 'cart_id';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tableName(): string
|
||||||
|
{
|
||||||
|
return 'store_cart_dg';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function searchCartIdAttr($query,$value)
|
||||||
|
{
|
||||||
|
$query->where('cart_id',$value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function product()
|
||||||
|
{
|
||||||
|
return $this->hasOne(Product::class, 'product_id', 'product_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function productAttr()
|
||||||
|
{
|
||||||
|
return $this->hasOne(ProductAttrValue::class, 'unique', 'product_attr_unique');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attr()
|
||||||
|
{
|
||||||
|
return $this->hasMany(ProductAttr::class,'product_id','product_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attrValue()
|
||||||
|
{
|
||||||
|
return $this->hasMany(ProductAttrValue::class, 'product_id', 'product_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function merchant()
|
||||||
|
{
|
||||||
|
return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function productPresell()
|
||||||
|
{
|
||||||
|
return $this->hasOne(ProductPresell::class,'product_presell_id','source_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function productDiscount()
|
||||||
|
{
|
||||||
|
return $this->hasOne(StoreDiscounts::class, 'discount_id', 'source_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProductDiscountAttrAttr()
|
||||||
|
{
|
||||||
|
return app()->make(ProductSkuRepository::class)->getSearch(['active_id' => $this->source_id, 'unique' => $this->product_attr_unique])->find();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function productAssistSet()
|
||||||
|
{
|
||||||
|
return $this->hasOne(ProductAssistSet::class,'product_assist_set_id','source_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProductPresellAttrAttr()
|
||||||
|
{
|
||||||
|
return app()->make(ProductPresellSkuRepository::class)->getSearch(['product_presell_id' => $this->source_id, 'unique' => $this->product_attr_unique])->find();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProductAssistAttrAttr()
|
||||||
|
{
|
||||||
|
$make = app()->make(ProductAssistSkuRepository::class);
|
||||||
|
$where = [
|
||||||
|
"product_assist_id" => $this->productAssistSet->product_assist_id,
|
||||||
|
"unique" => $this->product_attr_unique
|
||||||
|
];
|
||||||
|
return $make->getSearch($where)->find();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO 活动商品 SKU
|
||||||
|
* @return array|\think\Model|null
|
||||||
|
* @author Qinii
|
||||||
|
* @day 1/13/21
|
||||||
|
*/
|
||||||
|
public function getActiveSkuAttr()
|
||||||
|
{
|
||||||
|
switch ($this->product_type)
|
||||||
|
{
|
||||||
|
case 2:
|
||||||
|
$make = app()->make(ProductPresellSkuRepository::class);
|
||||||
|
$where['product_presell_id'] = $this->source_id;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
$make = app()->make(ProductAssistSkuRepository::class);
|
||||||
|
$where['product_assist_id'] = $this->productAssistSet->product_assist_id;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
$make = app()->make(ProductGroupSkuRepository::class);
|
||||||
|
$where['product_group_id'] = $this->product->productGroup->product_group_id;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$make = app()->make(ProductAttrValueRepository::class);
|
||||||
|
$where['product_id'] = $this->product_id;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$where['unique'] = $this->product_attr_unique;
|
||||||
|
return $make->getSearch($where)->find();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSpuAttr()
|
||||||
|
{
|
||||||
|
if ($this->product_type) {
|
||||||
|
$where = [
|
||||||
|
'activity_id' => $this->source_id,
|
||||||
|
'product_type' => $this->product_type,
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$where = [
|
||||||
|
'product_id' => $this->product_id,
|
||||||
|
'product_type' => $this->product_type,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return Spu::where($where)->field('spu_id,store_name')->find();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* TODO 检测商品是否有效
|
||||||
|
* @return bool
|
||||||
|
* @author Qinii
|
||||||
|
* @day 2020-10-29
|
||||||
|
*/
|
||||||
|
public function getCheckCartProductAttr()
|
||||||
|
{
|
||||||
|
if($this->is_fail == 1) return false;
|
||||||
|
|
||||||
|
if(is_null($this->product) || is_null($this->productAttr) || $this->product->status !== 1 || $this->product->mer_status !== 1 || $this->product->is_del !== 0)
|
||||||
|
{$this->is_fail = 1;$this->save();return false;}
|
||||||
|
|
||||||
|
switch ($this->product_type)
|
||||||
|
{
|
||||||
|
case 0: //普通商品
|
||||||
|
if ($this->product->product_type !== 0 || $this->product->is_show !== 1 || $this->productAttr->stock < $this->cart_num || $this->product->is_used !== 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1: //秒杀商品
|
||||||
|
if ($this->product->product_type !== 1 || $this->product->is_show !== 1) return false;
|
||||||
|
//结束时间
|
||||||
|
if ($this->product->end_time < time()) return false;
|
||||||
|
//限量
|
||||||
|
$order_make = app()->make(StoreOrderRepository::class);
|
||||||
|
$count = $order_make->seckillOrderCounut($this->product_id);
|
||||||
|
if ($this->productAttr->stock <= $count) return false;
|
||||||
|
|
||||||
|
//原商品sku库存
|
||||||
|
$value_make = app()->make(ProductAttrValueRepository::class);
|
||||||
|
$sku = $value_make->getWhere(['sku' => $this->productAttr->sku, 'product_id' => $this->product->old_product_id]);
|
||||||
|
if (!$sku || $sku['stock'] <= 0) return false;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2: //预售商品
|
||||||
|
if($this->source !== 2 || $this->product->product_type !== 2) return false;
|
||||||
|
if($this->productPresell->status !== 1 ||
|
||||||
|
$this->productPresell->is_show !== 1 ||
|
||||||
|
$this->productPresell->is_del !== 0 ||
|
||||||
|
$this->productPresell->presell_status !== 1)
|
||||||
|
{$this->is_fail = 1;$this->save();return false;}
|
||||||
|
|
||||||
|
$sku = $this->ActiveSku;
|
||||||
|
if(!$sku || !$sku->sku()) {$this->is_fail = 1; $this->save(); return false; }
|
||||||
|
|
||||||
|
//库存不足
|
||||||
|
if($sku->stock < $this->cart_num || $sku->sku->stock < $this->cart_num) return false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3: //助力商品
|
||||||
|
if($this->source !== 3 || $this->product->product_type !== 3 || ($this->productAssistSet->assist_count !== $this->productAssistSet->yet_assist_count)) return false;
|
||||||
|
if(
|
||||||
|
$this->productAssistSet->stop_time < time() ||
|
||||||
|
$this->productAssistSet->sataus === -1 ||
|
||||||
|
!$this->productAssistSet->assist->is_show ||
|
||||||
|
$this->productAssistSet->assist->is_del !== 0 ||
|
||||||
|
$this->productAssistSet->assist->status !== 1)
|
||||||
|
{$this->is_fail = 1;$this->save();return false;}
|
||||||
|
$sku = $this->ActiveSku;
|
||||||
|
if(!$sku || !$sku->sku()) { $this->is_fail = 1; $this->save(); return false; }
|
||||||
|
//库存不足
|
||||||
|
if($sku->stock < $this->cart_num || $sku->sku->stock < $this->cart_num) return false;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if($this->source !== 4 || $this->product->product_type !== 4 ) return false;
|
||||||
|
$sku = $this->ActiveSku;
|
||||||
|
if(!$sku || !$sku->sku()) { $this->is_fail = 1; $this->save(); return false; }
|
||||||
|
//库存不足
|
||||||
|
if($sku->stock < $this->cart_num || $sku->sku->stock < $this->cart_num) return false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
* @return bool
|
||||||
|
* @author Qinii
|
||||||
|
* @day 2020-10-29
|
||||||
|
*/
|
||||||
|
public function getUserPayCountAttr()
|
||||||
|
{
|
||||||
|
$make = app()->make(StoreOrderRepository::class);
|
||||||
|
switch ($this->product_type)
|
||||||
|
{
|
||||||
|
case 1: //秒杀
|
||||||
|
if(!$make->getDayPayCount($this->uid,$this->product_id) || !$make->getPayCount($this->uid,$this->product_id))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case 2: //预售
|
||||||
|
$count = $this->productPresell->pay_count;
|
||||||
|
if($count == 0) return true;
|
||||||
|
$tattend = [
|
||||||
|
'activity_id' => $this->source_id,
|
||||||
|
'product_type' => 2,
|
||||||
|
];
|
||||||
|
$pay_count = $make->getTattendCount($tattend,$this->uid)->sum('total_num');
|
||||||
|
if($pay_count < $count) return false;
|
||||||
|
if (($count - $pay_count) < $this->cart_num) return false;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3: //助力
|
||||||
|
$tattend = [
|
||||||
|
'activity_id' => $this->source_id,
|
||||||
|
'product_type' => 3,
|
||||||
|
];
|
||||||
|
$pay_count = $make->getTattendCount($tattend,$this->uid)->count();
|
||||||
|
if($pay_count) return false;
|
||||||
|
|
||||||
|
$count = $this->productAssistSet->assist->pay_count;
|
||||||
|
if($count !== 0){
|
||||||
|
$_tattend = [
|
||||||
|
'exsits_id' => $this->productAssistSet->assist->product_assist_id,
|
||||||
|
'product_type' => 3,
|
||||||
|
];
|
||||||
|
$_count = $make->getTattendCount($_tattend,$this->uid)->count();
|
||||||
|
if($_count >= $count) return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
$tattend = [
|
||||||
|
'exsits_id' => $this->product_id,
|
||||||
|
'product_type' => 4,
|
||||||
|
];
|
||||||
|
$pay_count = $make->getTattendCount($tattend,$this->uid)->count();
|
||||||
|
if($pay_count) return false;
|
||||||
|
$count = $this->product->productGroup->pay_count;
|
||||||
|
if($count !== 0){
|
||||||
|
$_tattend = [
|
||||||
|
'exsits_id' => $this->product_id,
|
||||||
|
'product_type' => 34,
|
||||||
|
];
|
||||||
|
$_count = $make->getTattendCount($_tattend,$this->uid)->count();
|
||||||
|
if($_count >= $count) return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function searchProductIdAttr($query,$value)
|
||||||
|
{
|
||||||
|
$query->where('product_id',$value);
|
||||||
|
}
|
||||||
|
public function searchUidAttr($query,$value)
|
||||||
|
{
|
||||||
|
$query->where('uid',$value);
|
||||||
|
}
|
||||||
|
public function searchIsNewAttr($query,$value)
|
||||||
|
{
|
||||||
|
$query->where('is_new',$value);
|
||||||
|
}
|
||||||
|
public function searchIsPayAttr($query,$value)
|
||||||
|
{
|
||||||
|
$query->where('is_pay',$value);
|
||||||
|
}
|
||||||
|
public function searchIsDelAttr($query,$value)
|
||||||
|
{
|
||||||
|
$query->where('is_del',$value);
|
||||||
|
}
|
||||||
|
public function searchIsFailAttr($query,$value)
|
||||||
|
{
|
||||||
|
$query->where('is_fail',$value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
130
app/common/repositories/store/order/StoreCartDgRepository.php
Normal file
130
app/common/repositories/store/order/StoreCartDgRepository.php
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
<?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\order;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\dao\store\order\StoreCartDaoDg as StoreCartDao;
|
||||||
|
use app\common\model\store\product\Product;
|
||||||
|
use app\common\repositories\BaseRepository;
|
||||||
|
use app\common\repositories\store\coupon\StoreCouponProductRepository;
|
||||||
|
use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||||
|
use app\common\repositories\store\product\ProductRepository;
|
||||||
|
use think\exception\ValidateException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class StoreCartRepository
|
||||||
|
* @package app\common\repositories\store\order
|
||||||
|
* @author xaboy
|
||||||
|
* @day 2020/5/30
|
||||||
|
* @mixin StoreCartDao
|
||||||
|
*/
|
||||||
|
class StoreCartDgRepository extends BaseRepository
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* StoreCartRepository constructor.
|
||||||
|
* @param StoreCartDao $dao
|
||||||
|
*/
|
||||||
|
public function __construct(StoreCartDao $dao)
|
||||||
|
{
|
||||||
|
$this->dao = $dao;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $uid
|
||||||
|
* @return array
|
||||||
|
* @author Qinii
|
||||||
|
*/
|
||||||
|
public function getList($user)
|
||||||
|
{
|
||||||
|
$res = $this->dao->getAll($user->uid)->append(['checkCartProduct', 'UserPayCount', 'ActiveSku', 'attrValue', 'attr','spu']);
|
||||||
|
$make = app()->make(ProductRepository::class);
|
||||||
|
$res->map(function ($item) use ($make) {
|
||||||
|
$item['attr'] = $make->detailAttr($item['attr']);
|
||||||
|
});
|
||||||
|
return $this->checkCartList($res, $user->uid, $user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkCartList($res, $hasCoupon = 0, $user = null)
|
||||||
|
{
|
||||||
|
$arr = $fail = [];
|
||||||
|
$product_make = app()->make(ProductRepository::class);
|
||||||
|
$svip_status = ($user && $user->is_svip > 0 && systemConfig('svip_switch_status')) ? true : false;
|
||||||
|
foreach ($res as $item) {
|
||||||
|
if (!$item['checkCartProduct']) {
|
||||||
|
$item['product'] = $product_make->getFailProduct($item['product_id']);
|
||||||
|
$fail[] = $item;
|
||||||
|
} else {
|
||||||
|
$merchantData = $item['merchant']->append(['openReceipt'])->toArray();
|
||||||
|
unset($item['merchant']);
|
||||||
|
$coupon_make = app()->make(StoreCouponRepository::class);
|
||||||
|
if (!isset($arr[$item['mer_id']])) {
|
||||||
|
if ($hasCoupon)
|
||||||
|
$merchantData['hasCoupon'] = $coupon_make->validMerCouponExists($item['mer_id'], $hasCoupon);
|
||||||
|
$arr[$item['mer_id']] = $merchantData;
|
||||||
|
}
|
||||||
|
if ($hasCoupon && !$arr[$item['mer_id']]['hasCoupon']) {
|
||||||
|
$couponIds = app()->make(StoreCouponProductRepository::class)->productByCouponId([$item['product']['product_id']]);
|
||||||
|
$arr[$item['mer_id']]['hasCoupon'] = count($couponIds) ? $coupon_make->validProductCouponExists([$item['product']['product_id']], $hasCoupon) : 0;
|
||||||
|
}
|
||||||
|
if ($svip_status && $item['product']['show_svip_price']) {
|
||||||
|
$item['productAttr']['show_svip_price'] = true;
|
||||||
|
$item['productAttr']['org_price'] = $item['productAttr']['price'];
|
||||||
|
$item['productAttr']['price'] = $item['productAttr']['svip_price'];
|
||||||
|
} else {
|
||||||
|
$item['productAttr']['show_svip_price'] = false;
|
||||||
|
}
|
||||||
|
$arr[$item['mer_id']]['list'][] = $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$list = array_values($arr);
|
||||||
|
return compact('list', 'fail');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取单条购物车信息
|
||||||
|
* @Author:Qinii
|
||||||
|
* @Date: 2020/5/30
|
||||||
|
* @param int $id
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
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];
|
||||||
|
return ($this->dao->getWhere($where));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看相同商品的sku是存在
|
||||||
|
* @param $sku
|
||||||
|
* @param $uid
|
||||||
|
* @author Qinii
|
||||||
|
*/
|
||||||
|
public function getCartByProductSku($sku,$uid)
|
||||||
|
{
|
||||||
|
$where = ['is_del'=>0,'is_fail'=>0,'is_new'=>0,'is_pay'=>0,'uid' => $uid,'product_type' => 0,'product_attr_unique' => $sku];
|
||||||
|
return ($this->dao->getWhere($where));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getProductById($productId)
|
||||||
|
{
|
||||||
|
$where = [
|
||||||
|
'is_del' =>0,
|
||||||
|
'is_new'=>0,
|
||||||
|
'is_pay'=>0,
|
||||||
|
'product_id'=>$productId
|
||||||
|
];
|
||||||
|
return $this->dao->getWhereCount($where);
|
||||||
|
}
|
||||||
|
}
|
@ -45,6 +45,10 @@ class EnterCompany extends BaseController
|
|||||||
$validate->check($data);
|
$validate->check($data);
|
||||||
$data['create_time'] = time();
|
$data['create_time'] = time();
|
||||||
$data['shop_user_id'] = $this->request->uid();
|
$data['shop_user_id'] = $this->request->uid();
|
||||||
|
$is_have = Db::connect('dev')->name('market_company')->where('shop_user_id',$this->request->uid())->find();
|
||||||
|
if($is_have){
|
||||||
|
return app('json')->fail('已经录入,不能重复录入');
|
||||||
|
}
|
||||||
$res = Db::connect('dev')->name('market_company')->insert($data);
|
$res = Db::connect('dev')->name('market_company')->insert($data);
|
||||||
return app('json')->success('添加成功');
|
return app('json')->success('添加成功');
|
||||||
}
|
}
|
||||||
|
379
app/controller/api/store/order/StoreCartDg.php
Normal file
379
app/controller/api/store/order/StoreCartDg.php
Normal file
@ -0,0 +1,379 @@
|
|||||||
|
<?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\repositories\store\order\StoreOrderRepository;
|
||||||
|
use app\common\repositories\store\product\ProductAssistRepository;
|
||||||
|
use app\common\repositories\store\product\ProductAssistSetRepository;
|
||||||
|
use app\common\repositories\store\product\ProductAttrValueRepository;
|
||||||
|
use app\common\repositories\store\product\ProductGroupRepository;
|
||||||
|
use app\common\repositories\store\product\ProductPresellRepository;
|
||||||
|
use app\common\repositories\store\product\ProductRepository;
|
||||||
|
use app\common\repositories\store\product\StoreDiscountProductRepository;
|
||||||
|
use app\common\repositories\store\product\StoreDiscountRepository;
|
||||||
|
use app\common\repositories\store\StoreSeckillActiveRepository;
|
||||||
|
use app\common\repositories\user\UserRepository;
|
||||||
|
use MongoDB\BSON\MaxKey;
|
||||||
|
use think\App;
|
||||||
|
use think\facade\Db;
|
||||||
|
use crmeb\basic\BaseController;
|
||||||
|
use app\validate\api\StoreCartValidate as validate;
|
||||||
|
use app\common\repositories\store\order\StoreCartDgRepository as repository;
|
||||||
|
use think\exception\ValidateException;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class StoreCartDg extends BaseController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var repository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StoreBrand constructor.
|
||||||
|
* @param App $app
|
||||||
|
* @param repository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(App $app, repository $repository)
|
||||||
|
{
|
||||||
|
parent::__construct($app);
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:Qinii
|
||||||
|
* @Date: 2020/5/28
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function lst()
|
||||||
|
{
|
||||||
|
[$page, $limit] = $this->getPage();
|
||||||
|
return app('json')->success($this->repository->getList($this->request->userInfo()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param validate $validate
|
||||||
|
* @return mixed
|
||||||
|
* @author Qinii
|
||||||
|
*/
|
||||||
|
public function create(validate $validate)
|
||||||
|
{
|
||||||
|
$data = $this->checkParams($validate);
|
||||||
|
|
||||||
|
if(!in_array($data['product_type'],[0,1,2,3,4])) return app('json')->fail('商品类型错误');
|
||||||
|
if ($data['cart_num'] <= 0) return app('json')->fail('购买数量有误');
|
||||||
|
$user = $this->request->userInfo();
|
||||||
|
event('user.cart.before',compact('user','data'));
|
||||||
|
switch ($data['product_type'])
|
||||||
|
{
|
||||||
|
case 0: //普通商品
|
||||||
|
$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);
|
||||||
|
break;
|
||||||
|
case 1: //秒杀商品
|
||||||
|
$result = app()->make(ProductRepository::class)->cartSeckillCheck($data,$this->request->userInfo());
|
||||||
|
break;
|
||||||
|
case 2: //预售商品
|
||||||
|
$result = app()->make(ProductPresellRepository::class)->cartCheck($data,$this->request->userInfo());
|
||||||
|
$data['source'] = $data['product_type'];
|
||||||
|
$data['source_id'] = $data['product_id'];
|
||||||
|
$data['product_id'] = $result['product']['product_id'];
|
||||||
|
break;
|
||||||
|
case 3: //助力商品
|
||||||
|
$result = app()->make(ProductAssistSetRepository::class)->cartCheck($data,$this->request->userInfo());
|
||||||
|
$data['source'] = $data['product_type'];
|
||||||
|
$data['source_id'] = $data['product_id'];
|
||||||
|
$data['product_id'] = $result['product']['product_id'];
|
||||||
|
break;
|
||||||
|
case 4: //拼团商品
|
||||||
|
$result = app()->make(ProductGroupRepository::class)->cartCheck($data,$this->request->userInfo());
|
||||||
|
$data['source'] = $data['product_type'];
|
||||||
|
$data['source_id'] = $data['group_buying_id'];
|
||||||
|
$data['product_id'] = $result['product']['product_id'];
|
||||||
|
break;
|
||||||
|
case 99: //小组代购
|
||||||
|
$result = app()->make(ProductGroupRepository::class)->cartCheck($data,$this->request->userInfo());
|
||||||
|
$data['source'] = $data['product_type'];
|
||||||
|
$data['source_id'] = $data['group_buying_id'];
|
||||||
|
$data['product_id'] = $result['product']['product_id'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($data['group_buying_id']);
|
||||||
|
|
||||||
|
if ($cart = $result['cart']) {
|
||||||
|
//更新购物车
|
||||||
|
$cart_id = $cart['cart_id'];
|
||||||
|
$cart_num = ['cart_num' => ($cart['cart_num'] + $data['cart_num'])];
|
||||||
|
$storeCart = $this->repository->update($cart_id,$cart_num);
|
||||||
|
} else {
|
||||||
|
//添加购物车
|
||||||
|
$data['uid'] = $this->request->uid();
|
||||||
|
$data['mer_id'] = $result['product']['mer_id'];
|
||||||
|
$cart = $storeCart = $this->repository->create($data);
|
||||||
|
}
|
||||||
|
event('user.cart', compact('user','storeCart'));
|
||||||
|
return app('json')->success(['cart_id' => $cart['cart_id']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $id
|
||||||
|
* @return mixed
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @author Qinii
|
||||||
|
*/
|
||||||
|
public function change($id)
|
||||||
|
{
|
||||||
|
$where = $this->request->params(['cart_num']);
|
||||||
|
$product_attr_unique = $this->request->param('product_attr_unique');
|
||||||
|
if (intval($where['cart_num']) < 0)
|
||||||
|
return app('json')->fail('数量必须大于0');
|
||||||
|
if (!$cart = $this->repository->getOne($id, $this->request->uid()))
|
||||||
|
return app('json')->fail('购物车信息不存在');
|
||||||
|
if ($cart->product->once_count) {
|
||||||
|
$cart_num = app()->make(ProductRepository::class)->productOnceCountCart($cart['product_id'], $this->request->uid());
|
||||||
|
if (($cart_num - $cart['cart_num'] + $where['cart_num']) > $cart->product->once_count)
|
||||||
|
return app('json')->fail('单次购买限制 ' . $cart->product->once_count . ' 件');
|
||||||
|
}
|
||||||
|
if (!$res = app()->make(ProductAttrValueRepository::class)->getOptionByUnique($product_attr_unique ?? $cart['product_attr_unique']))
|
||||||
|
return app('json')->fail('SKU不存在');
|
||||||
|
if ($res['stock'] < $where['cart_num'])
|
||||||
|
return app('json')->fail('库存不足');
|
||||||
|
if($product_attr_unique){
|
||||||
|
$where['product_attr_unique'] = $product_attr_unique;
|
||||||
|
}
|
||||||
|
$this->repository->update($id, $where);
|
||||||
|
return app('json')->success('修改成功');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $id
|
||||||
|
* @return mixed
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @author Qinii
|
||||||
|
* 保存委托代购人收货信息
|
||||||
|
*/
|
||||||
|
public function edit()
|
||||||
|
{
|
||||||
|
$params = $this->request->params(['cart_ids','name','address','phone']);
|
||||||
|
$map[] = ['uid','=',$this->request->uid()];
|
||||||
|
$map[] = ['cart_ids','=',$params['cart_ids']];
|
||||||
|
$is_have = Db::table('eb_store_cart_dg_nopay')->where($map)->find();
|
||||||
|
if($is_have){
|
||||||
|
$params['update_time'] = time();
|
||||||
|
$res = Db::table('eb_store_cart_dg_nopay')->where('id',$is_have['id'])->strict(false)->field(true)->update($params);
|
||||||
|
}else{
|
||||||
|
$params['create_time'] = time();
|
||||||
|
$params['uid'] = $this->request->uid();
|
||||||
|
$res = Db::table('eb_store_cart_dg_nopay')->strict(false)->field(true)->insert($params);
|
||||||
|
}
|
||||||
|
if($res){
|
||||||
|
return app('json')->success('保存成功');
|
||||||
|
}else{
|
||||||
|
return app('json')->fail('保存失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $id
|
||||||
|
* @return mixed
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @author Qinii
|
||||||
|
* 保存当前购物车数据
|
||||||
|
*/
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
$params = $this->request->params(['cart_ids','name','address','phone']);
|
||||||
|
$is_have = Db::table('eb_store_cart_dg_nopay')->where('uid',$this->request->uid())->find();
|
||||||
|
if($is_have){
|
||||||
|
$params['update_time'] = time();
|
||||||
|
Db::table('eb_store_cart_dg_nopay')->where('id',$is_have['id'])->strict(false)->field(true)->update($params);
|
||||||
|
$nopay_id = $is_have['id'];
|
||||||
|
}else{
|
||||||
|
$params['create_time'] = time();
|
||||||
|
$params['uid'] = $this->request->uid();
|
||||||
|
$nopay_id = Db::table('eb_store_cart_dg_nopay')->strict(false)->field(true)->insertGetId($params);
|
||||||
|
}
|
||||||
|
// 删除购物车里数据
|
||||||
|
$where[] = ['cate_id','in',$params['cart_ids']];
|
||||||
|
$data['is_del'] = 1;
|
||||||
|
$data['nopay_id'] = $nopay_id;
|
||||||
|
Db::table('eb_store_cart_dg')->where($where)->update($data);
|
||||||
|
Db::commit();
|
||||||
|
return app('json')->success('保存成功');
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Db::rollback();
|
||||||
|
return app('json')->fail('保存失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $id
|
||||||
|
* @return mixed
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @author Qinii
|
||||||
|
* 获取保存的未付款代购
|
||||||
|
*/
|
||||||
|
public function get_list($page=1,$limit=10)
|
||||||
|
{
|
||||||
|
// 判断是否已付款
|
||||||
|
$where['a.is_pay'] = 1;
|
||||||
|
$where['b.status'] = 0;
|
||||||
|
$where['a.uid'] = $this->request->uid();
|
||||||
|
$data['b.status'] = 1;
|
||||||
|
Db::table('eb_store_cart_dg')->alias('a')
|
||||||
|
->join('eb_store_cart_dg_nopay b','a.nopay_id = b.id')
|
||||||
|
->where($where)
|
||||||
|
->update($data);
|
||||||
|
|
||||||
|
$map['status'] = 0;
|
||||||
|
$map['uid'] = $this->request->uid();
|
||||||
|
$list = Db::table('eb_store_cart_dg_nopay')
|
||||||
|
->where($map)
|
||||||
|
->page($page,$limit)
|
||||||
|
->withAttr('goods',function ($value,$data){
|
||||||
|
$www[] = ['a.cart_id','in',$data['cart_ids']];
|
||||||
|
return Db::table('eb_store_cart_dg')->alias('a')->join('eb_store_product b','a.product_id = b.product_id')->field('a.cart_num,b.product_id,b.store_name')->where($www)->select();
|
||||||
|
})
|
||||||
|
->select();
|
||||||
|
if($list){
|
||||||
|
return app('json')->success($list);
|
||||||
|
}else{
|
||||||
|
return app('json')->fail('暂无数据');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
* @author Qinii
|
||||||
|
*/
|
||||||
|
public function batchDelete()
|
||||||
|
{
|
||||||
|
$ids = $this->request->param('cart_id');
|
||||||
|
if(!count($ids))return app('json')->fail('参数错误');
|
||||||
|
$this->repository->batchDelete($ids,$this->request->uid());
|
||||||
|
return app('json')->success('删除成功');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
* @author Qinii
|
||||||
|
*/
|
||||||
|
public function cartCount()
|
||||||
|
{
|
||||||
|
return app('json')->success($this->repository->getCartCount($this->request->uid()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $data
|
||||||
|
* @return mixed
|
||||||
|
* @author Qinii
|
||||||
|
* @day 2020-06-11
|
||||||
|
*/
|
||||||
|
public function check($data)
|
||||||
|
{
|
||||||
|
$product = app()->make(ProductRepository::class)->get($data['product_id']);
|
||||||
|
if(!$product)
|
||||||
|
throw new ValidateException('商品不存在');
|
||||||
|
if( $data['cart_num'] < 0 )
|
||||||
|
throw new ValidateException('数量必须大于0');
|
||||||
|
if(!$res= app()->make(ProductAttrValueRepository::class)->getOptionByUnique($data['product_attr_unique']))
|
||||||
|
throw new ValidateException('SKU不存在');
|
||||||
|
if($res['product_id'] != $data['product_id'])
|
||||||
|
throw new ValidateException('数据不一致');
|
||||||
|
if($res['stock'] < $data['cart_num'])
|
||||||
|
throw new ValidateException('库存不足');
|
||||||
|
$data['is_new'] = 1;
|
||||||
|
$data['uid'] = $this->request->uid();
|
||||||
|
$data['mer_id'] = $product['mer_id'];
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param validate $validate
|
||||||
|
* @return mixed
|
||||||
|
* @author Qinii
|
||||||
|
* @day 2020-06-11
|
||||||
|
*/
|
||||||
|
public function again(validate $validate)
|
||||||
|
{
|
||||||
|
$param = $this->request->param('data',[]);
|
||||||
|
foreach ($param as $data){
|
||||||
|
$validate->check($data);
|
||||||
|
$item[] = $this->check($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($item as $it){
|
||||||
|
$it__id = $this->repository->create($it);
|
||||||
|
$ids[] = $it__id['cart_id'];
|
||||||
|
}
|
||||||
|
return app('json')->success(['cart_id' => $ids]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param validate $validate
|
||||||
|
* @return array
|
||||||
|
* @author Qinii
|
||||||
|
* @day 2020-06-11
|
||||||
|
*/
|
||||||
|
public function checkParams(validate $validate)
|
||||||
|
{
|
||||||
|
$data = $this->request->params(['product_id','product_attr_unique','cart_num','is_new',['product_type',0],['group_buying_id',0],['spread_id',0]]);
|
||||||
|
$validate->check($data);
|
||||||
|
if ($data['spread_id']) {
|
||||||
|
if ($data['spread_id'] !== $this->request->userInfo()->uid){
|
||||||
|
$user = app()->make(UserRepository::class)->get($data['spread_id']);
|
||||||
|
if (!$user) $data['spread_id'] = 0;
|
||||||
|
} else {
|
||||||
|
$data['spread_id'] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO 套餐购买
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author Qinii
|
||||||
|
* @day 1/7/22
|
||||||
|
*/
|
||||||
|
public function batchCreate()
|
||||||
|
{
|
||||||
|
$data = $this->request->params(['data','discount_id','is_new']);
|
||||||
|
$productRepostory = app()->make(ProductRepository::class);
|
||||||
|
if (!$data['discount_id'])
|
||||||
|
return app('json')->fail('优惠套餐ID不能为空');
|
||||||
|
if (!$data['is_new'])
|
||||||
|
return app('json')->fail('套餐不能加入购物车');
|
||||||
|
|
||||||
|
$cartData = app()->make(StoreDiscountRepository::class)->check($data['discount_id'], $data['data'], $this->request->userInfo());
|
||||||
|
$cart_id = [];
|
||||||
|
if ($cartData){
|
||||||
|
foreach ($cartData as $datum) {
|
||||||
|
$cart = $this->repository->create($datum);
|
||||||
|
$cart_id[] = $cart['cart_id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return app('json')->success(compact('cart_id'));
|
||||||
|
}
|
||||||
|
}
|
@ -209,6 +209,20 @@ Route::group('api/', function () {
|
|||||||
Route::post('/batchCreate', 'StoreCart/batchCreate');
|
Route::post('/batchCreate', 'StoreCart/batchCreate');
|
||||||
})->prefix('api.store.order.');
|
})->prefix('api.store.order.');
|
||||||
|
|
||||||
|
//代购购物车
|
||||||
|
Route::group('user/cartdg', function () {
|
||||||
|
Route::get('/lst', 'StoreCartDg/lst');
|
||||||
|
Route::post('/create', 'StoreCartDg/create');
|
||||||
|
Route::post('/again', 'StoreCartDg/again');
|
||||||
|
Route::post('/change/:id', 'StoreCartDg/change');
|
||||||
|
Route::post('/delete', 'StoreCartDg/batchDelete');
|
||||||
|
Route::get('/count', 'StoreCartDg/cartCount');
|
||||||
|
Route::post('/batchCreate', 'StoreCartDg/batchCreate');
|
||||||
|
Route::post('/edit', 'StoreCartDg/edit');
|
||||||
|
Route::post('/save', 'StoreCartDg/save');
|
||||||
|
Route::post('/get_list', 'StoreCartDg/get_list');
|
||||||
|
})->prefix('api.store.order.');
|
||||||
|
|
||||||
Route::group('store/product', function () {
|
Route::group('store/product', function () {
|
||||||
Route::post('/assist/create/:id', 'StoreProductAssistSet/create');
|
Route::post('/assist/create/:id', 'StoreProductAssistSet/create');
|
||||||
Route::get('/assist/detail/:id', 'StoreProductAssistSet/detail');
|
Route::get('/assist/detail/:id', 'StoreProductAssistSet/detail');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user