diff --git a/app/admin/common.php b/app/admin/common.php index fd2aa8a..fae15ee 100644 --- a/app/admin/common.php +++ b/app/admin/common.php @@ -9,6 +9,8 @@ use think\facade\Config; use think\facade\Request; use think\facade\Cache; use think\facade\Db; +use app\admin\model\StoreCategory; // 商品分类模型 + //获取后台模块当前登录用户的信息 function get_login_admin($key = "") { @@ -93,6 +95,7 @@ function set_recursion($result, $pid = 0, $level=-1) static $list = array(); static $space = ['','├─','§§├─','§§§§├─','§§§§§§├─']; $level++; + foreach ($result as $k => $v) { if ($v['pid'] == $pid) { if ($pid != 0) { @@ -103,9 +106,40 @@ function set_recursion($result, $pid = 0, $level=-1) set_recursion($result, $v['id'],$level); } } + return $list; } +//读取商品分类节点列表 +function get_product_calss() +{ + $result = StoreCategory::select()->toArray(); + return $result; +} + +//递归排序,用于分类选择 +function set_product_recursion($result, $pid = 0, $level=-1) +{ + /*记录排序后的类别数组*/ + static $list = array(); + static $space = ['','├─','§§├─','§§§§├─','§§§§§§├─']; + $level++; + + foreach ($result as $k => $v) { + if ($v['pid'] == $pid) { + if ($pid != 0) { + $v['cate_name'] = $space[$level] . $v['cate_name']; + } + /*将该类别的数据放入list中*/ + $list[] = $v; + set_product_recursion($result, $v['store_category_id'],$level); + } + } + + return $list; +} + + /** * 根据id递归返回子数据 * @param $data 数据 diff --git a/app/admin/controller/product/Classify.php b/app/admin/controller/product/Classify.php new file mode 100644 index 0000000..cd8cf4c --- /dev/null +++ b/app/admin/controller/product/Classify.php @@ -0,0 +1,262 @@ +adminInfo = get_login_admin(); + $this->category_id=354; + $this->url=[ + '/admin/product.classify/index?category_id='.$this->category_id, + '/admin/product.classify/add', + '/admin/product.classify/edit', + '/admin/product.classify/delete' + ]; + } + + /** + * + * 商城分类列表 + * + */ + public function index() + { + if (request()->isAjax()) { + + $params= get_params(); + + $where = []; + + if (isset($params['keywords']) && !empty($params['keywords'])){ + $where[]= ['name','like','%'.$params['keywords'].'%']; + } + if($this->adminInfo['position_id'] != 1){ //不是超级管理员 + $www['admin_id'] = $this->adminInfo['id']; + $user_address = Db::table('fa_szxc_information_useraddress')->where($www)->find(); + if ($user_address){ + if($user_address['auth_range'] == 1){ + $where[] = ['village_id','=',$user_address['village_id']]; + }elseif ($user_address['auth_range'] == 2){ + $where[] = ['street_id','=',$user_address['street_id']]; + }elseif ($user_address['auth_range'] == 3){ + $where[] = ['area_id','=',$user_address['area_id']]; + }else{ + $where[] = ['village_id','=',$user_address['village_id']]; + } + }else{ + $where[] = ['village_id','=','']; + } + } + + $total = StoreCategory::where('mer_id', 0)->where($where)->count(); + + // $list = StoreCategory::with(['merchant', 'street', 'area'])->order('id desc')->select(); + $list = StoreCategory::where('mer_id', 0)->order('store_category_id desc')->select(); + + View::assign('url', $this->url); + View::assign('list', $list); + + $result = ['total' => $total, 'data' => $list]; + + return table_assign(0, '', $result); + + }else{ + + $list = StoreCategory::where('mer_id', 0)->select(); + + View::assign('url', $this->url); + View::assign('list', $list); + return view(); + } + } + + /** + * + * 新增 + * + */ + public function add() + { + $param = get_params(); + + if (request()->isAjax()) { + $param['src'] = preg_replace('# #','',$param['src']); + if ($param['id'] > 0) { + try { + validate(RuleCheck::class)->scene('edit')->check($param); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); + } + Db::name('AdminRule')->strict(false)->field(true)->update($param); + add_log('edit', $param['id'], $param); + } else { + try { + validate(RuleCheck::class)->scene('add')->check($param); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); + } + $param['create_time'] = time(); + $rid = Db::name('AdminRule')->strict(false)->field(true)->insertGetId($param); + //自动为系统所有者管理组分配新增的节点 + $group = Db::name('AdminGroup')->find(1); + if (!empty($group)) { + $newGroup['id'] = 1; + $newGroup['rules'] = $group['rules'] . ',' . $rid; + Db::name('AdminGroup')->strict(false)->field(true)->update($newGroup); + add_log('add', $rid, $param); + } + } + // 删除后台节点缓存 + clear_cache('adminRules'); + return to_assign(); + } else { + + $id = isset($param['id']) ? $param['id'] : 0; + $pid = isset($param['pid']) ? $param['pid'] : 0; + + if($id > 0){ + $detail = StoreCategory::find($id); // 分类模型 + View::assign('detail', $detail); + } + + $storeCategoryList = StoreCategory::select(); + + View::assign('storeCategoryList', $storeCategoryList); + View::assign('url', $this->url); + + View::assign('id', $id); + View::assign('pid', $pid); + return view(); + + } + } + + /** + * + * 编辑 + * + */ + public function edit() + { + $id = get_params("id"); + if(!$id) return to_assign(1, '非法操作!'); + + if (request()->isAjax()) { + + $params = get_params(); + + $data['id'] = $params['id']; // 当前ID + $data['user_id'] = $this->adminInfo['id']; // 操作用户ID + $data['name'] = $params['title']; // 团队名称 + $data['tel'] = $params['phone']; // 联系电话 + $data['mer_id_list'] = isset($params['mer_id']) ? json_encode($params['mer_id']) : null; // 已选商户 + $data['street_id'] = $params['street_id']; // 街道ID + $street = GeoStreet::where('street_id', $data['street_id'])->find(); // 街道数据 + $data['lng'] = $street['lng']; // 经度 + $data['lat'] = $street['lat']; // 纬度 + $area = $street->area; // 区数据 + $data['area_id'] = $area['area_id']; // 区县id + $city = $area->city; // 获取市级 + $data['address'] = $city['city_name'] . $area['area_name'] . $street['street_name']; // 实际地址 + $data['create_time'] = date('Y-m-d H:i:s'); + + // 数据更新 + $supplyChain = SupplyChain::with(['linkMerchant'])->find($data['id']); + $res = $supplyChain->update($data); + + // 获取关联数据一对一---曲线救国 + $linkMerchant = $supplyChain['linkMerchant']; + // $linkMerchantArr = $linkMerchant->column('id'); + + // 先删除关联数据-- 曲线救国 + $linkMerchant->delete(); + + // 关联商户状态 + if($data['mer_id_list']) + { + // 再重新将关联数据入库 + foreach ($params['mer_id'] as $v) { + + $dataLink = [ + 'eb_merchant_id' => $v, // 商户ID + 'user_id' => $data['user_id'], + 'create_time' => $data['create_time'], + ]; + + $supplyChain->linkMerchant()->save($dataLink); + } + } + + if ($res){ + return to_assign(0,'操作成功',['aid'=>$res]); + } + + return to_assign(1, '操作失败,原因:'.$res); + + }else{ + + $category = StoreCategory::find($id); // 取出当前供应链数据 + + View::assign('detail', $category); + + // 取出正常的商家 + $merchant = Merchant::where('status', 1)->column('mer_id, real_name'); + // 区域模型 + $arealist = GeoArea::where('city_code', '510500')->select(); + + View::assign('arealist', $arealist); + View::assign('merchant', $merchant); + View::assign('url', $this->url); + return view(); + } + + } + + /** + * + * 删除 + * + */ + public function delete() + { + $id = get_params("id"); + if(!$id) return to_assign(1, '非法操作!'); + + $supplyChain = SupplyChain::with(['linkMerchant'])->find($id); + // 删除关联模型 + $res = $supplyChain->together(['linkMerchant'])->delete(); + + if ($res){ + return to_assign(0,'操作成功',['aid'=>$res]); + } + + return to_assign(1, '操作失败,原因:'.$res); + + } + +} \ No newline at end of file diff --git a/app/admin/controller/product/Comment.php b/app/admin/controller/product/Comment.php new file mode 100644 index 0000000..a4183ba --- /dev/null +++ b/app/admin/controller/product/Comment.php @@ -0,0 +1,263 @@ +adminInfo = get_login_admin(); + $this->category_id=354; + $this->url=[ + '/admin/product.comment/index?category_id='.$this->category_id, + '/admin/product.comment/add', + '/admin/product.comment/edit', + '/admin/product.comment/del', + '/admin/product.comment/index', + ]; + } + + /** + * + * 商品评论列表 + * + */ + public function index() + { + if (request()->isAjax()) { + + $params= get_params(); + + $where = []; + + if (isset($params['keywords']) && !empty($params['keywords'])){ + $where[]= ['name','like','%'.$params['keywords'].'%']; + } + if($this->adminInfo['position_id'] != 1){ //不是超级管理员 + $www['admin_id'] = $this->adminInfo['id']; + $user_address = Db::table('fa_szxc_information_useraddress')->where($www)->find(); + if ($user_address){ + if($user_address['auth_range'] == 1){ + $where[] = ['village_id','=',$user_address['village_id']]; + }elseif ($user_address['auth_range'] == 2){ + $where[] = ['street_id','=',$user_address['street_id']]; + }elseif ($user_address['auth_range'] == 3){ + $where[] = ['area_id','=',$user_address['area_id']]; + }else{ + $where[] = ['village_id','=',$user_address['village_id']]; + } + }else{ + $where[] = ['village_id','=','']; + } + } + + $total = StoreProductReply::where($where)->count(); + + $list = StoreProductReply::with(['product'])->order('reply_id desc')->select(); + + View::assign('url', $this->url); + View::assign('list', $list); + + $result = ['total' => $total, 'data' => $list]; + + return table_assign(0, '', $result); + + }else{ + + $list = StoreProductReply::select(); + + View::assign('url', $this->url); + View::assign('list', $list); + return view(); + } + } + + /** + * + * 新增 + * + */ + public function add() + { + if (request()->isAjax()) { + + $params = get_params(); + + $data['user_id'] = $this->adminInfo['id']; // 操作用户ID + $data['name'] = $params['title']; // 团队名称 + $data['tel'] = $params['phone']; // 联系电话 + $data['mer_id_list'] = json_encode($params['mer_id']); // 已选商户 + + $data['street_id'] = $params['street_id']; // 街道ID + $street = GeoStreet::where('street_id', $data['street_id'])->find(); // 街道数据 + $data['lng'] = $street['lng']; // 经度 + $data['lat'] = $street['lat']; // 纬度 + $area = $street->area; // 区数据 + $data['area_id'] = $area['area_id']; // 区县id + $city = $area->city; // 获取市级 + $data['address'] = $city['city_name'] . $area['area_name'] . $street['street_name']; // 实际地址 + $data['create_time'] = date('Y-m-d H:i:s'); + + // 数据入库 + $res = SupplyChain::create($data); + + // 关联数据入库 + foreach ($params['mer_id'] as $v) { + + $dataLink = [ + 'eb_merchant_id' => $v, // 商户ID + 'user_id' => $data['user_id'], + 'create_time' => $data['create_time'], + ]; + + $res->linkMerchant()->save($dataLink); // 插入关联数据 + } + + if ($res){ + return to_assign(0,'操作成功',['aid'=>$res]); + } + + return to_assign(1, '操作失败,原因:'.$res); + + }else{ + + // 取出正常的商家 + $merchant = Merchant::where('status', 1)->column('mer_id, real_name'); + + // 区域模型 + $arealist = GeoArea::where('city_code', '510500')->select(); + + View::assign('editor', get_system_config('other','editor')); + View::assign('arealist', $arealist); + View::assign('merchant', $merchant); + View::assign('url', $this->url); + return view(); + } + } + + /** + * + * 编辑 + * + */ + public function edit() + { + $id = get_params("id"); + if(!$id) return to_assign(1, '非法操作!'); + + if (request()->isAjax()) { + + $params = get_params(); + + $data['id'] = $params['id']; // 当前ID + $data['user_id'] = $this->adminInfo['id']; // 操作用户ID + $data['name'] = $params['title']; // 团队名称 + $data['tel'] = $params['phone']; // 联系电话 + $data['mer_id_list'] = isset($params['mer_id']) ? json_encode($params['mer_id']) : null; // 已选商户 + $data['street_id'] = $params['street_id']; // 街道ID + $street = GeoStreet::where('street_id', $data['street_id'])->find(); // 街道数据 + $data['lng'] = $street['lng']; // 经度 + $data['lat'] = $street['lat']; // 纬度 + $area = $street->area; // 区数据 + $data['area_id'] = $area['area_id']; // 区县id + $city = $area->city; // 获取市级 + $data['address'] = $city['city_name'] . $area['area_name'] . $street['street_name']; // 实际地址 + $data['create_time'] = date('Y-m-d H:i:s'); + + // 数据更新 + $supplyChain = SupplyChain::with(['linkMerchant'])->find($data['id']); + $res = $supplyChain->update($data); + + // 获取关联数据一对一---曲线救国 + $linkMerchant = $supplyChain['linkMerchant']; + // $linkMerchantArr = $linkMerchant->column('id'); + + // 先删除关联数据-- 曲线救国 + $linkMerchant->delete(); + + // 关联商户状态 + if($data['mer_id_list']) + { + // 再重新将关联数据入库 + foreach ($params['mer_id'] as $v) { + + $dataLink = [ + 'eb_merchant_id' => $v, // 商户ID + 'user_id' => $data['user_id'], + 'create_time' => $data['create_time'], + ]; + + $supplyChain->linkMerchant()->save($dataLink); + } + } + + if ($res){ + return to_assign(0,'操作成功',['aid'=>$res]); + } + + return to_assign(1, '操作失败,原因:'.$res); + + }else{ + + $supplyChain = SupplyChain::with(['merchant', 'street', 'area'])->find($id); // 取出当前供应链数据 + + View::assign('detail', $supplyChain); + + // 取出正常的商家 + $merchant = Merchant::where('status', 1)->column('mer_id, real_name'); + // 区域模型 + $arealist = GeoArea::where('city_code', '510500')->select(); + + View::assign('arealist', $arealist); + View::assign('merchant', $merchant); + View::assign('url', $this->url); + return view(); + } + + } + + /** + * + * 删除 + * + */ + public function del() + { + $id = get_params("id"); + + if(!$id) return to_assign(1, '非法操作!'); + + $res = StoreProductReply::where('reply_id', $id)->delete(); + + if ($res){ + return to_assign(0,'操作成功',['aid'=>$res]); + } + + return to_assign(1, '操作失败,原因:'.$res); + + } + +} \ No newline at end of file diff --git a/app/admin/controller/product/Label.php b/app/admin/controller/product/Label.php new file mode 100644 index 0000000..e2596d6 --- /dev/null +++ b/app/admin/controller/product/Label.php @@ -0,0 +1,264 @@ +adminInfo = get_login_admin(); + $this->category_id=354; + $this->url=[ + '/admin/product.label/index?category_id='.$this->category_id, + '/admin/product.label/add', + '/admin/product.label/edit', + '/admin/product.label/del', + '/admin/product.label/index', + ]; + } + + /** + * + * 商品评论列表 + * + */ + public function index() + { + if (request()->isAjax()) { + + $params= get_params(); + + $where = []; + + if (isset($params['keywords']) && !empty($params['keywords'])){ + $where[]= ['name','like','%'.$params['keywords'].'%']; + } + if($this->adminInfo['position_id'] != 1){ //不是超级管理员 + $www['admin_id'] = $this->adminInfo['id']; + $user_address = Db::table('fa_szxc_information_useraddress')->where($www)->find(); + if ($user_address){ + if($user_address['auth_range'] == 1){ + $where[] = ['village_id','=',$user_address['village_id']]; + }elseif ($user_address['auth_range'] == 2){ + $where[] = ['street_id','=',$user_address['street_id']]; + }elseif ($user_address['auth_range'] == 3){ + $where[] = ['area_id','=',$user_address['area_id']]; + }else{ + $where[] = ['village_id','=',$user_address['village_id']]; + } + }else{ + $where[] = ['village_id','=','']; + } + } + + $total = StoreProductLabel::where($where)->count(); + + $list = StoreProductLabel::with(['product'])->order('product_label_id desc')->select(); + + View::assign('url', $this->url); + View::assign('list', $list); + + $result = ['total' => $total, 'data' => $list]; + + return table_assign(0, '', $result); + + }else{ + + $list = StoreProductLabel::select(); + + View::assign('url', $this->url); + View::assign('list', $list); + return view(); + } + } + + /** + * + * 新增 + * + */ + public function add() + { + if (request()->isAjax()) { + + $params = get_params(); + + $data['user_id'] = $this->adminInfo['id']; // 操作用户ID + $data['name'] = $params['title']; // 团队名称 + $data['tel'] = $params['phone']; // 联系电话 + $data['mer_id_list'] = json_encode($params['mer_id']); // 已选商户 + + $data['street_id'] = $params['street_id']; // 街道ID + $street = GeoStreet::where('street_id', $data['street_id'])->find(); // 街道数据 + $data['lng'] = $street['lng']; // 经度 + $data['lat'] = $street['lat']; // 纬度 + $area = $street->area; // 区数据 + $data['area_id'] = $area['area_id']; // 区县id + $city = $area->city; // 获取市级 + $data['address'] = $city['city_name'] . $area['area_name'] . $street['street_name']; // 实际地址 + $data['create_time'] = date('Y-m-d H:i:s'); + + // 数据入库 + $res = SupplyChain::create($data); + + // 关联数据入库 + foreach ($params['mer_id'] as $v) { + + $dataLink = [ + 'eb_merchant_id' => $v, // 商户ID + 'user_id' => $data['user_id'], + 'create_time' => $data['create_time'], + ]; + + $res->linkMerchant()->save($dataLink); // 插入关联数据 + } + + if ($res){ + return to_assign(0,'操作成功',['aid'=>$res]); + } + + return to_assign(1, '操作失败,原因:'.$res); + + }else{ + + // 取出正常的商家 + $merchant = Merchant::where('status', 1)->column('mer_id, real_name'); + + // 区域模型 + $arealist = GeoArea::where('city_code', '510500')->select(); + + View::assign('editor', get_system_config('other','editor')); + View::assign('arealist', $arealist); + View::assign('merchant', $merchant); + View::assign('url', $this->url); + return view(); + } + } + + /** + * + * 编辑 + * + */ + public function edit() + { + $id = get_params("id"); + if(!$id) return to_assign(1, '非法操作!'); + + if (request()->isAjax()) { + + $params = get_params(); + + $data['id'] = $params['id']; // 当前ID + $data['user_id'] = $this->adminInfo['id']; // 操作用户ID + $data['name'] = $params['title']; // 团队名称 + $data['tel'] = $params['phone']; // 联系电话 + $data['mer_id_list'] = isset($params['mer_id']) ? json_encode($params['mer_id']) : null; // 已选商户 + $data['street_id'] = $params['street_id']; // 街道ID + $street = GeoStreet::where('street_id', $data['street_id'])->find(); // 街道数据 + $data['lng'] = $street['lng']; // 经度 + $data['lat'] = $street['lat']; // 纬度 + $area = $street->area; // 区数据 + $data['area_id'] = $area['area_id']; // 区县id + $city = $area->city; // 获取市级 + $data['address'] = $city['city_name'] . $area['area_name'] . $street['street_name']; // 实际地址 + $data['create_time'] = date('Y-m-d H:i:s'); + + // 数据更新 + $supplyChain = SupplyChain::with(['linkMerchant'])->find($data['id']); + $res = $supplyChain->update($data); + + // 获取关联数据一对一---曲线救国 + $linkMerchant = $supplyChain['linkMerchant']; + // $linkMerchantArr = $linkMerchant->column('id'); + + // 先删除关联数据-- 曲线救国 + $linkMerchant->delete(); + + // 关联商户状态 + if($data['mer_id_list']) + { + // 再重新将关联数据入库 + foreach ($params['mer_id'] as $v) { + + $dataLink = [ + 'eb_merchant_id' => $v, // 商户ID + 'user_id' => $data['user_id'], + 'create_time' => $data['create_time'], + ]; + + $supplyChain->linkMerchant()->save($dataLink); + } + } + + if ($res){ + return to_assign(0,'操作成功',['aid'=>$res]); + } + + return to_assign(1, '操作失败,原因:'.$res); + + }else{ + + $supplyChain = SupplyChain::with(['merchant', 'street', 'area'])->find($id); // 取出当前供应链数据 + + View::assign('detail', $supplyChain); + + // 取出正常的商家 + $merchant = Merchant::where('status', 1)->column('mer_id, real_name'); + // 区域模型 + $arealist = GeoArea::where('city_code', '510500')->select(); + + View::assign('arealist', $arealist); + View::assign('merchant', $merchant); + View::assign('url', $this->url); + return view(); + } + + } + + /** + * + * 删除 + * + */ + public function del() + { + $id = get_params("id"); + + if(!$id) return to_assign(1, '非法操作!'); + + $res = StoreProductReply::where('reply_id', $id)->delete(); + + if ($res){ + return to_assign(0,'操作成功',['aid'=>$res]); + } + + return to_assign(1, '操作失败,原因:'.$res); + + } + +} \ No newline at end of file diff --git a/app/admin/controller/product/Product.php b/app/admin/controller/product/Product.php new file mode 100644 index 0000000..0d3466a --- /dev/null +++ b/app/admin/controller/product/Product.php @@ -0,0 +1,262 @@ +adminInfo = get_login_admin(); + $this->category_id=354; + $this->url=[ + '/admin/product.product/index?category_id='.$this->category_id, + '/admin/product.product/add', + '/admin/product.product/edit', + '/admin/product.product/delete', + '/admin/product.product/index', + ]; + } + + /** + * + * 供应链团队列表 + * + */ + public function index() + { + if (request()->isAjax()) { + + $params= get_params(); + + $where = []; + + if (isset($params['keywords']) && !empty($params['keywords'])){ + $where[]= ['name','like','%'.$params['keywords'].'%']; + } + if($this->adminInfo['position_id'] != 1){ //不是超级管理员 + $www['admin_id'] = $this->adminInfo['id']; + $user_address = Db::table('fa_szxc_information_useraddress')->where($www)->find(); + if ($user_address){ + if($user_address['auth_range'] == 1){ + $where[] = ['village_id','=',$user_address['village_id']]; + }elseif ($user_address['auth_range'] == 2){ + $where[] = ['street_id','=',$user_address['street_id']]; + }elseif ($user_address['auth_range'] == 3){ + $where[] = ['area_id','=',$user_address['area_id']]; + }else{ + $where[] = ['village_id','=',$user_address['village_id']]; + } + }else{ + $where[] = ['village_id','=','']; + } + } + + $total = EbStoreProduct::where($where)->count(); + + $list = EbStoreProduct::with(['merchant' => ['merchantType', 'category']])->order('product_id desc')->select(); + + View::assign('url', $this->url); + View::assign('list', $list); + + $result = ['total' => $total, 'data' => $list]; + + return table_assign(0, '', $result); + + }else{ + + $list = SupplyChain::with(['merchant' => ['merchantType', 'category']])->select(); + + View::assign('url', $this->url); + View::assign('list', $list); + return view(); + } + } + + /** + * + * 新增 + * + */ + public function add() + { + if (request()->isAjax()) { + + $params = get_params(); + + $data['user_id'] = $this->adminInfo['id']; // 操作用户ID + $data['name'] = $params['title']; // 团队名称 + $data['tel'] = $params['phone']; // 联系电话 + $data['mer_id_list'] = json_encode($params['mer_id']); // 已选商户 + + $data['street_id'] = $params['street_id']; // 街道ID + $street = GeoStreet::where('street_id', $data['street_id'])->find(); // 街道数据 + $data['lng'] = $street['lng']; // 经度 + $data['lat'] = $street['lat']; // 纬度 + $area = $street->area; // 区数据 + $data['area_id'] = $area['area_id']; // 区县id + $city = $area->city; // 获取市级 + $data['address'] = $city['city_name'] . $area['area_name'] . $street['street_name']; // 实际地址 + $data['create_time'] = date('Y-m-d H:i:s'); + + // 数据入库 + $res = SupplyChain::create($data); + + // 关联数据入库 + foreach ($params['mer_id'] as $v) { + + $dataLink = [ + 'eb_merchant_id' => $v, // 商户ID + 'user_id' => $data['user_id'], + 'create_time' => $data['create_time'], + ]; + + $res->linkMerchant()->save($dataLink); // 插入关联数据 + } + + if ($res){ + return to_assign(0,'操作成功',['aid'=>$res]); + } + + return to_assign(1, '操作失败,原因:'.$res); + + }else{ + + // 取出正常的商家 + $merchant = Merchant::where('status', 1)->column('mer_id, real_name'); + + // 区域模型 + $arealist = GeoArea::where('city_code', '510500')->select(); + + View::assign('editor', get_system_config('other','editor')); + View::assign('arealist', $arealist); + View::assign('merchant', $merchant); + View::assign('url', $this->url); + return view(); + } + } + + /** + * + * 编辑 + * + */ + public function edit() + { + $id = get_params("id"); + if(!$id) return to_assign(1, '非法操作!'); + + if (request()->isAjax()) { + + $params = get_params(); + + $data['id'] = $params['id']; // 当前ID + $data['user_id'] = $this->adminInfo['id']; // 操作用户ID + $data['name'] = $params['title']; // 团队名称 + $data['tel'] = $params['phone']; // 联系电话 + $data['mer_id_list'] = isset($params['mer_id']) ? json_encode($params['mer_id']) : null; // 已选商户 + $data['street_id'] = $params['street_id']; // 街道ID + $street = GeoStreet::where('street_id', $data['street_id'])->find(); // 街道数据 + $data['lng'] = $street['lng']; // 经度 + $data['lat'] = $street['lat']; // 纬度 + $area = $street->area; // 区数据 + $data['area_id'] = $area['area_id']; // 区县id + $city = $area->city; // 获取市级 + $data['address'] = $city['city_name'] . $area['area_name'] . $street['street_name']; // 实际地址 + $data['create_time'] = date('Y-m-d H:i:s'); + + // 数据更新 + $supplyChain = SupplyChain::with(['linkMerchant'])->find($data['id']); + $res = $supplyChain->update($data); + + // 获取关联数据一对一---曲线救国 + $linkMerchant = $supplyChain['linkMerchant']; + // $linkMerchantArr = $linkMerchant->column('id'); + + // 先删除关联数据-- 曲线救国 + $linkMerchant->delete(); + + // 关联商户状态 + if($data['mer_id_list']) + { + // 再重新将关联数据入库 + foreach ($params['mer_id'] as $v) { + + $dataLink = [ + 'eb_merchant_id' => $v, // 商户ID + 'user_id' => $data['user_id'], + 'create_time' => $data['create_time'], + ]; + + $supplyChain->linkMerchant()->save($dataLink); + } + } + + if ($res){ + return to_assign(0,'操作成功',['aid'=>$res]); + } + + return to_assign(1, '操作失败,原因:'.$res); + + }else{ + + $supplyChain = SupplyChain::with(['merchant', 'street', 'area'])->find($id); // 取出当前供应链数据 + + View::assign('detail', $supplyChain); + + // 取出正常的商家 + $merchant = Merchant::where('status', 1)->column('mer_id, real_name'); + // 区域模型 + $arealist = GeoArea::where('city_code', '510500')->select(); + + View::assign('arealist', $arealist); + View::assign('merchant', $merchant); + View::assign('url', $this->url); + return view(); + } + + } + + /** + * + * 删除 + * + */ + public function delete() + { + $id = get_params("id"); + if(!$id) return to_assign(1, '非法操作!'); + + $supplyChain = SupplyChain::with(['linkMerchant'])->find($id); + // 删除关联模型 + $res = $supplyChain->together(['linkMerchant'])->delete(); + + if ($res){ + return to_assign(0,'操作成功',['aid'=>$res]); + } + + return to_assign(1, '操作失败,原因:'.$res); + + } + +} \ No newline at end of file diff --git a/app/admin/controller/supplychain/Index.php b/app/admin/controller/supplychain/Index.php new file mode 100644 index 0000000..fe57dad --- /dev/null +++ b/app/admin/controller/supplychain/Index.php @@ -0,0 +1,257 @@ +adminInfo = get_login_admin(); + $this->category_id=354; + $this->url=[ + '/admin/supplychain.index/index?category_id='.$this->category_id, + '/admin/supplychain.index/add', + '/admin/supplychain.index/edit', + '/admin/supplychain.index/delete', + '/admin/supplychain.merchant/index', + '/admin/supplychain.merchant/bill', + ]; + } + + /** + * + * 供应链团队列表 + * + */ + public function index() + { + if (request()->isAjax()) { + + $params= get_params(); + + $where[]= ['status','=',0]; + + if (isset($params['keywords']) && !empty($params['keywords'])){ + $where[]= ['name','like','%'.$params['keywords'].'%']; + } + if($this->adminInfo['position_id'] != 1){ //不是超级管理员 + $www['admin_id'] = $this->adminInfo['id']; + $user_address = Db::table('fa_szxc_information_useraddress')->where($www)->find(); + if ($user_address){ + if($user_address['auth_range'] == 1){ + $where[] = ['village_id','=',$user_address['village_id']]; + }elseif ($user_address['auth_range'] == 2){ + $where[] = ['street_id','=',$user_address['street_id']]; + }elseif ($user_address['auth_range'] == 3){ + $where[] = ['area_id','=',$user_address['area_id']]; + }else{ + $where[] = ['village_id','=',$user_address['village_id']]; + } + }else{ + $where[] = ['village_id','=','']; + } + } + + $total = SupplyChain::where($where)->count(); + + $list = SupplyChain::with(['merchant', 'street', 'area'])->order('id desc')->select(); + + View::assign('url', $this->url); + View::assign('list', $list); + + $result = ['total' => $total, 'data' => $list]; + + return table_assign(0, '', $result); + + }else{ + + $list = SupplyChain::select(); + + View::assign('url', $this->url); + View::assign('list', $list); + return view(); + } + } + + /** + * + * 新增 + * + */ + public function add() + { + if (request()->isAjax()) { + + $params = get_params(); + + $data['user_id'] = $this->adminInfo['id']; // 操作用户ID + $data['name'] = $params['title']; // 团队名称 + $data['tel'] = $params['phone']; // 联系电话 + $data['mer_id_list'] = json_encode($params['mer_id']); // 已选商户 + + $data['street_id'] = $params['street_id']; // 街道ID + $street = GeoStreet::where('street_id', $data['street_id'])->find(); // 街道数据 + $data['lng'] = $street['lng']; // 经度 + $data['lat'] = $street['lat']; // 纬度 + $area = $street->area; // 区数据 + $data['area_id'] = $area['area_id']; // 区县id + $city = $area->city; // 获取市级 + $data['address'] = $city['city_name'] . $area['area_name'] . $street['street_name']; // 实际地址 + $data['create_time'] = date('Y-m-d H:i:s'); + + // 数据入库 + $res = SupplyChain::create($data); + + // 关联数据入库 + foreach ($params['mer_id'] as $v) { + + $dataLink = [ + 'eb_merchant_id' => $v, // 商户ID + 'user_id' => $data['user_id'], + 'create_time' => $data['create_time'], + ]; + + $res->linkMerchant()->save($dataLink); // 插入关联数据 + } + + if ($res){ + return to_assign(0,'操作成功',['aid'=>$res]); + } + + return to_assign(1, '操作失败,原因:'.$res); + + }else{ + + // 取出正常的商家 + $merchant = Merchant::where('status', 1)->column('mer_id, real_name'); + + // 区域模型 + $arealist = GeoArea::where('city_code', '510500')->select(); + + View::assign('editor', get_system_config('other','editor')); + View::assign('arealist', $arealist); + View::assign('merchant', $merchant); + View::assign('url', $this->url); + return view(); + } + } + + /** + * + * 编辑 + * + */ + public function edit() + { + $id = get_params("id"); + if(!$id) return to_assign(1, '非法操作!'); + + if (request()->isAjax()) { + + $params = get_params(); + + $data['id'] = $params['id']; // 当前ID + $data['user_id'] = $this->adminInfo['id']; // 操作用户ID + $data['name'] = $params['title']; // 团队名称 + $data['tel'] = $params['phone']; // 联系电话 + $data['mer_id_list'] = isset($params['mer_id']) ? json_encode($params['mer_id']) : null; // 已选商户 + $data['street_id'] = $params['street_id']; // 街道ID + $street = GeoStreet::where('street_id', $data['street_id'])->find(); // 街道数据 + $data['lng'] = $street['lng']; // 经度 + $data['lat'] = $street['lat']; // 纬度 + $area = $street->area; // 区数据 + $data['area_id'] = $area['area_id']; // 区县id + $city = $area->city; // 获取市级 + $data['address'] = $city['city_name'] . $area['area_name'] . $street['street_name']; // 实际地址 + $data['create_time'] = date('Y-m-d H:i:s'); + + // 数据更新 + $supplyChain = SupplyChain::with(['linkMerchant'])->find($data['id']); + $res = $supplyChain->update($data); + + // 获取关联数据一对一---曲线救国 + $linkMerchant = $supplyChain['linkMerchant']; + // $linkMerchantArr = $linkMerchant->column('id'); + + // 先删除关联数据-- 曲线救国 + $linkMerchant->delete(); + + // 关联商户状态 + if($data['mer_id_list']) + { + // 再重新将关联数据入库 + foreach ($params['mer_id'] as $v) { + + $dataLink = [ + 'eb_merchant_id' => $v, // 商户ID + 'user_id' => $data['user_id'], + 'create_time' => $data['create_time'], + ]; + + $supplyChain->linkMerchant()->save($dataLink); + } + } + + if ($res){ + return to_assign(0,'操作成功',['aid'=>$res]); + } + + return to_assign(1, '操作失败,原因:'.$res); + + }else{ + + $supplyChain = SupplyChain::with(['merchant', 'street', 'area'])->find($id); // 取出当前供应链数据 + + View::assign('detail', $supplyChain); + + // 取出正常的商家 + $merchant = Merchant::where('status', 1)->column('mer_id, real_name'); + // 区域模型 + $arealist = GeoArea::where('city_code', '510500')->select(); + + View::assign('arealist', $arealist); + View::assign('merchant', $merchant); + View::assign('url', $this->url); + return view(); + } + + } + + /** + * + * 删除 + * + */ + public function delete() + { + $id = get_params("id"); + if(!$id) return to_assign(1, '非法操作!'); + + $supplyChain = SupplyChain::with(['linkMerchant'])->find($id); + // 删除关联模型 + $res = $supplyChain->together(['linkMerchant'])->delete(); + + if ($res){ + return to_assign(0,'操作成功',['aid'=>$res]); + } + + return to_assign(1, '操作失败,原因:'.$res); + + } + +} \ No newline at end of file diff --git a/app/admin/controller/supplychain/Merchant.php b/app/admin/controller/supplychain/Merchant.php new file mode 100644 index 0000000..d77e5f8 --- /dev/null +++ b/app/admin/controller/supplychain/Merchant.php @@ -0,0 +1,185 @@ +adminInfo = get_login_admin(); + $this->category_id=354; + $this->url=[ + '/admin/supplychain.index/index?category_id='.$this->category_id, + '/admin/supplychain.index/add', + '/admin/supplychain.index/edit', + '/admin/supplychain.index/delete', + '/admin/supplychain.merchant/index', + '/admin/supplychain.merchant/bill', + ]; + } + + /** + * + * 供应链团队列表 + * + */ + public function index() + { + if (request()->isAjax()) { + + $params= get_params(); + + $where = []; + + if (isset($params['keywords']) && !empty($params['keywords'])){ + $where[]= ['name','like','%'.$params['keywords'].'%']; + } + if($this->adminInfo['position_id'] != 1){ //不是超级管理员 + $www['admin_id'] = $this->adminInfo['id']; + $user_address = Db::table('fa_szxc_information_useraddress')->where($www)->find(); + if ($user_address){ + if($user_address['auth_range'] == 1){ + $where[] = ['village_id','=',$user_address['village_id']]; + }elseif ($user_address['auth_range'] == 2){ + $where[] = ['street_id','=',$user_address['street_id']]; + }elseif ($user_address['auth_range'] == 3){ + $where[] = ['area_id','=',$user_address['area_id']]; + }else{ + $where[] = ['village_id','=',$user_address['village_id']]; + } + }else{ + $where[] = ['village_id','=','']; + } + } + + $total = SupplyChainLinkMerchant::where($where)->count(); + + $list = SupplyChainLinkMerchant::with(['supplyChain', 'merchant'])->order('id desc')->select(); + + View::assign('url', $this->url); + View::assign('list', $list); + + $result = ['total' => $total, 'data' => $list]; + + return table_assign(0, '', $result); + + }else{ + + $total = SupplyChainLinkMerchant::count(); + $list = SupplyChainLinkMerchant::with(['merchant', 'supplyChain'])->select(); + + View::assign('url', $this->url); + View::assign('list', $list); + + $result = ['total' => $total, 'data' => $list]; + return view(); + } + } + + /** + * + * 交易订单 + * + */ + public function bill() + { + if (request()->isAjax()) { + + $params= get_params(); + + $where = []; + + if (isset($params['keywords']) && !empty($params['keywords'])){ + $where[]= ['name','like','%'.$params['keywords'].'%']; + } + if($this->adminInfo['position_id'] != 1){ //不是超级管理员 + $www['admin_id'] = $this->adminInfo['id']; + $user_address = Db::table('fa_szxc_information_useraddress')->where($www)->find(); + if ($user_address){ + if($user_address['auth_range'] == 1){ + $where[] = ['village_id','=',$user_address['village_id']]; + }elseif ($user_address['auth_range'] == 2){ + $where[] = ['street_id','=',$user_address['street_id']]; + }elseif ($user_address['auth_range'] == 3){ + $where[] = ['area_id','=',$user_address['area_id']]; + }else{ + $where[] = ['village_id','=',$user_address['village_id']]; + } + }else{ + $where[] = ['village_id','=','']; + } + } + + $total = StoreOrderModel::where($where)->count(); + + $list = StoreOrderModel::with(['merchant'])->order('order_id desc')->select(); + + View::assign('url', $this->url); + View::assign('list', $list); + + $result = ['total' => $total, 'data' => $list]; + + return table_assign(0, '', $result); + + }else{ + + $total = StoreOrderModel::count(); + $list = StoreOrderModel::with(['merchant'])->select(); + + View::assign('url', $this->url); + View::assign('list', $list); + + $result = ['total' => $total, 'data' => $list]; + return view(); + } + + } + + /** + * + * 新增 + * + */ + public function add() + { + return view(); + } + + /** + * + * 编辑 + * + */ + public function edit() + { + return view(); + } + + /** + * + * 删除 + * + */ + public function delete() + { + return view(); + } + +} \ No newline at end of file diff --git a/app/admin/model/EbStoreProduct.php b/app/admin/model/EbStoreProduct.php new file mode 100644 index 0000000..b5a873b --- /dev/null +++ b/app/admin/model/EbStoreProduct.php @@ -0,0 +1,31 @@ +hasOne(Merchant::class, 'mer_id', 'mer_id'); + } + } \ No newline at end of file diff --git a/app/admin/model/GeoArea.php b/app/admin/model/GeoArea.php new file mode 100644 index 0000000..3ac0060 --- /dev/null +++ b/app/admin/model/GeoArea.php @@ -0,0 +1,26 @@ +hasOne(GeoArea::class, 'area_code', 'area_code'); + } + } \ No newline at end of file diff --git a/app/admin/model/GeoCity.php b/app/admin/model/GeoCity.php new file mode 100644 index 0000000..ea24176 --- /dev/null +++ b/app/admin/model/GeoCity.php @@ -0,0 +1,19 @@ +hasOne(GeoArea::class, 'area_code', 'area_code'); + } + } \ No newline at end of file diff --git a/app/admin/model/Merchant.php b/app/admin/model/Merchant.php new file mode 100644 index 0000000..4368153 --- /dev/null +++ b/app/admin/model/Merchant.php @@ -0,0 +1,52 @@ +hasOneThrough(SupplyChainLinkMerchant::class, SupplyChain::class); + } + + /** + * + * 关联商户类型 + * + */ + public function merchantType() + { + return $this->hasOne(MerchantType::class, 'mer_type_id', 'type_id'); + } + + /** + * + * 关联商户类别 + * + */ + public function category() + { + return $this->hasOne(MerchantCategory::class, 'merchant_category_id', 'category_id'); + } + + } \ No newline at end of file diff --git a/app/admin/model/MerchantCategory.php b/app/admin/model/MerchantCategory.php new file mode 100644 index 0000000..b486efa --- /dev/null +++ b/app/admin/model/MerchantCategory.php @@ -0,0 +1,22 @@ +hasOne(EbStoreProduct::class, 'product_id', 'product_id'); + } + + /** + * + * 所属用户 + * + */ + public function user() + { + return $this->hasOne(Merchant::class, 'mer_id', 'mer_id'); + } + } \ No newline at end of file diff --git a/app/admin/model/StoreCategory.php b/app/admin/model/StoreCategory.php new file mode 100644 index 0000000..94ffe02 --- /dev/null +++ b/app/admin/model/StoreCategory.php @@ -0,0 +1,22 @@ +hasOne(Merchant::class, 'mer_id', 'mer_id'); + } + + /** + * 所属商品 + * + */ + public function cart() + { + return $this->hasOne(StoreCart::class, 'cart_id', 'cart_id'); + } + + /** + * 获取购物车商品 + * + */ + public function getCartIdAttr($value) + { + // 分割为数组 + $cartId = explode(',', $value); + // 购物车ID + $scartList = StoreCart::whereIn('cart_id', $cartId)->with(['product'])->select(); + + return $scartList; + } + + /** + * + * 所属用户 + * + */ + public function user() + { + return $this->hasOne(Merchant::class, 'mer_id', 'mer_id'); + } + } \ No newline at end of file diff --git a/app/admin/model/StoreProductLabel.php b/app/admin/model/StoreProductLabel.php new file mode 100644 index 0000000..881f58a --- /dev/null +++ b/app/admin/model/StoreProductLabel.php @@ -0,0 +1,51 @@ +hasOne(EbStoreProduct::class, 'product_id', 'product_id'); + } + } \ No newline at end of file diff --git a/app/admin/model/StoreProductReply.php b/app/admin/model/StoreProductReply.php new file mode 100644 index 0000000..e4fcbb3 --- /dev/null +++ b/app/admin/model/StoreProductReply.php @@ -0,0 +1,51 @@ +hasOne(EbStoreProduct::class, 'product_id', 'product_id'); + } + } \ No newline at end of file diff --git a/app/admin/model/SupplyChain.php b/app/admin/model/SupplyChain.php new file mode 100644 index 0000000..2b6762a --- /dev/null +++ b/app/admin/model/SupplyChain.php @@ -0,0 +1,60 @@ +hasManyThrough(Merchant::class, SupplyChainLinkMerchant::class, 'fa_supply_chain_id', 'mer_id', 'id', 'eb_merchant_id'); + } + + /** + * + * 关联中间表 + * + */ + public function linkMerchant() + { + return $this->hasMany(SupplyChainLinkMerchant::class, 'fa_supply_chain_id'); + } + + /** + * 关联街道 + * + * + */ + public function street() + { + return $this->hasOne(GeoStreet::class, 'street_id', 'street_id'); + } + + /** + * 关联区县 + * + * + */ + public function area() + { + return $this->hasOne(GeoArea::class, 'area_id', 'area_id'); + } + } \ No newline at end of file diff --git a/app/admin/model/SupplyChainLinkMerchant.php b/app/admin/model/SupplyChainLinkMerchant.php new file mode 100644 index 0000000..b2cf046 --- /dev/null +++ b/app/admin/model/SupplyChainLinkMerchant.php @@ -0,0 +1,44 @@ +hasOne(SupplyChain::class, 'id', 'fa_supply_chain_id'); + } + + /** + * + * 所属商户 + * 一对一 + * + */ + public function merchant() + { + return $this->hasOne(Merchant::class, 'mer_id', 'eb_merchant_id'); + } + } \ No newline at end of file diff --git a/app/admin/view/product/Label/add.html b/app/admin/view/product/Label/add.html new file mode 100644 index 0000000..d5e2d1e --- /dev/null +++ b/app/admin/view/product/Label/add.html @@ -0,0 +1,96 @@ +{extend name="common/base"/} +{block name="style"} + +{/block} + +{block name="body"} +
+{/block} + + + +{block name="script"} + + + + +{/block} + \ No newline at end of file diff --git a/app/admin/view/product/Label/edit.html b/app/admin/view/product/Label/edit.html new file mode 100644 index 0000000..2ebf4e4 --- /dev/null +++ b/app/admin/view/product/Label/edit.html @@ -0,0 +1,188 @@ +{extend name="common/base"/} +{block name="style"} + +{/block} + +{block name="body"} + +{/block} + + + +{block name="script"} + + + + +{/block} + \ No newline at end of file diff --git a/app/admin/view/product/Label/index.html b/app/admin/view/product/Label/index.html new file mode 100644 index 0000000..3bc5c51 --- /dev/null +++ b/app/admin/view/product/Label/index.html @@ -0,0 +1,200 @@ +{extend name="common/base"/} + +{block name="body"} + +标题* | ++ | ||||||
简介* | ++ + | +||||||
内容 | ++ + | +||||||
坐标 | +
+ 经度:{$detail.lng} +纬度:{$detail.lat} + + |
+ ||||||
运输距离 | +
+ {volist name='farmers' id='vo'}
+ 距离 {$vo.title} {$vo.juli} 公里 + {/volist} + |
+
标题* | ++ | ||||||
简介* | ++ + | +||||||
内容 | ++ + | +||||||
坐标 | +
+ 经度:{$detail.lng} +纬度:{$detail.lat} + + |
+ ||||||
运输距离 | +
+ {volist name='farmers' id='vo'}
+ 距离 {$vo.title} {$vo.juli} 公里 + {/volist} + |
+