368 行
12 KiB
PHP
可执行文件
368 行
12 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Common\Model;
|
|
|
|
use Retail\Model\ThirdErpSetModel;
|
|
|
|
//[1.8.50]
|
|
|
|
/**
|
|
* 插件表
|
|
* Class RetailPlugModel
|
|
* @package Common\Model
|
|
*/
|
|
class RetailPlugModel extends BaseModel
|
|
{
|
|
protected $tableName = 'plug';
|
|
protected $fields = array(
|
|
'id', //int(11) NOT NULL AUTO_INCREMENT,
|
|
'plug_name', //varchar(100) DEFAULT NULL COMMENT '插件名称',
|
|
'plug_url', //varchar(255) DEFAULT NULL COMMENT '插件管理路径',
|
|
'use_url', //varchar(255) DEFAULT NULL COMMENT '使用路径',
|
|
'icon_url', //varchar(255) DEFAULT NULL COMMENT '图标路径',
|
|
'status', //smallint(1) DEFAULT NULL COMMENT '是否启用 0:未启用 1:已启用',
|
|
'addtime', //varchar(12) DEFAULT NULL COMMENT '添加时间',
|
|
'information', //varchar(1000) DEFAULT NULL COMMENT '描述信息',
|
|
'class_id', //int(11) DEFAULT NULL COMMENT '类别id',
|
|
'type', //tinyint(1) DEFAULT '1',
|
|
'origin_type', //tinyint(1) DEFAULT '1' COMMENT '插件来源 1系统自带 2付费插件',
|
|
'identification',//varchar(255) DEFAULT NULL COMMENT '插件唯一标识',
|
|
'version', //varchar(50) DEFAULT NULL COMMENT '版本号',
|
|
'private_key', //varchar(255) DEFAULT NULL COMMENT '应用私钥',
|
|
'is_install', //tinyint(1) DEFAULT '0' COMMENT '是否安装 0未安装 1已安装',
|
|
);
|
|
|
|
/*
|
|
* 获取该门店的插件状态
|
|
* */
|
|
public function getPlugStatus($map, $fields)
|
|
{
|
|
$status = $this->alias('p')
|
|
->join('ls_plug_store as s on p.id=s.plug_id')
|
|
->field($fields)
|
|
->where($map)
|
|
->find();
|
|
return $status;
|
|
}
|
|
|
|
/*
|
|
* 获取该门店的插件状态
|
|
* */
|
|
public function getGiftStatus($where, $field)
|
|
{
|
|
$status = M('plug as p')// 礼品卡插件
|
|
->join('ls_plug_merchant as m on p.id=m.plug_id')
|
|
->field($field)
|
|
->where($where)
|
|
->find();
|
|
return $status;
|
|
}
|
|
|
|
/**
|
|
* 验证商户的红包插件是否可用
|
|
* $merchant_id 商户id
|
|
*/
|
|
public function getRewardAccess($merchant_id)
|
|
{
|
|
$plug = $this->getFind(array('plug_name' => '红包', 'status' => 1));
|
|
if ($plug) {
|
|
$PlugMerchantModel = new RetailPlugMerchantModel();
|
|
// 有该插件
|
|
$map['plug_id'] = $plug['id']; //
|
|
$map['merchant_id'] = $merchant_id; // 主店id
|
|
$map['m_status'] = 1;
|
|
$merchant_plug = $PlugMerchantModel->getFind($map);
|
|
if ($merchant_plug) {
|
|
return $plug;
|
|
} else {
|
|
return false;
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 2019-12-14 获取该门店的插件状态
|
|
* @param $store_id
|
|
* @param $plug array()
|
|
* @return array()
|
|
*/
|
|
public function getStorePlugState($store_id, $plug = array('拼团', '秒杀', '预售'))
|
|
{
|
|
$map = array(
|
|
'p.plug_name' => array('in', $plug),
|
|
'p.status' => 1,
|
|
's.storeid' => $store_id,
|
|
's.s_status' => 1,
|
|
);
|
|
$fields = array(
|
|
'p.plug_name',
|
|
);
|
|
$list = $this->alias('p')
|
|
->join('ls_plug_merchant as m on p.id=m.plug_id AND m.m_status=1')
|
|
->join('ls_retail_store as o on o.merchantid=m.merchant_id')
|
|
->join('ls_plug_store as s on p.id=s.plug_id AND s.s_status=1 AND o.id=s.storeid')
|
|
->field($fields)
|
|
->where($map)
|
|
->select();
|
|
$res = array(
|
|
'group_state' => 0,
|
|
'seckill_state' => 0,
|
|
'advance_state' => 0,
|
|
);
|
|
foreach ($list as $val) {
|
|
switch ($val['plug_name']) {
|
|
case '拼团':
|
|
$res['group_state'] = 1;
|
|
break;
|
|
case '秒杀':
|
|
$res['seckill_state'] = 1;
|
|
break;
|
|
case '预售':
|
|
$res['advance_state'] = 1;
|
|
break;
|
|
}
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 2019-12-14 获取该商户的插件状态
|
|
* @param $merchant_id
|
|
* @param $plug array()
|
|
* @return array()
|
|
*/
|
|
public function getMerchantPlugState($merchant_id, $plug = array('积分商城', '礼品卡', '大转盘', '红包', '优惠券', '次卡'))
|
|
{
|
|
$map = array(
|
|
'p.plug_name' => array('in', $plug),
|
|
'p.status' => 1,
|
|
'm.m_status' => 1,
|
|
'm.merchant_id' => $merchant_id,
|
|
);
|
|
$fields = array(
|
|
'p.plug_name',
|
|
);
|
|
$list = $this->alias('p')
|
|
->join('ls_plug_merchant as m on p.id=m.plug_id AND m.m_status=1')
|
|
->field($fields)
|
|
->where($map)
|
|
->select();
|
|
$res = array(
|
|
'score_mall_state' => 0,
|
|
'gift_card_state' => 0,
|
|
'turntable_state' => 0,
|
|
'reward_state' => 0,
|
|
'coupon_state' => 0,
|
|
'sub_card_state' => 0,
|
|
);
|
|
foreach ($list as $val) {
|
|
switch ($val['plug_name']) {
|
|
case '积分商城':
|
|
$res['score_mall_state'] = 1;
|
|
break;
|
|
case '礼品卡':
|
|
$res['gift_card_state'] = 1;
|
|
break;
|
|
case '大转盘':
|
|
$res['turntable_state'] = 1;
|
|
break;
|
|
case '红包':
|
|
$res['reward_state'] = 1;
|
|
break;
|
|
case '优惠券':
|
|
$res['coupon_state'] = 1;
|
|
break;
|
|
case '次卡':
|
|
$res['sub_card_state'] = 1;
|
|
break;
|
|
}
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 验证商户插件状态2020-3-27
|
|
* @$parameter $plug_id 插件id集合
|
|
*/
|
|
public function plug_mer_verify($parameter)
|
|
{
|
|
if (is_array($parameter)) {
|
|
$merchant_id = $parameter['merchant_id'];
|
|
$plug_id = $parameter['plug_id'];
|
|
$where = array(
|
|
'p.id' => array('in', $plug_id),
|
|
'p.status' => 1,
|
|
'm.m_status' => 1,
|
|
'm.status' => 1,
|
|
'm.merchant_id' => $merchant_id
|
|
);
|
|
$fields = array(
|
|
'p.id',
|
|
);
|
|
$list = $this->alias('p')
|
|
->join('ls_plug_merchant as m on p.id=m.plug_id')
|
|
->field($fields)
|
|
->where($where)
|
|
->select();
|
|
$res = array(
|
|
'turntable_id' => 0,
|
|
'score_mall_id' => 0,
|
|
'reward_id' => 0,
|
|
'gift_card_id' => 0,
|
|
'coupon_id' => 0,
|
|
'group_id' => 0,
|
|
'seckill_id' => 0,
|
|
'subcard_id' => 0,
|
|
'advance_id' => 0,
|
|
);
|
|
foreach ($list as $val) {
|
|
switch ($val["id"]) {
|
|
case 36:
|
|
//大转盘
|
|
$res['turntable_id'] = $val["id"];
|
|
break;
|
|
case 38:
|
|
//积分商城
|
|
$res['score_mall_id'] = $val["id"];
|
|
break;
|
|
case 39:
|
|
//红包
|
|
$res['reward_id'] = $val["id"];
|
|
break;
|
|
case 40:
|
|
//礼品卡
|
|
$res['gift_card_id'] = $val["id"];
|
|
break;
|
|
case 41:
|
|
//优惠券
|
|
$res['coupon_id'] = $val["id"];
|
|
break;
|
|
case 42:
|
|
//拼团
|
|
$res['group_id'] = $val["id"];
|
|
break;
|
|
case 43:
|
|
//秒杀
|
|
$res['seckill_id'] = $val["id"];
|
|
break;
|
|
case 44:
|
|
//次卡
|
|
$res['subcard_id'] = $val["id"];
|
|
break;
|
|
case 45:
|
|
//预售
|
|
$res['advance_id'] = $val["id"];
|
|
break;
|
|
case 48:
|
|
//微信商家券
|
|
$res['shop_coupon_id'] = $val['id'];
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '参数类型错误';
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
|
|
/**
|
|
* 验证门店插件状态
|
|
* @param $parameter
|
|
* [
|
|
* store_id
|
|
* identification 插件标识
|
|
* ]
|
|
* @return array
|
|
*/
|
|
public function plug_store_verify($parameter)
|
|
{
|
|
if (is_array($parameter)) {
|
|
$store_id = $parameter['store_id'];
|
|
$identification = $parameter['identification'];
|
|
$where = array(
|
|
'p.identification' => array('in', $identification),
|
|
'p.status' => 1,
|
|
's.s_status' => 1,
|
|
's.storeid' => $store_id,
|
|
);
|
|
$fields = array(
|
|
'p.identification'
|
|
);
|
|
$list = $this->alias('p')
|
|
->join('ls_plug_store as s on p.id=s.plug_id')
|
|
->field($fields)
|
|
->where($where)
|
|
->select();
|
|
$res = array(
|
|
'group' => '',
|
|
'seckill' => '',
|
|
'presale' => '',
|
|
'blessing' => ''
|
|
);
|
|
foreach ($list as $val) {
|
|
switch ($val["identification"]) {
|
|
case 'group':
|
|
$res['group'] = $val["identification"];
|
|
break;
|
|
case 'seckill':
|
|
$res['seckill'] = $val["identification"];
|
|
break;
|
|
case 'presale':
|
|
$res['presale'] = $val["identification"];
|
|
break;
|
|
case 'blessing':
|
|
$res['blessing'] = $val["identification"];
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '参数类型错误';
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
|
|
/**
|
|
* 关闭代理商插件
|
|
* @param $plug_id 插件ID
|
|
* @param $agent_id 代理商ID
|
|
* @param $identification 插件标识
|
|
*/
|
|
public function closeAgentPlug($plug_id, $agent_id, $identification)
|
|
{
|
|
$map['plug_id'] = $plug_id;
|
|
$map['a_status'] = 1;
|
|
$map['agent_id'] = $agent_id;
|
|
$updateAgent = M('plug_agent')->where($map)->save(array('a_status' => 2));
|
|
if ($updateAgent) {
|
|
$merchant_ids = M('retail_merchant')->where(array('agentid' => $agent_id))->getField('id', true);
|
|
if (!empty($merchant_list)) {
|
|
$map2['merchant_id'] = array('in', $merchant_ids);
|
|
$map2['m_status'] = 1;
|
|
$map2['plug_id'] = $plug_id;
|
|
$updateMer = M('plug_merchant')->where($map2)->save(array('m_status' => 2));
|
|
if ($updateMer) {
|
|
$storeIds = M('retail_store')->where(['merchantid' => ['in', $merchant_ids], 'state' => 0])->getField('id', true);
|
|
if (!empty($storeIds)) {
|
|
M('plug_store')->where(['plug_id' => $plug_id, 'storeid' => ['in', $storeIds], 's_status' => 1])->save(array('s_status' => 2));
|
|
}
|
|
}
|
|
switch ($identification){
|
|
case 'little_gift':
|
|
$ThirdSetModel = new ThirdErpSetModel();
|
|
$ThirdSetModel->updateOrder([
|
|
'merchant_id'=>['in',$merchant_ids]
|
|
],[
|
|
'status'=>2
|
|
]);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |