'/index.php/Retail/Attributes/newSaveAttr', 'newDelSku' => '/index.php/Retail/Attributes/newDelSku', ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $this->display(); } /** * 门店-规格展示页面 */ public function mIndex() { $arr = array( 'newMerSaveAttr' => '/index.php/Retail/Attributes/newMerSaveAttr', 'newMerDelSku' => '/index.php/Retail/Attributes/newMerDelSku', ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $this->display(); } /** * 展示页获取规格列表 */ public function newGetAttr_v1() { $sku_attr = M('retail_sku_attr')->where(array('merchantid' => $this->merchant_id, 'state' => 0))->field('id,name')->select(); foreach ($sku_attr as &$val) { $val['old_name'] = $val['name']; $val['list'] = M('retail_sku_list')->where(array('attr_id' => $val['id'], 'state' => 0))->field('id,name,name as old_name,attr_id')->select(); $val['isShow'] = true; $val['list'] = $val['list'] ? $val['list'] : array(); array_unshift($val['list'], array('id' => 0, 'name' => '', 'old_name' => '', 'attr_id' => $val['id'])); } array_unshift($sku_attr, array('id' => 0, 'name' => '', 'old_name' => '', 'list' => array(), 'isShow' => false)); $res['data'] = $sku_attr; $this->ajaxReturn($res); } /** * 门店-删除规格属性 */ public function newDelSku() { $this->delSku(); } /** * 商户-删除规格属性 */ public function newMerDelSku() { $this->delSku(); } /** * 删除规格属性 */ private function delSku() { $id = I('post.id'); if (empty($id) || !is_numeric($id) || $id != intval($id)) { $res['status'] = 0; $res['msg'] = '缺少参数'; $this->ajaxReturn($res); } $map1['state'] = 0; $map1['merchant_id'] = $this->merchant_id; $map1['attr_id'] = $id; $list = M('retail_sku_list')->where($map1)->getField('id', true); foreach ($list as $value) { $map['s.state'] = 0; $map['g.status'] = array('in', '0,1'); $map['_string'] = 's.sku_id_list like "%,' . $value . ',%" OR s.sku_id_list like "%,' . $value . '" OR s.sku_id_list like "' . $value . ',%" OR s.sku_id_list=' . $value; $data = M('retail_sku_mgoods as s') ->join('ls_retail_mgoods as g on s.mgoods_id=g.id') ->where($map)->find(); $data1 = M('retail_sku_goods as s') ->join('ls_retail_goods as g on s.goods_id=g.id') ->where($map)->find(); if (!empty($data) || !empty($data1)) { $res['status'] = 0; $res['msg'] = '该属性的规格有商品在使用,无法删除'; $this->ajaxReturn($res); } } $del = M('retail_sku_attr')->where(array('merchantid' => $this->merchant_id, 'id' => $id))->save(array('state' => 1)); if (!empty($list)) { $del1 = M('retail_sku_list')->where(array('merchant_id' => $this->merchant_id, 'id' => array('in', $list)))->save(array('state' => 1)); } else { $del1 = true; } if ($del && $del1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 if (session('merchant_userinfo') != null) { $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 } elseif (session('store_userinfo') != null) { $type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端 } $request_data = json_encode($_POST);//请求参数 json数据 $desc = '商品规格-删除规格';//操作行为描述 action_log($source, $type, $request_data, $desc); $res['status'] = 1; $res['msg'] = '删除成功'; } else { $res['status'] = 0; $res['msg'] = '删除失败'; } $this->ajaxReturn($res); } /** * 门店-新增、保存规格属性 */ public function newSaveAttr() { $this->saveAttr(); } /** * 商户-新增、保存规格属性 */ public function newMerSaveAttr() { $this->saveAttr(); } /** * 新增、保存规格属性 */ private function saveAttr() { $id = I('post.id'); $name = I('post.name'); $name = trim($name, ' '); if (empty($name) || !isset($id) || !is_numeric($id)) { $res['status'] = 0; $res['msg'] = '参数有误'; $this->ajaxReturn($res); } else { $map['id'] = array('neq', $id); $map['merchantid'] = $this->merchant_id; $map['state'] = 0; $map['name'] = $name; $old = M('retail_sku_attr')->where($map)->find(); if (!empty($old)) { $res['status'] = 0; $res['msg'] = '已存在该名称的属性'; $this->ajaxReturn($res); } if ($id == 0) { //新建 $add['name'] = $name; $add['merchantid'] = $this->merchant_id; $add['state'] = 0; $add['storeid'] = 0; $add['addtime'] = time(); $state = M('retail_sku_attr')->add($add); if ($state) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 if (session('merchant_userinfo') != null) { $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 } elseif (session('store_userinfo') != null) { $type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端 } $request_data = json_encode($_POST);//请求参数 json数据 $desc = '商品规格-添加规格';//操作行为描述 action_log($source, $type, $request_data, $desc); } } else { $state = M('retail_sku_attr')->where(array('id' => $id, 'merchantid' => $this->merchant_id))->save(array('name' => $name)); $state = $id; if ($state) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 if (session('merchant_userinfo') != null) { $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 } elseif (session('store_userinfo') != null) { $type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端 } $request_data = json_encode($_POST);//请求参数 json数据 $desc = '商品规格编辑规格';//操作行为描述 action_log($source, $type, $request_data, $desc); } } if ($state) { $res['data'] = array( 'id' => $state, 'name' => $name, 'old_name' => $name, 'list' => array(0 => array('id' => 0, 'name' => '', 'old_name' => '', 'attr_id' => $state)), 'isShow' => true ); $res['id'] = $state; $res['status'] = 1; $res['msg'] = '保存成功'; } else { $res['status'] = 0; $res['msg'] = '保存失败'; } } $this->ajaxReturn($res); } /** * 门店-新增、保存规格值 */ public function newSaveAttrList() { $this->saveAttrList(); } /** * 商户-新增、保存规格值 */ public function newMerSaveAttrList() { $this->saveAttrList(); } /** * 新增、保存规格值 */ private function saveAttrList(){ $id = I('post.id'); $attr_id = I('post.attr_id'); $name = I('post.name'); $name = trim($name, ' '); if (empty($name) || !isset($id) || empty($attr_id)) { $res['status'] = 0; $res['msg'] = '参数有误'; $this->ajaxReturn($res); } else { $map['id'] = array('neq', $id); $map['attr_id'] = $attr_id; $map['merchant_id'] = $this->merchant_id; $map['state'] = 0; $map['name'] = $name; $old = M('retail_sku_list')->where($map)->find(); if (!empty($old)) { $res['status'] = 0; $res['msg'] = '已存在该名称的属性'; $this->ajaxReturn($res); } if ($id == 0) { //新建 $add['name'] = $name; $add['merchant_id'] = $this->merchant_id; $add['attr_id'] = $attr_id; $add['state'] = 0; $add['store_id'] = 0; $add['add_time'] = time(); $state = M('retail_sku_list')->add($add); if ($state) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 if (session('merchant_userinfo') != null) { $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 } elseif (session('store_userinfo') != null) { $type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端 } $request_data = json_encode($_POST);//请求参数 json数据 $desc = '商品规格-添加规格下属性';//操作行为描述 action_log($source, $type, $request_data, $desc); } } else { $state = M('retail_sku_list')->where(array('id' => $id, 'merchant_id' => $this->merchant_id))->save(array('name' => $name)); if ($state) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 if (session('merchant_userinfo') != null) { $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 } elseif (session('store_userinfo') != null) { $type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端 } $request_data = json_encode($_POST);//请求参数 json数据 $desc = '商品规格-编辑规格下属性';//操作行为描述 action_log($source, $type, $request_data, $desc); } } if ($state) { $res['data'] = array( 'id' => $id == 0 ? $state : $id, 'name' => $name, 'old_name' => $name, 'attr_id' => $attr_id ); $res['status'] = 1; $res['msg'] = '保存成功'; } else { $res['status'] = 0; $res['msg'] = '保存失败'; } } $this->ajaxReturn($res); } /** * 门店-删除规格值 */ public function newDelSkuList() { $this->delSkuList(); } /** * 商户-删除规格值 */ public function newMerDelSkuList() { $this->delSkuList(); } /** * 删除规格值 */ private function delSkuList(){ $id = I('post.id'); if (empty($id) || !is_numeric($id) || $id != intval($id)) { $res['status'] = 0; $res['msg'] = '缺少参数'; $this->ajaxReturn($res); } $map['s.state'] = 0; $map['g.status'] = array('in', '0,1'); $map['_string'] = 's.sku_id_list like "%,' . $id . ',%" OR s.sku_id_list like "%,' . $id . '" OR s.sku_id_list like "' . $id . ',%" OR s.sku_id_list=' . $id; $data = M('retail_sku_mgoods as s') ->join('ls_retail_mgoods as g on s.mgoods_id=g.id') ->where($map)->find(); $data1 = M('retail_sku_goods as s') ->join('ls_retail_goods as g on s.goods_id=g.id') ->where($map)->find(); if (!empty($data) || !empty($data1)) { $res['status'] = 0; $res['msg'] = '该规格正在被商品使用,无法删除'; } else { $del = M('retail_sku_list')->where(array('merchant_id' => $this->merchant_id, 'id' => $id))->save(array('state' => 1)); if ($del) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 if (session('merchant_userinfo') != null) { $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 } elseif (session('store_userinfo') != null) { $type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端 } $request_data = json_encode($_POST);//请求参数 json数据 $desc = '商品规格-删除规格下属性';//操作行为描述 action_log($source, $type, $request_data, $desc); $res['status'] = 1; $res['msg'] = '删除成功'; } else { $res['status'] = 0; $res['msg'] = '删除失败'; } } $this->ajaxReturn($res); } /** * 新增、编辑商品处新增规格属性 */ public function addSkuAttr_forAddMGoods() { $user = session('jurisdiction_user'); $name = I('post.name'); if (!empty($name)) { $map['merchantid'] = $this->merchant_id; $map['state'] = 0; $map['name'] = $name; $old = M('retail_sku_attr')->where($map)->find(); if (!empty($old)) { if ($old['status'] == 1) { $res['status'] = 0; $res['msg'] = '已存在同名规格'; } else { $res['status'] = 0; $res['msg'] = '该规格已被您禁用'; } } else { if ($user['login_type'] == 3) { //商户 $add['storeid'] = 0; } else { $add['storeid'] = $this->store_id; } $add = $map; $add['addtime'] = time(); $add['status'] = 1; $id = M('retail_sku_attr')->add($add); if ($id) { $res['status'] = 1; $res['msg'] = '添加成功'; $res['id'] = $id; } else { $res['status'] = 0; $res['msg'] = '服务器出差了'; } } } else { $res['status'] = 0; $res['msg'] = '请输入规格名称'; } $this->ajaxReturn($res); } /** * 新增、编辑商品处新增规格值 */ public function addSkuList_forAddMGoods() { $user = session('jurisdiction_user'); $name = I('post.name'); $id = I('post.id'); if (!empty($name) || !empty($id)) { $map['merchant_id'] = $this->merchant_id; $map['state'] = 0; $map['name'] = $name; $map['attr_id'] = $id; $old = M('retail_sku_list')->where($map)->find(); if (!empty($old)) { if ($old['status'] == 1) { $res['status'] = 0; $res['msg'] = '已存在同名规格'; } else { $res['status'] = 0; $res['msg'] = '该规格已被您禁用'; } } else { $add = $map; $add['add_time'] = time(); if ($user['login_type'] == 1) { //商户 $add['store_id'] = 0; } else { $add['store_id'] = $user['id']; } $add['status'] = 1; $id = M('retail_sku_list')->add($add); if ($id) { $res['status'] = 1; $res['msg'] = '添加成功'; $res['id'] = $id; } else { $res['status'] = 0; $res['msg'] = '服务器出差了'; } } } else { $res['status'] = 0; $res['msg'] = '缺少规格名称'; } $this->ajaxReturn($res); } /** * 新增、编辑商品处获取规格供选择 */ public function getSkuAttr() { $skuList = M('retail_sku_attr') ->where(array('merchantid' => $this->merchant_id, 'status' => 1, 'state' => 0)) ->field('id,name') ->select(); foreach ($skuList as &$val) { $list = M('retail_sku_list') ->where(array('attr_id' => $val['id'], 'status' => 1, 'state' => 0)) ->field('id,name') ->select(); foreach ($list as &$v) { $v['checked'] = false; } $val['list'] = $list; } $this->ajaxReturn(array('data' => $skuList)); } }