diff --git a/app/admin/controller/supplychain/Index.php b/app/admin/controller/supplychain/Index.php index 03caf01..fe57dad 100644 --- a/app/admin/controller/supplychain/Index.php +++ b/app/admin/controller/supplychain/Index.php @@ -69,7 +69,7 @@ class Index extends BaseController $total = SupplyChain::where($where)->count(); - $list = SupplyChain::order('id desc')->select(); + $list = SupplyChain::with(['merchant', 'street', 'area'])->order('id desc')->select(); View::assign('url', $this->url); View::assign('list', $list); @@ -121,7 +121,7 @@ class Index extends BaseController foreach ($params['mer_id'] as $v) { $dataLink = [ - 'mer_id' => $v, // 商户ID + 'eb_merchant_id' => $v, // 商户ID 'user_id' => $data['user_id'], 'create_time' => $data['create_time'], ]; @@ -161,19 +161,75 @@ class Index extends BaseController $id = get_params("id"); if(!$id) return to_assign(1, '非法操作!'); - $supplyChain = SupplyChain::with(['merchant', 'street', 'area'])->find($id); // 取出当前供应链数据 + 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(); + } - 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(); } /** @@ -183,7 +239,19 @@ class Index extends BaseController */ public function delete() { - return view(); + $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 index c5891c4..d77e5f8 100644 --- a/app/admin/controller/supplychain/Merchant.php +++ b/app/admin/controller/supplychain/Merchant.php @@ -9,12 +9,30 @@ namespace app\admin\controller\supplychain; use app\admin\BaseController; use think\facade\Db; use think\facade\View; +use app\admin\model\Merchant as MerchantModel; // 商户模型 +use app\admin\model\StoreOrder as StoreOrderModel; // 商户订单模型 +use app\admin\model\GeoCity; // 省市模型 +use app\admin\model\GeoArea; // 区域模型 +use app\admin\model\GeoStreet; // 街道模型 +use app\admin\model\SupplyChain; // 供应链模型 +use app\admin\model\SupplyChainLinkMerchant; // 供应链关联商户模型 +use app\api\model\Area as AreaModel; // 市场区域模型 +use app\api\model\AreaManager as AreaManagerModel; // 区域负责人模型 class Merchant extends BaseController { public function __construct() { $this->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', + ]; } /** @@ -24,7 +42,55 @@ class Merchant extends BaseController */ public function index() { - return view(); + 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(); + } } /** @@ -34,7 +100,55 @@ class Merchant extends BaseController */ public function bill() { - return view(); + 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(); + } } diff --git a/app/admin/model/EbStoreProduct.php b/app/admin/model/EbStoreProduct.php new file mode 100644 index 0000000..28c3804 --- /dev/null +++ b/app/admin/model/EbStoreProduct.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/StoreOrder.php b/app/admin/model/StoreOrder.php new file mode 100644 index 0000000..0fbfa00 --- /dev/null +++ b/app/admin/model/StoreOrder.php @@ -0,0 +1,64 @@ +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/SupplyChain.php b/app/admin/model/SupplyChain.php index 3bb4bd5..2b6762a 100644 --- a/app/admin/model/SupplyChain.php +++ b/app/admin/model/SupplyChain.php @@ -12,17 +12,20 @@ class SupplyChain extends Model { + // 设置当前模型的数据库连接 + protected $connection = 'mysql'; + // 设置当前模型对应的完整数据表名称 protected $table = 'fa_supply_chain'; /** * 关联拥有多个商户 * 远程一对多 - * + * 关联模型、中间模型 */ public function merchant() { - return $this->belongsToMany(Merchant::class, SupplyChainLinkMerchant::class, 'eb_merchant_id', 'fa_supply_chain_id'); + return $this->hasManyThrough(Merchant::class, SupplyChainLinkMerchant::class, 'fa_supply_chain_id', 'mer_id', 'id', 'eb_merchant_id'); } /** @@ -32,7 +35,7 @@ */ public function linkMerchant() { - return $this->hasMany(SupplyChainLinkMerchant::class); + return $this->hasMany(SupplyChainLinkMerchant::class, 'fa_supply_chain_id'); } /** diff --git a/app/admin/model/SupplyChainLinkMerchant.php b/app/admin/model/SupplyChainLinkMerchant.php index f778055..b2cf046 100644 --- a/app/admin/model/SupplyChainLinkMerchant.php +++ b/app/admin/model/SupplyChainLinkMerchant.php @@ -28,7 +28,7 @@ */ public function supplyChain() { - return $this->hasOne(SupplyChain::class); + return $this->hasOne(SupplyChain::class, 'id', 'fa_supply_chain_id'); } /** @@ -39,6 +39,6 @@ */ public function merchant() { - return $this->hasOne(); + return $this->hasOne(Merchant::class, 'mer_id', 'eb_merchant_id'); } } \ No newline at end of file diff --git a/app/admin/view/supplychain/index/add.html b/app/admin/view/supplychain/index/add.html index 479d6ba..b4b9888 100644 --- a/app/admin/view/supplychain/index/add.html +++ b/app/admin/view/supplychain/index/add.html @@ -180,7 +180,8 @@ data: [], radio: true, initValue: [], - disabled: group_access == 2 || group_access==4 ? true : false + disabled: group_access == 2 || group_access==4 ? true : false, + }); $.get('/api/geo/street?pcode=' + id, function (result) { diff --git a/app/admin/view/supplychain/index/edit.html b/app/admin/view/supplychain/index/edit.html index 2a6e0b3..dff1dd2 100644 --- a/app/admin/view/supplychain/index/edit.html +++ b/app/admin/view/supplychain/index/edit.html @@ -19,6 +19,7 @@ {block name="body"}
+

编辑

@@ -37,12 +38,12 @@ @@ -86,14 +87,12 @@ {else /} {/if} - {/volist}
- {$detail.address}
@@ -114,6 +113,7 @@ {block name="script"} + + + + + + + +{/block} + + + +{block name="script"} + +{/block} + \ No newline at end of file diff --git a/app/admin/view/supplychain/merchant/index.html b/app/admin/view/supplychain/merchant/index.html index acad52f..0ec5f85 100644 --- a/app/admin/view/supplychain/merchant/index.html +++ b/app/admin/view/supplychain/merchant/index.html @@ -5,7 +5,7 @@
- +
@@ -56,7 +56,7 @@ elem: '#article', title: '列表', toolbar: '#toolbarDemo', - url: '{$url[0]}', + url: '{$url[4]}', page: true, limit: 20, cols: [ @@ -68,53 +68,138 @@ align: 'center', width:80, },{ - field: 'area', - title: '区域', + fixed: 'left', + field: 'supplyChain', + title: '供应链', align: 'center', templet: function (d) { - var html = '【' + d['area']['area_name'] + '】' + var html = d.supplyChain.name; return html; }, width:120, },{ - field: 'name', - title: '姓名', - align: 'center', - width:120, - },{ - field: 'duty', - title: '职务', - align: 'center', - width:150, - },{ - field: 'phone', - title: '电话', - align: 'center', - width:150, - },{ - field: 'status', - title: '状态', + field: 'brokerage', + title: '团队负责人', align: 'center', templet: function (d) { - var html = '禁用'; - if (d.status == '0') { + var html = d.principal ? '是': '否'; + return html; + }, + width:150, + },{ + field: 'merchant', + title: '商户', + align: 'center', + templet: function (d) + { + var html = d.merchant.mer_name; + return html; + }, + width:120, + },{ + field: 'merchant', + title: '姓名', + align: 'center', + templet: function (d) + { + var html = d.merchant.real_name; + return html; + }, + width:150, + },{ + field: 'merchant', + title: '联系电话', + align: 'center', + templet: function (d) + { + var html = d.merchant.mer_phone; + return html; + }, + width:150, + },{ + field: 'merchant', + title: '店铺状态', + align: 'center', + templet: function (d) + { + var html = '锁定'; + if (d.merchant.status == 1) { html = '正常'; } return html; }, },{ - field: 'created_at', - title: '添加时间', + field: 'merchant', + title: '产品数量', + align: 'center', + templet: function (d) + { + var html = d.merchant.mer_phone; + return html; + }, + width:150, + },{ + field: 'merchant', + title: '产品数量', + align: 'center', + templet: function (d) + { + var html = d.merchant.mer_phone; + return html; + }, + width:150, + },{ + field: 'merchant', + title: '余额', + align: 'center', + templet: function (d) + { + var html = d.merchant.mer_money; + return html; + }, + width:150, + },{ + field: 'merchant', + title: '保证金', + align: 'center', + templet: function (d) + { + var html = d.merchant.margin; + return html; + }, + width:150, + },{ + field: 'order_number', + title: '销量', + align: 'center', + templet: function (d) + { + var html = d.merchant.sales; + return html; + }, + width:150, + },{ + field: 'merchant', + title: '商户地址', + templet: function (d) + { + var html = d.merchant.mer_address; + return html; + }, align: 'center', width:150, },{ - fixed: 'right', - field: 'right', - title: '操作', - toolbar: '#barDemo', - align: 'center' + field: 'merchant', + title: '入驻时间', + align: 'center', + templet: function (d) + { + var html = d.merchant.create_time; + return html; + }, + width:150, } ] ]
-
+
- {$detail} - {volist name='arealist' id='vo'} - {/volist} + {volist name='detail.merchant' id='vo'} + + {/volist}