更新
This commit is contained in:
parent
83b1f50e6c
commit
139eb47116
@ -18,6 +18,7 @@ use think\App;
|
||||
use crmeb\basic\BaseController;
|
||||
use app\validate\merchant\StoreProductAdminValidate as validate;
|
||||
use app\common\repositories\store\product\ProductRepository as repository;
|
||||
use think\facade\Db;
|
||||
use think\facade\Queue;
|
||||
|
||||
class StoreProduct extends BaseController
|
||||
@ -49,11 +50,11 @@ class StoreProduct extends BaseController
|
||||
public function lst()
|
||||
{
|
||||
[$page, $limit] = $this->getPage();
|
||||
$where = $this->request->params(['cate_id', 'keyword', ['type', 1], 'mer_cate_id', 'pid','store_name','is_trader','us_status','product_id','star','sys_labels','hot_type','svip_price_type']);
|
||||
$mer_id = $this->request->param('mer_id','');
|
||||
$where = $this->request->params(['cate_id', 'keyword', ['type', 1], 'mer_cate_id', 'pid', 'store_name', 'is_trader', 'us_status', 'product_id', 'star', 'sys_labels', 'hot_type', 'svip_price_type']);
|
||||
$mer_id = $this->request->param('mer_id', '');
|
||||
$merId = $mer_id ? $mer_id : null;
|
||||
$where['is_gift_bag'] = 0;
|
||||
$_where = $this->repository->switchType($where['type'], null,0);
|
||||
$_where = $this->repository->switchType($where['type'], null, 0);
|
||||
unset($_where['product_type']);
|
||||
unset($_where['star']);
|
||||
$where = array_merge($where, $_where);
|
||||
@ -68,14 +69,14 @@ class StoreProduct extends BaseController
|
||||
public function bagList()
|
||||
{
|
||||
[$page, $limit] = $this->getPage();
|
||||
$where = $this->request->params(['cate_id','keyword',['type',1],'mer_cate_id' ,'is_trader','us_status']);
|
||||
$where = $this->request->params(['cate_id', 'keyword', ['type', 1], 'mer_cate_id', 'is_trader', 'us_status']);
|
||||
$merId = $this->request->param('mer_id') ? $this->request->param('mer_id') : null;
|
||||
|
||||
$_where = $this->repository->switchType($where['type'], null,10);
|
||||
$where = array_merge($where,$_where);
|
||||
$_where = $this->repository->switchType($where['type'], null, 10);
|
||||
$where = array_merge($where, $_where);
|
||||
$where['order'] = 'rank';
|
||||
unset($where['star']);
|
||||
return app('json')->success($this->repository->getAdminList($merId,$where, $page, $limit));
|
||||
return app('json')->success($this->repository->getAdminList($merId, $where, $page, $limit));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,7 +86,7 @@ class StoreProduct extends BaseController
|
||||
*/
|
||||
public function getStatusFilter()
|
||||
{
|
||||
return app('json')->success($this->repository->getFilter(null,'商品',[0,98]));
|
||||
return app('json')->success($this->repository->getFilter(null, '商品', [0, 98]));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,7 +97,7 @@ class StoreProduct extends BaseController
|
||||
*/
|
||||
public function getBagStatusFilter()
|
||||
{
|
||||
return app('json')->success($this->repository->getFilter(null,'礼包',10));
|
||||
return app('json')->success($this->repository->getFilter(null, '礼包', 10));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,9 +108,9 @@ class StoreProduct extends BaseController
|
||||
*/
|
||||
public function detail($id)
|
||||
{
|
||||
if(!$this->repository->merExists(null,$id))
|
||||
if (!$this->repository->merExists(null, $id))
|
||||
return app('json')->fail('数据不存在');
|
||||
return app('json')->success($this->repository->getAdminOneProduct($id,0));
|
||||
return app('json')->success($this->repository->getAdminOneProduct($id, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -119,10 +120,10 @@ class StoreProduct extends BaseController
|
||||
* @param validate $validate
|
||||
* @return mixed
|
||||
*/
|
||||
public function update($id,validate $validate)
|
||||
public function update($id, validate $validate)
|
||||
{
|
||||
$data = $this->checkParams($validate);
|
||||
$this->repository->adminUpdate($id,$data);
|
||||
$this->repository->adminUpdate($id, $data);
|
||||
return app('json')->success('编辑成功');
|
||||
}
|
||||
|
||||
@ -137,14 +138,14 @@ class StoreProduct extends BaseController
|
||||
{
|
||||
//0:审核中,1:审核通过 -1: 未通过 -2: 下架
|
||||
$id = $this->request->param('id');
|
||||
$data = $this->request->params(['status','refusal']);
|
||||
if (in_array($data['status'],[1,0,-2,-1]))
|
||||
if($data['status'] == -1 && empty($data['refusal']))
|
||||
return app('json')->fail('请填写拒绝理由');
|
||||
if(is_array($id)) {
|
||||
$this->repository->batchSwitchStatus($id,$data);
|
||||
$data = $this->request->params(['status', 'refusal']);
|
||||
if (in_array($data['status'], [1, 0, -2, -1]))
|
||||
if ($data['status'] == -1 && empty($data['refusal']))
|
||||
return app('json')->fail('请填写拒绝理由');
|
||||
if (is_array($id)) {
|
||||
$this->repository->batchSwitchStatus($id, $data);
|
||||
} else {
|
||||
$this->repository->switchStatus($id,$data);
|
||||
$this->repository->switchStatus($id, $data);
|
||||
}
|
||||
return app('json')->success('操作成功');
|
||||
}
|
||||
@ -159,7 +160,7 @@ class StoreProduct extends BaseController
|
||||
*/
|
||||
public function checkParams(validate $validate)
|
||||
{
|
||||
$data = $this->request->params(['is_hot','is_best','is_benefit','is_new','store_name','content','rank','star']);
|
||||
$data = $this->request->params(['is_hot', 'is_best', 'is_benefit', 'is_new', 'store_name', 'content', 'rank', 'star']);
|
||||
$validate->check($data);
|
||||
return $data;
|
||||
}
|
||||
@ -171,14 +172,14 @@ class StoreProduct extends BaseController
|
||||
*/
|
||||
public function checkProduct()
|
||||
{
|
||||
Queue::push(CheckProductExtensionJob::class,[]);
|
||||
Queue::push(CheckProductExtensionJob::class, []);
|
||||
return app('json')->success('后台已开始检测');
|
||||
}
|
||||
|
||||
public function lists()
|
||||
{
|
||||
$make = app()->make(MerchantRepository::class);
|
||||
$data = $make->selectWhere(['is_del' => 0],'mer_id,mer_name');
|
||||
$data = $make->selectWhere(['is_del' => 0], 'mer_id,mer_name');
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
@ -191,7 +192,7 @@ class StoreProduct extends BaseController
|
||||
*/
|
||||
public function addFictiForm($id)
|
||||
{
|
||||
if(!$this->repository->merExists(null,$id))
|
||||
if (!$this->repository->merExists(null, $id))
|
||||
return app('json')->fail('数据不存在');
|
||||
return app('json')->success(formToData($this->repository->fictiForm($id)));
|
||||
}
|
||||
@ -206,18 +207,18 @@ class StoreProduct extends BaseController
|
||||
*/
|
||||
public function addFicti($id)
|
||||
{
|
||||
$data = $this->request->params(['type','ficti']);
|
||||
if(!in_array($data['type'],[1,2])) return app('json')->fail('类型错误');
|
||||
if(!$data['ficti'] || $data['ficti'] < 0) return app('json')->fail('已售数量必须大于0');
|
||||
$res = $this->repository->getWhere(['product_id' => $id],'ficti,sales');
|
||||
if(!$res) return app('json')->fail('数据不存在');
|
||||
if($data['type'] == 2 && $res['ficti'] < $data['ficti']) return app('json')->fail('已售数量不足');
|
||||
$data = $this->request->params(['type', 'ficti']);
|
||||
if (!in_array($data['type'], [1, 2])) return app('json')->fail('类型错误');
|
||||
if (!$data['ficti'] || $data['ficti'] < 0) return app('json')->fail('已售数量必须大于0');
|
||||
$res = $this->repository->getWhere(['product_id' => $id], 'ficti,sales');
|
||||
if (!$res) return app('json')->fail('数据不存在');
|
||||
if ($data['type'] == 2 && $res['ficti'] < $data['ficti']) return app('json')->fail('已售数量不足');
|
||||
$ficti = ($data['type'] == 1) ? $data['ficti'] : '-' . $data['ficti'];
|
||||
$data = [
|
||||
'ficti' => $res['ficti'] + $ficti,
|
||||
'sales' => $res['sales'] + $ficti
|
||||
];
|
||||
$this->repository->update($id,$data);
|
||||
$this->repository->update($id, $data);
|
||||
return app('json')->success('修改成功');
|
||||
}
|
||||
|
||||
@ -231,14 +232,14 @@ class StoreProduct extends BaseController
|
||||
public function updateSort($id)
|
||||
{
|
||||
$sort = $this->request->param('sort');
|
||||
$this->repository->updateSort($id,null,['rank' => $sort]);
|
||||
$this->repository->updateSort($id, null, ['rank' => $sort]);
|
||||
return app('json')->success('修改成功');
|
||||
}
|
||||
|
||||
public function setLabels($id)
|
||||
{
|
||||
$data = $this->request->params(['sys_labels']);
|
||||
app()->make(SpuRepository::class)->setLabels($id,0,$data,0);
|
||||
app()->make(SpuRepository::class)->setLabels($id, 0, $data, 0);
|
||||
return app('json')->success('修改成功');
|
||||
}
|
||||
|
||||
@ -251,10 +252,10 @@ class StoreProduct extends BaseController
|
||||
*/
|
||||
public function changeUsed($id)
|
||||
{
|
||||
if(!$this->repository->merExists(null,$id))
|
||||
if (!$this->repository->merExists(null, $id))
|
||||
return app('json')->fail('数据不存在');
|
||||
$status = $this->request->param('status',0) == 1 ? 1 : 0;
|
||||
$this->repository->switchShow($id,$status,'is_used',0);
|
||||
$status = $this->request->param('status', 0) == 1 ? 1 : 0;
|
||||
$this->repository->switchShow($id, $status, 'is_used', 0);
|
||||
return app('json')->success('修改成功');
|
||||
}
|
||||
|
||||
@ -268,7 +269,7 @@ class StoreProduct extends BaseController
|
||||
{
|
||||
$ids = $this->request->param('ids');
|
||||
$status = $this->request->param('status') == 1 ? 1 : 0;
|
||||
$this->repository->batchSwitchShow($ids,$status,'is_used',0);
|
||||
$this->repository->batchSwitchShow($ids, $status, 'is_used', 0);
|
||||
return app('json')->success('修改成功');
|
||||
}
|
||||
|
||||
@ -283,7 +284,7 @@ class StoreProduct extends BaseController
|
||||
$ids = $this->request->param('ids');
|
||||
$data = $this->request->params(['sys_labels']);
|
||||
if (empty($ids)) return app('json')->fail('请选择商品');
|
||||
app()->make(SpuRepository::class)->batchLabels($ids, $data,0);
|
||||
app()->make(SpuRepository::class)->batchLabels($ids, $data, 0);
|
||||
return app('json')->success('修改成功');
|
||||
}
|
||||
|
||||
@ -296,19 +297,33 @@ class StoreProduct extends BaseController
|
||||
public function batchHot()
|
||||
{
|
||||
$ids = $this->request->param('ids');
|
||||
$data = $this->request->params([['is_hot',0],['is_benefit',0],['is_best',0],['is_new',0]]);
|
||||
$data = $this->request->params([['is_hot', 0], ['is_benefit', 0], ['is_best', 0], ['is_new', 0]]);
|
||||
if (empty($ids)) return app('json')->fail('请选择商品');
|
||||
$this->repository->updates($ids,$data);
|
||||
$this->repository->updates($ids, $data);
|
||||
return app('json')->success('修改成功');
|
||||
}
|
||||
//**复制商品 */
|
||||
public function copy($product_id=0,$mer_id=0){
|
||||
if($product_id==0) return app('json')->fail('参数错误');
|
||||
$product=$this->repository->getAdminOneProduct($product_id,0);
|
||||
public function copy($product_id = 0, $mer_id = 0, $street_code = 0, $type_id = 0, $category_id = 0)
|
||||
{
|
||||
if ($product_id == 0) return app('json')->fail('参数错误');
|
||||
$product = $this->repository->getAdminOneProduct($product_id, 0);
|
||||
$product = $product->toArray();
|
||||
$product['mer_id']=$mer_id;
|
||||
$product['old_product_id']=$product['product_id'];
|
||||
return $this->repository->create($product, 0,1);
|
||||
|
||||
$product['mer_id'] = $mer_id;
|
||||
$product['old_product_id'] = $product['product_id'];
|
||||
$productId = $this->repository->create($product, 0, 1);
|
||||
$data = [
|
||||
'product_id' => $productId,
|
||||
'mer_id' => $mer_id,
|
||||
'source_mer_id' => $product['mer_id'],
|
||||
'street_code' => $street_code,
|
||||
'weight' => 1,
|
||||
'status' => 1,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'type_id' => $type_id,
|
||||
'category_id' => $category_id,
|
||||
'cate_id' => $product['type']
|
||||
];
|
||||
Db::name('cloud_product')->insert($data);
|
||||
return $productId;
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class Demo extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
// Queue::push(ProductCopyJob::class, ['product_id' => 0, 'mer_id' =>0]);//短信通知
|
||||
Queue::push(ProductCopyJob::class, ['product_id' => 0, 'mer_id' =>0]);//短信通知
|
||||
|
||||
halt(1);
|
||||
$mer_id = 104;
|
||||
|
@ -24,7 +24,7 @@ class ProductCopyJob implements JobInterface
|
||||
public function fire($job, $data)
|
||||
{
|
||||
$make = app()->make(StoreProduct::class);
|
||||
$make->copyProduct($data['id'],$data['copy_id']);
|
||||
$make->copy($data['id'],$data['copy_id']);
|
||||
$job->delete();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user