setConfig($data, '门店分类设置', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'STORE_CATEGORY' ] ]); } /** * 获取门店分类设置 * @param $site_id * @return array */ public function getCategoryConfig($site_id) { $data = ( new Config() )->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'STORE_CATEGORY' ] ]); if (empty($data[ 'data' ][ 'value' ])) { $data[ 'data' ][ 'value' ] = [ 'status' => 0 ]; } return $data; } /** * 添加门店分类 * * @param array $data */ public function addStoreCategory($data) { $res = model('store_category')->add($data); Cache::tag("store_category")->clear(); return $this->success($res); } /** * 修改门店分类 * * @param array $data * @param array $condition */ public function editStoreCategory($data, $condition) { $check_condition = array_column($condition, 2, 0); $category_id = isset($check_condition[ 'category_id' ]) ? $check_condition[ 'category_id' ] : 0; $site_id = isset($check_condition[ 'site_id' ]) ? $check_condition[ 'site_id' ] : 0; if (empty($category_id)) return $this->error('', 'category_id不能为空'); if (empty($site_id)) return $this->error('', 'site_id不能为空'); $res = model('store_category')->update($data, $condition); if (isset($data[ 'category_name' ]) && !empty($data[ 'category_name' ])) model('store')->update([ 'category_name' => $data[ 'category_name' ] ], [ [ 'category_id', '=', $category_id ], [ 'site_id', '=', $site_id ] ]); Cache::tag("store_category")->clear(); return $this->success($res); } /** * 删除门店分类 * @param array $condition */ public function deleteStoreCategory($condition) { $check_condition = array_column($condition, 2, 0); $category_id = isset($check_condition[ 'category_id' ]) ? array_filter(explode(',', $check_condition[ 'category_id' ])) : []; $site_id = isset($check_condition[ 'site_id' ]) ? $check_condition[ 'site_id' ] : 0; if (empty($category_id)) return $this->error('', 'category_id不能为空'); if (empty($site_id)) return $this->error('', 'site_id不能为空'); $res = model('store_category')->delete($condition); model('store')->update([ 'category_name' => '', 'category_id' => '' ], [ [ 'category_id', 'in', $category_id ], [ 'site_id', '=', $site_id ] ]); Cache::tag("store_category")->clear(); return $this->success($res); } /** * 获取门店分类信息 * * @param array $condition * @param string $field */ public function getStoreCategoryInfo($condition = [], $field = '*') { $data = json_encode([ $condition, $field ]); $cache = Cache::get("store_category_getStoreCategoryInfo_" . $data); if (!empty($cache)) { return $this->success($cache); } $info = model('store_category')->getInfo($condition, $field); Cache::tag("store_category")->set("store_category_getStoreCategoryInfo_" . $data, $info); return $this->success($info); } /** * 获取门店分类列表 * * @param array $condition * @param string $field * @param string $order * @param string $limit */ public function getStoreCategoryList($condition = [], $field = '*', $order = 'sort asc, category_id asc', $limit = null) { $data = json_encode([ $condition, $field, $order, $limit ]); $cache = Cache::get("store_category_getStoreCategoryList_" . $data); if (!empty($cache)) { return $this->success($cache); } $list = model('store_category')->getList($condition, $field, $order, '', '', '', $limit); Cache::tag("store_category")->set("store_category_getStoreCategoryList_" . $data, $list); return $this->success($list); } /** * 获取门店分类分页列表 * * @param array $condition * @param number $page * @param string $page_size * @param string $order * @param string $field */ public function getStoreCategoryPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'category_id desc', $field = '*') { $data = json_encode([ $condition, $field, $order, $page, $page_size ]); $cache = Cache::get("store_category_getStoreCategoryPageList_" . $data); if (!empty($cache)) { return $this->success($cache); } $list = model('store_category')->pageList($condition, $field, $order, $page, $page_size); Cache::tag("store_category")->set("store_category_getStoreCategoryPageList_" . $data, $list); return $this->success($list); } }