文件
mashangyoujiu/Application/Retail/Controller/XcxRouteController.class.php

487 行
17 KiB
PHP
可执行文件

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

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

<?php
namespace Retail\Controller;
use Think\Controller;
//[1.6.10]
/**
* 小程序地址
* Class XcxRouteController
* @package Retail\Controller
*/
class XcxRouteController extends BaseController
{
public function _initialize()
{
parent::_initialize();
if (empty($this->store_id)) {
if (IS_POST) {
$res = array(
'status' => 0,
'msg' => '您无权访问该接口',
);
$this->ajaxReturn($res);
} else {
session(null);
echo '<script>top.window.location="' . $_SERVER ["SCRIPT_NAME"] . '/Retail/Login/index"</script>';
exit;
}
}
}
/**
* 已添加的地址列表页
*/
public function index()
{
$systemRouteList = D('SystemXcxRoute')->select();
foreach ($systemRouteList as &$value) {
$value['param_json'] = json_decode($value['param_json'], true);
}
$arr = array(
'addRoute' => '/index.php/Retail/XcxRoute/addRoute',
'changeRoute' => '/index.php/Retail/XcxRoute/changeRoute',
'delRoute' => '/index.php/Retail/XcxRoute/delRoute',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->assign('store_id', $this->store_id);
$this->assign('systemRouteList', json_encode($systemRouteList));
$this->display();
}
/**
* 获取已添加地址列表
*/
public function getRouteList()
{
$page = I('post.page');
$limit = I('post.limit');
$time = I('post.time');
$keyword = I('post.keyword');
$route_status = I('post.route_status');
$StoreXcxRouteModel = D('StoreXcxRoute');
$map = array(
'state' => 1,
'store_id' => $this->store_id,
);
if (!empty($time)) {
$map['add_time'] = array('between', array(strtotime($time[0]), strtotime($time[1])));
}
if (!empty($keyword)) {
$map['name'] = array('like', "%{$keyword}%");
}
if (!empty($route_status)) {
$map['status'] = $route_status == 1 ? 1 : 0;
}
$list = $StoreXcxRouteModel->getSelect($map, '*', 'id desc', $page . ',' . $limit);
//针对新版DIY路由做调整
$newData = array(
'pages/lives/lives' => '/pages/index/lives/lives',
'pages/Coupon/Coupon' => '/pages/index/Coupon/Coupon',
'pages/Group-purchase-details/Group-purchase-details' => '/pages/index/Group-purchase-details/Group-purchase-details',
'pages/Group-purchase/Group-purchase' => '/pages/index/Group-purchase/Group-purchase',
'pages/Seckill-purchase-details/Seckill-purchase-details' => '/pages/index/Seckill-purchase-details/Seckill-purchase-details',
'pages/Seckill-purchase/Seckill-purchase' => '/pages/index/Seckill-purchase/Seckill-purchase',
'pages/advanceDetails/advanceDetails' => '/pages/index/advanceDetails/advanceDetails',
'pages/advanceSale/advanceSale' => '/pages/index/advanceSale/advanceSale',
'pages/MyCollect/MyCollect' => '/pages/mine/MyCollect/MyCollect',
'pages/card/card' => '/pages/mine/card/card',
'pages/gift_home/gift_home' => '/pages/mine/gift_home/gift_home',
'pages/gift_purchase/gift_purchase' => '/pages/mine/gift_purchase/gift_purchase',
'pages/recharge/recharge' => '/pages/mine/recharge/recharge',
'pages/subCard/subCard' => '/pages/mine/subCard/subCard',
'pages/buySubCard/buySubCard' => '/pages/mine/buySubCard/buySubCard',
'pages/MyAddress/MyAddress' => '/pages/mine/MyAddress/MyAddress',
'pages/plusHome/plusHome' => '/pages/mine/plusHome/plusHome',
'pages/details/details' => '/pages/product/details/details',
'pages/new-goods/new-goods' => '/pages/product/new-goods/new-goods',
'pages/plusGoods/plusGoods' => '/pages/product/plusGoods/plusGoods',
'pages/productList/productList' => '/pages/product/productList/productList',
'pages/promotion/promotion' => '/pages/product/promotion/promotion',
);
foreach ($list as &$value) {
$value['add_time'] = date('Y-m-d H:i:s', $value['add_time']);
$arr = explode('?', $value['path']);
$key = $arr[0];
if (!empty($newData[$key])) {
$value['diy_path'] = $newData[$key] . ($arr[1] ? ('?' . $arr[1]) : '');
}else{
$value['diy_path'] = $value['path'];
}
}
$count = $StoreXcxRouteModel->getCount($map);
$res['status'] = 1;
$res['count'] = $count;
$res['msg'] = empty($list) ? '暂无数据' : '获取成功';
$res['data'] = $list;
$this->ajaxReturn($res);
}
/**
* 修改状态
*/
public function changeRoute()
{
$id = I('post.id');
$status = I('post.status') == 1 ? 1 : 0;
$StoreXcxRouteModel = D('StoreXcxRoute');
$map = array(
'state' => 1,
'id' => $id,
'store_id' => $this->store_id,
);
$save = array(
'status' => $status,
);
$update = $StoreXcxRouteModel->updateOrder($map, $save);
if ($update) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
if ($status == 1) {
$desc = '商城地址库-开启地址库';//操作行为描述
} else {
$desc = '商城地址库-关闭地址库';//操作行为描述
}
action_log($source, $type, $request_data, $desc);
$res['status'] = 1;
$res['msg'] = $status == 1 ? '开启成功' : '关闭成功';
} else {
$res['status'] = 0;
$res['msg'] = $status == 1 ? '开启失败' : '关闭失败';
}
$this->ajaxReturn($res);
}
/**
* 删除记录
*/
public function delRoute()
{
$id = I('post.id');
$StoreXcxRouteModel = D('StoreXcxRoute');
$map = array(
'state' => 1,
'id' => $id,
'store_id' => $this->store_id,
);
$save = array(
'state' => 0,
'del_time' => time(),
);
$update = $StoreXcxRouteModel->updateOrder($map, $save);
if ($update) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$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 getSubCardList()
{
$page = I('post.page');
$limit = I('post.limit');
$keyword = I('post.keyword');
$type = I('post.type');//1次卡 2卡包
// 实例化模型
$CardModel = $type == 1 ? D('SubCard') : D('CardBag');
$time = time();
// 类型搜索
$map = array(
'type' => array('in', '4,5'),//门店购买
'merchantid' => $this->merchant_id,
'card_type' => $type,
'storeids' => array('like', array("{$this->store_id}", "{$this->store_id},%", "%,{$this->store_id},%", "%,{$this->store_id}", "0"), "OR"),
);
// 名称搜索
if (trim($keyword)) {
$map['name'] = array('like', '%' . trim($keyword) . '%');
}
$map['_string'] = "end_time > {$time} AND surplus > 0 AND status = 0";
// 统计总数
$count = $CardModel->total($map);
$subCardList = $CardModel->toSelect($map, $page, $limit, array('id', 'name', 'end_time', 'storeids', 'type'));
foreach ($subCardList as &$val) {
$val['end_time'] = date('Y-m-d H:i:s', $val['end_time']);
}
$res['status'] = 1;
$res['msg'] = empty($subCardList) ? '暂无数据' : '获取成功';
$res['data'] = $subCardList;
$res['count'] = (int)$count;
$this->ajaxReturn($res);
}
/**
* 获取一级分类列表
*/
public function getClass()
{
$page = I('post.page');
$limit = I('post.limit');
$keyword = I('post.keyword');
$ClassModel = D('RetailGoodsClass');
$map = array(
$ClassModel::MERCHANT_ID => $this->merchant_id,
$ClassModel::STATUS => 0,
$ClassModel::TYPE => 1,
);
if (!empty($keyword)) {
$map[$ClassModel::CLASS_NAME] = array('like', "%{$keyword}%");
}
$count = $ClassModel->getCount($map);
$list = $ClassModel->getSelect($map, array('id,class_name,code'), 'code asc', $page . ',' . $limit);
$res['status'] = 1;
$res['msg'] = empty($list) ? '暂无数据' : '获取成功';
$res['data'] = $list;
$res['count'] = $count;
$this->ajaxReturn($res);
}
/**
* 获取秒杀列表
*/
public function getSeckill()
{
$page = I('post.page');
$limit = I('post.limit');
$keyword = I('post.keyword');
$RetailSpikeViewModel = D('RetailSpikeView');
$time = time();
$map = array(
'end_time' => array('gt', $time),
'store_id' => $this->store_id,
'stock' => array('gt', 0),
'status' => 1,
);
if (!empty($keyword)) {
$map['RetailSpike.active_title|goods_name'] = array('like', "%{$keyword}%");
}
$fields = array(
'id',
'name',
'goods_name',
'start_time',
'end_time',
'stock',
);
$count = $RetailSpikeViewModel->getCount($map);
$list = $RetailSpikeViewModel->getSelect($map, $fields, $page, $limit);
foreach ($list as &$value) {
$value['time'] = date('Y-m-d H:i:s', $value['start_time']) . ' -- ' . date('Y-m-d H:i:s', $value['end_time']);
}
$res['status'] = 1;
$res['msg'] = empty($list) ? '暂无数据' : '获取成功';
$res['data'] = $list;
$res['count'] = intval($count);
$this->ajaxReturn($res);
}
/**
* 获取拼团列表
*/
public function getGroup()
{
$page = I('post.page');
$limit = I('post.limit');
$keyword = I('post.keyword');
$RetailSpikeViewModel = D('RetailGroupView');
$time = time();
$map = array(
'end_time' => array('gt', $time),
'store_id' => $this->store_id,
'act_num' => array('gt', 0),
'act_type' => 1,
);
if (!empty($keyword)) {
$map['RetailGroup.actname|goods_name'] = array('like', "%{$keyword}%");
}
$fields = array(
'id',
'act_name',
'goods_name',
'start_time',
'end_time',
'act_num',
);
$count = $RetailSpikeViewModel->getCount($map);
$list = $RetailSpikeViewModel->getSelect($map, $fields, $page, $limit);
foreach ($list as &$value) {
$value['time'] = date('Y-m-d H:i:s', $value['start_time']) . ' -- ' . date('Y-m-d H:i:s', $value['end_time']);
}
$res['status'] = 1;
$res['msg'] = empty($list) ? '暂无数据' : '获取成功';
$res['data'] = $list;
$res['count'] = intval($count);
$this->ajaxReturn($res);
}
/**
* 获取礼品卡列表
*/
public function getGift()
{
$page = I('post.page');
$limit = I('post.limit');
$keyword = I('post.keyword');
$RetailGiftCardModel = D('RetailGiftCard');
$time = time();
$map = array(
'start_time' => array('lt', $time),
'end_time' => array('gt', $time),
'merchantid' => $this->merchant_id,
'status' => 1,
'state' => 1,
);
if (!empty($keyword)) {
$map['title'] = array('like', "%{$keyword}%");
}
$fields = array(
'id',
'title',
'start_time',
'end_time',
);
$count = $RetailGiftCardModel->getCount($map);
$list = $RetailGiftCardModel->getSelect($map, $fields, 'id desc', $page . ',' . $limit);
foreach ($list as &$value) {
$value['time'] = date('Y-m-d H:i:s', $value['start_time']) . ' -- ' . date('Y-m-d H:i:s', $value['end_time']);
}
$res['status'] = 1;
$res['msg'] = empty($list) ? '暂无数据' : '获取成功';
$res['data'] = $list;
$res['count'] = $count;
$this->ajaxReturn($res);
}
//获取商品
public function getGoodsList()
{
$page = I('post.page');
$limit = I('post.limit');
$keyword = I('post.keyword');
//按照商品类别搜索
$person1 = I('post.person1');
$person2 = I('post.person2');
$person3 = I('post.person3');
if (!empty($keyword)) {
$keyword = trim($keyword);
$map['goods_number|goods_code|goods_name'] = array('like', '%' . $keyword . '%');
}
$flag = 0;
if (!empty($person3)) {
$map['goods_class_id'] = $person3;
} else if (!empty($person2)) {
$class = M('retail_goods_class as c2')
->join('ls_retail_goods_class as c3 on c2.id=c3.pid')
->where(array('c2.id' => $person2, 'c3.status' => 0))
->field('c3.id')->select();
$flag = 1;
} else if (!empty($person1)) {
$class = M('retail_goods_class as c1')
->join('ls_retail_goods_class as c2 on c1.id=c2.pid')
->join('ls_retail_goods_class as c3 on c2.id=c3.pid AND c3.status=0', 'LEFT')
->where(array('c1.id' => $person1, 'c2.status' => 0))
->field('c2.id,c3.id as c3_id')->select();
$flag = 1;
}
if (!empty($class)) {
$arr = array();
foreach ($class as &$val) {
if (!in_array($val['id'], $arr)) {
$arr[] = $val['id'];
}
if (!empty($val['c3_id'])) {
if (!in_array($val['c3_id'], $arr)) {
$arr[] = $val['c3_id'];
}
}
}
$str = implode(',', $arr);
$map['goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1));
} else if ($flag == 1) {
$map['goods_class_id'] = $person2 ? $person2 : $person1;
}
$map['status'] = 0;
$map['store_id'] = $this->store_id;
//商品列表
$goods = D('RetailGoods')->getSelect($map, 'id,goods_name,goods_code,goods_number,goods_img_id', "id desc", $page . ',' . $limit);
$goods_count = D('RetailGoods')->getCount($map);
foreach ($goods as $key => &$value) {
$value['goods_code'] = $value['goods_code'] ? $value['goods_code'] : '';
if ($value['goods_img_id']) {
$value['goods_img'] = D('ImageGallery')->getImagePath($value['goods_img_id']);
} else {
$value['goods_img'] = '';
}
$value['goods_number'] = $value['goods_number'] ? $value['goods_number'] : '';
$value['goods_num'] = A('Api/Inventory')->goods_num(2, $this->store_id, $value['id']);
}
$res['status'] = 1;
$res['msg'] = '获取成功';
$res['count'] = $goods_count;
$res['data'] = $goods;
$this->ajaxReturn($res);
}
/**
* 添加小程序地址
*/
public function addRoute()
{
$name = I('post.name');
$path = I('post.path');
$type_name = I('post.type_name');
if (empty($name) || empty($path) || empty($type_name)) {
$res['status'] = 0;
$res['msg'] = '请完善请求参数';
$this->ajaxReturn($res);
}
$addItem = array(
'name' => $name,
'path' => $path,
'type_name' => $type_name,
'add_time' => time(),
'status' => 1,
'state' => 1,
'store_id' => $this->store_id,
);
$add = D('StoreXcxRoute')->addOrder($addItem);
if ($add) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$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);
}
}