192 lines
6.2 KiB
PHP
192 lines
6.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\common\repositories\system\merchant\MerchantRepository;
|
||
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/08 15:25
|
||
* @return mixed
|
||
*/
|
||
public function merList(){
|
||
// 商户类别:0=普通商户,1=酒道馆,2=供应商
|
||
$where['merchant_type'] = 1;
|
||
$where['mer_state'] = 1;
|
||
$where['status'] = 1;
|
||
|
||
$list = app()->make(MerchantRepository::class)
|
||
->search($where)
|
||
->field(['mer_id','mer_name','merchant_type'])
|
||
->select()
|
||
->toArray();
|
||
|
||
return app('json')->success($list);
|
||
}
|
||
/**
|
||
* Common: 获取全部酒道馆商品
|
||
* Author: wu-hui
|
||
* Time: 2024/03/07 11:40
|
||
* @return mixed
|
||
*/
|
||
public function goodsList(){
|
||
// 参数获取
|
||
$search = $this->request->params(['store_name','lat','lng','brand_id','store_category_id','mer_id']);
|
||
[$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/08 15:39
|
||
* @return mixed
|
||
*/
|
||
public function cartList(){
|
||
// 参数获取
|
||
$uid = $this->request->uid();
|
||
$list = (array)app()->make(StoreCartRepository::class)
|
||
->getSearch([
|
||
'is_pay' => 0,
|
||
'is_del' => 0,
|
||
'is_new' => 0,
|
||
'is_fail' => 0,
|
||
'product_type' => 36,
|
||
'uid' => $uid,
|
||
])
|
||
->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', 'wine_type']);
|
||
}
|
||
])
|
||
->select()
|
||
->toArray();
|
||
|
||
return app('json')->success($list);
|
||
}
|
||
/**
|
||
* Common: 获取当前用户酒道馆购物车id列表
|
||
* Author: wu-hui
|
||
* Time: 2024/03/08 15:40
|
||
* @return mixed
|
||
*/
|
||
public function cartIds(){
|
||
// 参数获取
|
||
$uid = $this->request->uid();
|
||
$ids = (array)app()->make(StoreCartRepository::class)
|
||
->getSearch([
|
||
'is_pay' => 0,
|
||
'is_del' => 0,
|
||
'is_new' => 0,
|
||
'is_fail' => 0,
|
||
'product_type' => 36,
|
||
'uid' => $uid,
|
||
])->column('cart_id');
|
||
|
||
return app('json')->success($ids);
|
||
}
|
||
/**
|
||
* Common: 新增购买商品&修改购买商品数量
|
||
* Author: wu-hui
|
||
* Time: 2024/03/08 15:41
|
||
* @return mixed
|
||
*/
|
||
public function cartAdd(){
|
||
// 参数获取
|
||
$uid = $this->request->uid();
|
||
$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'],
|
||
'uid' => $uid,
|
||
])->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'];
|
||
$data['uid'] = $uid;
|
||
app()->make(StoreCartRepository::class)->create($data);
|
||
}
|
||
|
||
return app('json')->success();
|
||
}
|
||
/**
|
||
* Common: 删除购买商品
|
||
* Author: wu-hui
|
||
* Time: 2024/03/08 15:42
|
||
* @return mixed
|
||
*/
|
||
public function cartDel(){
|
||
// 参数获取
|
||
$uid = $this->request->uid();
|
||
$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'],
|
||
'uid' => $uid,
|
||
])->delete();
|
||
|
||
return app('json')->success();
|
||
}
|
||
|
||
|
||
|
||
}
|