merchant_id; $store_id = $this->store_id; $map = [ 'name' => $brand_name, 'state' => 0, 'merchantid' => $merchant_id, ]; if ($brand_id) { $map['id'] = ['neq', $brand_id]; } $repeat = $GoodsBrandModel->getFind($map); if ($repeat) { $this->ajaxReturn(['status' => 0, 'msg' => '已存在相同品牌名!']); } $new_data['name'] = $brand_name; if ($brand_id) { $res = $GoodsBrandModel->updateOrder(['id' => $brand_id], $new_data); $msg = $res ? ['status' => 1, 'msg' => '品牌更新成功!'] : ['status' => 0, 'msg' => '品牌更新失败!']; } else { $new_data['merchantid'] = $merchant_id; $new_data['storeid'] = $store_id; $new_data['addtime'] = time(); $res = $GoodsBrandModel->addOrder($new_data); $msg = $res ? ['status' => 1, 'msg' => '品牌新增成功!', 'data' => ['id' => $res]] : ['status' => 0, 'msg' => '品牌新增失败!']; } $this->ajaxReturn($msg); } /** * 获取品牌库列表 * @param add_time 选填 添加时间 * @param name 选填 品牌名 * @param type 必填 类型 1商户 2门店 * @param page 必填 页码 * @param limit 必填 页长 */ public function getGoodsBrandList() { $GoodsBrandModel = new RetailGoodsBrandModel(); $RetailGoodsModel = new RetailGoodsModel(); $SkuMGoodsViewModel = new SkuMGoodsViewModel(); $add_time = I('post.add_time'); $name = I('post.name'); $type = I('post.type'); $page = I('post.page') ? I('post.page') : 1; $limit = I('post.limit') ? I('post.limit') : 10; $merchant_id = $this->merchant_id; if (!in_array($type, [1, 2])) { $this->ajaxReturn(['status' => 0, 'msg' => '缺少重要参数!']); } $map = [ 'state' => 0, 'merchantid' => $merchant_id, ]; if (trim($name)) { $map['name'] = ['like', '%' . trim($name) . '%']; } if (!empty($add_time)) { $map['addtime'] = ['between', [strtotime($add_time[0]), strtotime($add_time[1])]]; } $field = ['name,addtime,id']; $data = $GoodsBrandModel->getSelect($map, $field, 'addtime desc', "{$page},{$limit}"); foreach ($data as &$val) { $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']); if ($type == 1) { $val['num'] = (string)$SkuMGoodsViewModel->getCount(['goods_brand_id' => $val['id'], 'status' => ['neq', 2]]); } else if ($type == 2) { $val['num'] = (string)$RetailGoodsModel->getCount(['goods_brand_id' => $val['id'], 'status' => ['neq', 2]]); } } $result = [ 'status' => 1, 'msg' => $data ? '数据获取成功' : '暂无数据', 'total' => $GoodsBrandModel->getCount($map), 'data' => $data, ]; $this->ajaxReturn($result); } /** * 品牌库删除 * @param id 必填 品牌id */ public function delGoodsBrand() { $GoodsBrandModel = new RetailGoodsBrandModel(); $RetailGoodsModel = new RetailGoodsModel(); $SkuMGoodsViewModel = new SkuMGoodsViewModel(); $id = I('post.id'); $merchantNum = (string)$SkuMGoodsViewModel->getCount(['goods_brand_id' => $id, 'status' => ['neq', 2]]); $storeNum = (string)$RetailGoodsModel->getCount(['goods_brand_id' => $id, 'status' => ['neq', 2]]); if ($merchantNum > 0 || $storeNum > 0) { $this->ajaxReturn(['status' => 0, 'msg' => '该品牌存在商品使用!']); } $res = $GoodsBrandModel->updateOrder(['id' => $id], ['state' => '1']); if ($res) { $this->ajaxReturn(['status' => 1, 'msg' => '品牌删除成功!']); } else { $this->ajaxReturn(['status' => 0, 'msg' => '品牌删除失败!']); } } /** * 获取品牌库下拉选择 * @param name 选填 品牌名 */ public function getSelectBrand() { $Brand = new Brand(); $this->ajaxReturn($Brand->getSelectBrand([ 'merchant_id' => $this->merchant_id, 'store_id' => $this->store_id, 'name' => I('post.name'), ])); } /** * 商户管理品牌库 */ public function merchant_brand() { $this->display(); } /** * 门店管理品牌库 */ public function store_brand() { $this->display(); } }