文件
mashangyoujiu/Application/Common/Business/Plug.class.php

615 行
19 KiB
PHP
可执行文件

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace Common\Business;
use Agent\Model\AgentPlugModel;
use Common\Model\PlugModel;
use Common\Model\RetailPlugMerchantModel;
use Common\Model\RetailPlugStoreModel;
use Common\Model\RetailStoreModel;
use Common\Model\RetailPlugModel;
use Common\Model\RetailManagerModel;
//[1.9.5]
/**
* 插件类
* Class Plug
* [
* 获取系统是否安装插件 systemPlugState
* 获取代理商插件权限状态 agentPlugState
* 获取商户插件权限状态 merPlugState
* 获取门店插件权限状态 storePlugState
* 获取门店是否拥有并开启插件 storePlugStatus
* 获取门店列表及指定插件的状态 storeList
*
* 以下接口将废弃
* 判断代理商是否拥有插件权限 agentPlugPermissions
* 判断商户是否拥有插件权限 PlugPermissions
* 判断商户是否拥有插件权限的参数验证 PlugPermissionsVerify
* ]
* @package Common\Business
*/
class Plug
{
/**
* 获取系统是否安装插件
* @param $param
* [
* identification_arr 插件唯一标识集合
* ]
* @return array
*/
public function systemPlugState($param)
{
$map = [
'identification' => ['in', $param['identification_arr']],
[
'origin_type' => 1,
[
'origin_type' => 2,
'is_install' => 1
],
'_logic' => 'or'
],
];
$PlugModel = new RetailPlugModel();
$list = $PlugModel->getSelect($map, 'identification');
return $this->handlePlug($param['identification_arr'], $list);
}
/**
* 获取代理商插件权限状态
* @param $param
* [
* agent_id 代理商id
* identification_arr 插件唯一标识集合
* ]
* @return array
*/
public function agentPlugState($param)
{
$where = [
'p.identification' => ['in', $param['identification_arr']],
'p.status' => 1,
'a.a_status' => 1,
'a.agent_id' => $param['agent_id'],
[
'p.origin_type' => 1,
[
'p.origin_type' => 2,
'p.is_install' => 1
],
'_logic' => 'or'
],
];
$PlugModel = new AgentPlugModel();
$list = $PlugModel->plug_permissions($where, 'p.identification');
return $this->handlePlug($param['identification_arr'], $list);
}
/**
* 获取商户插件权限状态
* @param $param
* [
* merchant_id
* identification_arr 插件唯一标识集合
* ]
* @return array
*/
public function merPlugState($param)
{
$where = [
'p.identification' => ['in', $param['identification_arr']],
'p.status' => 1,
'm.m_status' => 1,
'm.merchant_id' => $param['merchant_id'],
'm.status' => 1,
[
'p.origin_type' => 1,
[
'p.origin_type' => 2,
'p.is_install' => 1
],
'_logic' => 'or'
]
];
$PlugModel = new RetailPlugMerchantModel();
$list = $PlugModel->plug_permissions('p.identification', $where);
return $this->handlePlug($param['identification_arr'], $list);
}
/**
* 获取门店插件权限状态
* @param $param
* [
* store_id 门店id
* identification_arr 插件唯一标识集合
* ]
* @return array
*/
public function storePlugState($param)
{
$where = [
'p.identification' => ['in', $param['identification_arr']],
'p.status' => 1,
's.s_status' => 1,
's.storeid' => $param['store_id'],
[
'p.origin_type' => 1,
[
'p.origin_type' => 2,
'p.is_install' => 1
],
'_logic' => 'or'
]
];
$PlugModel = new RetailPlugStoreModel();
$list = $PlugModel->plug_permissions('p.identification', $where);
return $this->handlePlug($param['identification_arr'], $list);
}
/**
* 获取门店是否拥有并开启插件
* @param $param
* [
* store_id 门店id
* identification_arr 插件唯一标识集合
* ]
* @return array
*/
public function storePlugStatus($param)
{
$where = [
'p.identification' => ['in', $param['identification_arr']],
'p.status' => 1,
's.s_status' => 1,
's.status' => 1,//门店是否开启该插件 1开启 2关闭
's.storeid' => $param['store_id'],
[
'p.origin_type' => 1,
[
'p.origin_type' => 2,
'p.is_install' => 1
],
'_logic' => 'or'
]
];
$PlugModel = new RetailPlugStoreModel();
$list = $PlugModel->plug_permissions('p.identification', $where);
return $this->handlePlug($param['identification_arr'], $list);
}
/**
* 获取门店列表及指定插件的状态
* @param $param
* [
* identification 插件唯一标识 必填
* merchant_id 商户id 必填
* page 当前页 必填
* limit 页数量 必填
* name 门店名称 选填
* ]
* @return mixed
*/
public function storeList($param)
{
if (empty($param['identification']) || empty($param['merchant_id']) || empty($param['page']) || empty($param['limit'])) {
return callBack(statusCode()['error'], '必要参数不能为空');
}
$plug = new RetailPlugModel();//插件表
$pMap = [
'identification' => $param['identification'],
];
$plugId = $plug->getFindField($pMap, 'id');//插件id
if (empty($plugId)) {
return callBack(statusCode()['error'], '插件不存在');
}
$map = [
's.merchantid' => $param['merchant_id'],
's.store_status' => 0,
's.state' => 0,
'ps.plug_id' => $plugId
];
if (!empty($param['name'])) {
$map['s.storetag'] = ['like', '%' . $param['name'] . '%'];
}
$fields = [
's.id',
's.storetag as store_name',
's.address',
'ps.s_status',
];
$list = M('retail_store as s')
->join('ls_plug_store as ps on ps.storeid = s.id', 'LEFT')
->where($map)
->field($fields)
->page($param['page'] . ',' . $param['limit'])
->order('s.id asc')
->select();
$count = M('retail_store as s')
->join('ls_plug_store as ps on ps.storeid = s.id', 'LEFT')
->where($map)
->count();
$ManagerModel = new RetailManagerModel();//店长表
$fieldManager = [
'name',
'mobile',
];
foreach ($list as &$val) {
//店长信息
$mMap = [
'storeid' => $val['id'],
'status' => 1,
];
$manager = $ManagerModel->getFind($mMap, $fieldManager);
$val['manager_name'] = $manager['name'];
$val['mobile'] = $manager['mobile'];
$val['s_status'] = $val['s_status'] == 1 ? 1 : 0;
}
return callBack(statusCode()['success'], !empty($list) ? '获取成功' : '暂无数据', [
'list' => $list ? $list : [],
'count' => $count,
]);
}
/**
* 处理插件状态返回值
* @param $identification_arr
* @param array $list
* @return array
* [
* 插件1唯一标识 => true(拥有)
* 插件2唯一标识 => false(未拥有)
* ]
*/
private function handlePlug($identification_arr, $list = [])
{
!is_array($identification_arr) && $identification_arr = explode(',', $identification_arr);
$info = [];
foreach ($list as $val) {
$info[$val['identification']] = true;
}
foreach ($identification_arr as $value) {
!isset($info[$value]) && $info[$value] = false;
}
return $info;
}
/**********************以下方法后期将舍弃**************************/
/**********************以下方法后期将舍弃**************************/
/**********************以下方法后期将舍弃**************************/
/**
* 判断代理商是否拥有插件权限
* @param $param
* [
* agent_id 代理商id
* identification_arr 插件唯一标识集合
* ]
* @return mixed\
*/
public function agentPlugPermissions($param)
{
$where = [
'p.identification' => ['in', $param['identification_arr']],
'p.status' => 1,
'a.a_status' => 1,
'a.agent_id' => $param['agent_id'],
[
'p.origin_type' => 1,
[
'p.origin_type' => 2,
'p.is_install' => 1
],
'_logic' => 'or'
],
];
$fields = 'p.identification,p.id';
$PlugModel = new AgentPlugModel();
$list = $PlugModel->plug_permissions($where, $fields);
$info = [];
if (!empty($list)) {
foreach ($list as $val) {
$info[$val['identification']] = $val['id'];
}
}
return callBack(statusCode()['success'], '查询成功', $info);
}
/**
* 判断商户是否拥有插件权限
* @param $param
* [
* merchant_id
* identification_arr 插件唯一标识集合
* ]
* @return mixed
*/
public function PlugPermissions($param)
{
$verify = $this->PlugPermissionsVerify($param); //参数验证
if ($verify['status'] != 1) {
return $verify;
}
$where = [
'p.identification' => ['in', $param['identification_arr']],
'p.status' => 1,
'm.m_status' => 1,
'm.merchant_id' => $param['merchant_id'],
'm.status' => 1,
[
'p.origin_type' => 1,
[
'p.origin_type' => 2,
'p.is_install' => 1
],
'_logic' => 'or'
]
];
$fields = 'p.id,p.identification';
try {
$PlugModel = new RetailPlugMerchantModel();
$list = $PlugModel->plug_permissions($fields, $where);
} catch (\Exception $e) {
return callBack(statusCode()['success'], "查询成功", ['plug' => []]);
}
$plug = [];
if (!empty($list)) {
foreach ($list as $val) {
$plug[$val['identification']] = $val['id'];
}
}
return callBack(statusCode()['success'], "查询成功", ['plug' => $plug]);
}
/**
* 判断商户是否拥有插件权限的参数验证
* @param $param
* [
* merchant_id
* identification_arr 插件唯一标识集合
* ]
* @return mixed
*/
private function PlugPermissionsVerify($param)
{
if (empty($param['merchant_id']) || empty($param['identification_arr'])) {
return callBack(statusCode()['error'], "参数缺失");
}
if (!is_array($param['identification_arr'])) {
return callBack(statusCode()['error'], "插件参数格式有误");
}
return callBack(statusCode()['success'], "验证成功");
}
/**
* 判断门店是否拥有插件权限(传递方式,同商户)
* @param $param
* [
* store_id 门店id
* identification_arr 插件唯一标识集合
* ]
* @return mixed
*/
public function plugStore($param)
{
$verify = $this->plugStoreVerify($param); //参数验证
if ($verify['status'] != 1) {
return false;
}
$where = [
'p.identification' => ['in', $param['identification_arr']],
'p.status' => 1,
's.s_status' => 1,
's.storeid' => $param['store_id'],
[
'p.origin_type' => 1,
[
'p.origin_type' => 2,
'p.is_install' => 1
],
'_logic' => 'or'
]
];
$fields = 'p.id,p.identification';
try {
$PlugModel = new RetailPlugStoreModel();
$list = $PlugModel->plug_permissions($fields, $where);
} catch (\Exception $e) {
return false;
}
$plug = [];
if (!empty($list)) {
foreach ($list as $val) {
$plug[$val['identification']] = $val['id'];
}
}
if (empty($plug)) {
return false;
} else {
return true;
}
}
/**
* 判断门店是否拥有插件权限的参数验证
* @param $param
* [
* store_id
* identification_arr 插件唯一标识集合
* ]
* @return mixed
*/
private function plugStoreVerify($param)
{
if (empty($param['store_id']) || empty($param['identification_arr'])) {
return callBack(statusCode()['error'], "参数缺失");
}
if (!is_array($param['identification_arr'])) {
return callBack(statusCode()['error'], "插件参数格式有误");
}
return callBack(statusCode()['success'], "验证成功");
}
/**
* 判断门店是否拥有插件,并开启插件权限(传递方式,同商户)
* @param $param
* [
* store_id 门店id
* identification_arr 插件唯一标识集合
* ]
* @return mixed
*/
public function plugStoreStatus($param)
{
$verify = $this->plugStoreVerify($param); //参数验证
if ($verify['status'] != 1) {
return false;
}
$where = [
'p.identification' => ['in', $param['identification_arr']],
'p.status' => 1,
's.s_status' => 1,
's.status' => 1,//门店是否开启该插件 1开启 2关闭
's.storeid' => $param['store_id'],
[
'p.origin_type' => 1,
[
'p.origin_type' => 2,
'p.is_install' => 1
],
'_logic' => 'or'
]
];
$fields = 'p.id,p.identification';
try {
$PlugModel = new RetailPlugStoreModel();
$list = $PlugModel->plug_permissions($fields, $where);
} catch (\Exception $e) {
return false;
}
$plug = [];
if (!empty($list)) {
foreach ($list as $val) {
$plug[$val['identification']] = $val['id'];
}
}
if (empty($plug)) {
return false;
} else {
return true;
}
}
/**
* 插件中的门店情况
* @param $post
* [
* identification 插件唯一标识 必填
* merchant_id 商户id 必填
* page 当前页 必填
* limit 页数量 必填
* name 门店名称 选填
* ]
* use Common\Model\RetailStoreModel; 门店表
* use Common\Model\RetailPlugModel; 插件表
* use Common\Model\RetailPlugStoreModel; 门店插件表
* use Common\Model\RetailManagerModel; 店长信息表
* @return mixed
*/
public function plugStoreList($post)
{
if ($post['identification'] == '' || $post['merchant_id'] == '' || $post['page'] == '' || $post['limit'] == '') {
return callBack(statusCode()['error'], '参数不能为空');
}
$merchantId = $post['merchant_id'];//商户id
$whereStore = [
'merchantid' => $merchantId,
'store_status' => 0,
'state' => 0,
];
if (isset($post['name']) && $post['name'] !== '') {
$whereStore[] = 'storetag like "%' . $post['name'] . '%"';
}
$fieldStore = [
'id',
'storetag as storetag_name',
'address',
];
$page = $post['page'] . ',' . $post['limit'];//分页
$retailStoreModel = new RetailStoreModel();//门店表
$data['total'] = $retailStoreModel->getCount($whereStore);
$data['data'] = $retailStoreModel->getSelect($whereStore, $fieldStore, $order = 'id asc', $page);//商户下的门店
$plug = new RetailPlugModel();//插件表
$wherePlug = [
'identification' => $post['identification'],
];
$fieldPlug = [
'id'
];
$plugId = $plug->getFind($wherePlug, $fieldPlug);//插件id
if (!$plugId) {
return callBack(statusCode()['error'], '没有这个插件');
}
$retailManagerModel = new RetailManagerModel();//店长表
$retailPlugStoreModel = new RetailPlugStoreModel();//门店插件表
foreach ($data['data'] as $k => $v) {
//店长信息
$whereManager = [
'storeid' => $v['id'],
'status' => 1,
];
$fieldManager = [
'name',
'mobile',
];
$manager = $retailManagerModel->getFind($whereManager, $fieldManager);
$v['manager_name'] = $manager['name'];
$v['mobile'] = $manager['mobile'];
//门店插件
$wherePlugStore = [
'storeid' => $v['id'],
'plug_id' => $plugId['id'],
];
$fieldPlugStore = [
's_status'
];
$plugStore = $retailPlugStoreModel->getFind($wherePlugStore, $fieldPlugStore);
if ($plugStore) {
$v['s_status'] = $plugStore['s_status'];
} else {
$v['s_status'] = 0;
}
$data['data'][$k] = $v;
}
if ($data['total'] === false || $data['data'] === false) {
return callBack(statusCode()['error'], '失败');
} else {
return callBack(statusCode()['success'], '成功', $data);
}
}
}