166 lines
5.2 KiB
PHP
166 lines
5.2 KiB
PHP
<?php
|
|
|
|
namespace app\controller\api;
|
|
|
|
use app\common\repositories\store\order\StoreCartRepository;
|
|
use app\common\repositories\store\product\ProductRepository;
|
|
use app\common\repositories\store\product\SupplierProductRepository;
|
|
use app\services\supplier\SystemSupplierApplyServices;
|
|
use app\services\supplier\SystemSupplierServices;
|
|
use crmeb\basic\BaseController;
|
|
use think\App;
|
|
use think\exception\ValidateException;
|
|
|
|
class Wine extends BaseController{
|
|
|
|
protected $services;
|
|
|
|
public function __construct(App $app, SystemSupplierServices $services){
|
|
parent::__construct($app);
|
|
$this->services = $services;
|
|
}
|
|
/**
|
|
* Common: 获取全部酒道馆商品
|
|
* Author: wu-hui
|
|
* Time: 2024/03/07 11:40
|
|
* @return mixed
|
|
*/
|
|
public function goodsList(){
|
|
// 参数获取
|
|
$search = $this->request->params(['store_name','lat','lng']);
|
|
[$page, $limit] = $this->getPage();
|
|
$data = app()->make(ProductRepository::class)->getWineList($search, $page, $limit);
|
|
|
|
return app('json')->success($data);
|
|
}
|
|
/**
|
|
* Common: 获取当前商户购物车列表
|
|
* Author: wu-hui
|
|
* Time: 2024/03/01 15:06
|
|
* @return mixed
|
|
*/
|
|
public function cartList(){
|
|
// 参数获取
|
|
$list = (array)app()->make(StoreCartRepository::class)
|
|
->getSearch([
|
|
'is_pay' => 0,
|
|
'is_del' => 0,
|
|
'is_new' => 0,
|
|
'is_fail' => 0,
|
|
'product_type' => 36,
|
|
])
|
|
->field(['cart_id','product_type','product_id','product_attr_unique','cart_num','is_batch','batch_num'])
|
|
->with([
|
|
'productAttr' => function($query){
|
|
$query->field(['product_id','detail','image','price','sku','unique','value_id', 'stock']);
|
|
},
|
|
'product' => function($query){
|
|
$query->field(['product_id','store_name','unit_name','is_batch','batch_num','batch_unit']);
|
|
}
|
|
])
|
|
->select()
|
|
->toArray();
|
|
|
|
return app('json')->success($list);
|
|
}
|
|
/**
|
|
* Common: 获取购物车id列表
|
|
* Author: wu-hui
|
|
* Time: 2024/03/01 15:39
|
|
* @return mixed
|
|
*/
|
|
public function cartIds(){
|
|
// 参数获取
|
|
$ids = (array)app()->make(StoreCartRepository::class)
|
|
->getSearch([
|
|
'is_pay' => 0,
|
|
'is_del' => 0,
|
|
'is_new' => 0,
|
|
'is_fail' => 0,
|
|
'product_type' => 36,
|
|
])->column('cart_id');
|
|
|
|
return app('json')->success($ids);
|
|
}
|
|
/**
|
|
* Common: 商户购物车 - 新增购买商品&修改购买商品数量
|
|
* Author: wu-hui
|
|
* Time: 2024/03/01 14:24
|
|
* @return mixed
|
|
*/
|
|
public function cartAdd(){
|
|
// 参数获取
|
|
$data = $this->request->params([
|
|
'cart_num',
|
|
'product_attr_unique',
|
|
'product_id',
|
|
'is_batch',
|
|
'batch_num',
|
|
]);
|
|
$data['product_type'] = 36;
|
|
$data['source'] = $data['product_type'];
|
|
$data['source_id'] = $data['product_id'];
|
|
// 校验数据
|
|
$result = app()->make(ProductRepository::class)->supplyCartCheck($data, 0, 1);
|
|
// 添加修改
|
|
$cartId = (int)app()->make(StoreCartRepository::class)->getSearch([
|
|
'is_pay' => 0,
|
|
'is_del' => 0,
|
|
'is_new' => 0,
|
|
'is_fail' => 0,
|
|
'product_type' => 36,
|
|
'product_id' => $data['source_id'],
|
|
'product_attr_unique' => $data['product_attr_unique'],
|
|
])->value('cart_id');
|
|
if($cartId > 0){
|
|
// 已经存在 修改数量
|
|
app()->make(StoreCartRepository::class)->update($cartId,[
|
|
'cart_num' => $data['cart_num'],
|
|
'is_batch' => $data['is_batch'],
|
|
'batch_num' => $data['batch_num']
|
|
]);
|
|
}else{
|
|
// 不存在 添加信息
|
|
$data['mer_id'] = $result['product']['mer_id'];
|
|
app()->make(StoreCartRepository::class)->create($data);
|
|
}
|
|
|
|
return app('json')->success();
|
|
}
|
|
/**
|
|
* Common: 商户购物车 - 删除购买商品
|
|
* Author: wu-hui
|
|
* Time: 2024/03/01 14:49
|
|
* @return mixed
|
|
*/
|
|
public function cartDel(){
|
|
// 参数获取
|
|
$data = $this->request->params([
|
|
'product_attr_unique',
|
|
'product_id',
|
|
]);
|
|
$data['product_type'] = 36;
|
|
$data['source'] = $data['product_type'];
|
|
$data['source_id'] = $data['product_id'];
|
|
// 删除操作
|
|
(int)app()->make(StoreCartRepository::class)->getSearch([
|
|
'is_pay' => 0,
|
|
'is_del' => 0,
|
|
'is_new' => 0,
|
|
'is_fail' => 0,
|
|
'product_type' => 36,
|
|
'product_id' => $data['source_id'],
|
|
'product_attr_unique' => $data['product_attr_unique'],
|
|
])->delete();
|
|
|
|
return app('json')->success();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|