1373 行
54 KiB
PHP
可执行文件
1373 行
54 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Retail\Controller;
|
||
|
||
use Common\Model\DeliveryTemplateModel;
|
||
use Common\Model\ImageGalleryModel;
|
||
use Common\Model\RetailBillOrderModel;
|
||
use Common\Model\RetailBillSpikeModel;
|
||
use Common\Model\RetailGoodsModel;
|
||
use Common\Model\RetailPayOrderModel;
|
||
use Common\Model\RetailSkuGoodsModel;
|
||
use Common\Model\RetailSkuListModel;
|
||
use Common\Model\RetailSpikeModel;
|
||
use Common\Model\RetailSpikeOrderViewModel;
|
||
use Common\Model\RetailSpikeViewModel;
|
||
use Common\Model\RetailStoreModel;
|
||
use Common\Model\RetailStoreXcxConfigModel;
|
||
use Common\Model\RetailVipModel;
|
||
use LittleGift\Business\Goods;
|
||
use LittleGift\Business\Order;
|
||
use PayApi\Controller\ActivityOrderController;
|
||
use PayApi\Controller\RefundController;
|
||
use Think\Controller;
|
||
use Common\Business\Plug;
|
||
|
||
//[1.8.68]
|
||
|
||
/**
|
||
* 门店秒杀管理
|
||
* Class SecKillController
|
||
* @package Retail\Controller
|
||
*/
|
||
class SecKillController extends BaseController
|
||
{
|
||
public function index()
|
||
{
|
||
if (IS_POST) {
|
||
$StoreXcxConfigModel = new RetailStoreXcxConfigModel();
|
||
$map = array(
|
||
'storeid' => $this->store_id
|
||
);
|
||
$conf = $StoreXcxConfigModel->getFind($map, 'seckill_status,home_seckill_status,xcx_seckill_cover_id');
|
||
if (empty($conf['seckill_status'])) {
|
||
$conf['seckill_status'] = '2';
|
||
$conf['home_seckill_status'] = '2';
|
||
$conf['xcx_seckill_cover_id'] = '';
|
||
$conf['xcx_seckill_cover'] = '';
|
||
} else {
|
||
//秒杀封面图
|
||
$ImageGalleryModel = new ImageGalleryModel();
|
||
$conf['xcx_seckill_cover'] = $ImageGalleryModel->getOneField(array('id' => $conf['xcx_seckill_cover_id']), 'path');
|
||
}
|
||
$this->ajaxReturn([
|
||
'status' => 1,
|
||
'msg' => '获取成功',
|
||
'data' => $conf
|
||
]);
|
||
} else {
|
||
$this->display();
|
||
}
|
||
}
|
||
|
||
// 活动信息页面
|
||
public function getData()
|
||
{
|
||
$platform_type = $this->role_info['platform_type'];
|
||
$type = I('post.type');//活动状态
|
||
$page = I('post.page');//页
|
||
$limit = I('post.limit');//每页数量
|
||
$time = time();
|
||
|
||
switch ($type) {
|
||
case '1':
|
||
//全部
|
||
$map['status'] = array('in', array(1, 2));//不含已删除
|
||
break;
|
||
case '2':
|
||
//未开始
|
||
$map['start_time'] = array('gt', $time);
|
||
$map['status'] = 1;
|
||
break;
|
||
case '3':
|
||
//进行中
|
||
$map['start_time'] = array('elt', $time);
|
||
$map['end_time'] = array('egt', $time);
|
||
$map['status'] = 1;
|
||
break;
|
||
case '4':
|
||
//已结束
|
||
$map['end_time'] = array('lt', $time);
|
||
$map['status'] = 1;
|
||
break;
|
||
case '5':
|
||
//已失效
|
||
$map['status'] = 2;
|
||
break;
|
||
default:
|
||
//全部
|
||
$map['status'] = array('in', array(1, 2));
|
||
break;
|
||
}
|
||
|
||
if (I('post.keyword')) {
|
||
$keyword = I('post.keyword');
|
||
$keyword_type = I('post.keyword_type');
|
||
switch ($keyword_type) {
|
||
case '1':
|
||
//活动名称
|
||
$key_name = 'name';
|
||
break;
|
||
case '2':
|
||
//商品名称
|
||
$key_name = 'goods_name';
|
||
break;
|
||
case '3':
|
||
//商品条码
|
||
$key_name = 'goods_code';
|
||
break;
|
||
case '4':
|
||
//商品货号
|
||
$key_name = 'goods_number';
|
||
break;
|
||
default:
|
||
$key_name = 'name';
|
||
}
|
||
$map[$key_name] = array('like', "%" . $keyword . "%");
|
||
}
|
||
$map['store_id'] = $this->store_id;
|
||
$map['goods_status'] = 0;
|
||
|
||
$fields = [
|
||
'id',
|
||
'gid',
|
||
'sku_id',
|
||
'goods_name',
|
||
'goods_code',
|
||
'goods_number',
|
||
'name',
|
||
'sell_number',
|
||
'start_time',
|
||
'end_time',
|
||
'stock',
|
||
'status',
|
||
'third_goods_code'
|
||
];
|
||
$RSViewModel = new RetailSpikeViewModel();
|
||
$list = $RSViewModel->getSelect($map, $fields, $page, $limit, 'id desc');
|
||
$InventoryApi = new \Api\Controller\InventoryController();
|
||
$count = 0;
|
||
if ($list) {
|
||
$count = $RSViewModel->getCount($map);
|
||
if ($platform_type == 2) {
|
||
//第三方平台
|
||
$SkuGoodsModel = new RetailSkuGoodsModel();
|
||
$code_arr = [];
|
||
}
|
||
foreach ($list as &$val) {
|
||
$val['act_time'] = date('Y-m-d H:i:s', $val['start_time']) . '至' . date('Y-m-d H:i:s', $val['end_time']);
|
||
if ($val['status'] == 2) {
|
||
$val['status_name'] = '已失效';
|
||
$val['state'] = 4;
|
||
} else if ($val['status'] == 1 && $val['start_time'] > $time) {
|
||
$val['status_name'] = '未开始';
|
||
$val['state'] = 1;
|
||
} else if ($val['status'] == 1 && $val['start_time'] <= $time && $val['end_time'] >= $time) {
|
||
$val['status_name'] = '进行中';
|
||
$val['state'] = 2;
|
||
} else if ($val['status'] == 1 && $val['end_time'] < $time) {
|
||
$val['status_name'] = '已结束';
|
||
$val['state'] = 4;
|
||
}
|
||
if ($val['state'] == 1 || $val['state'] == 2) {
|
||
if ($platform_type == 2) {
|
||
if (!empty($val['sku_id'])) {
|
||
$code_arr[$val['gid'] . '_' . $val['sku_id']] = $SkuGoodsModel->getFindField([
|
||
'id' => $val['sku_id']
|
||
], 'third_goods_code');
|
||
} else {
|
||
$code_arr[$val['gid']] = $val['third_goods_code'];
|
||
}
|
||
$val['goods_num'] = 0;
|
||
} else {
|
||
$val['goods_num'] = $InventoryApi->goods_num(2, $this->store_id, $val['gid'], $val['sku_id']);
|
||
}
|
||
}
|
||
}
|
||
if ($platform_type == 2 && !empty($code_arr)) {
|
||
$ThirdGoodsClass = new Goods();
|
||
$thirdResult = $ThirdGoodsClass->storeCode($this->store_id);
|
||
if (!empty($thirdResult['data'])) {
|
||
$thirdResult = $ThirdGoodsClass->goodsNumQuery([
|
||
'merchant_id' => $this->merchant_id,
|
||
'code_arr' => $code_arr,
|
||
'type' => 2,
|
||
'Customer_Codes' => $thirdResult['data'],
|
||
]);
|
||
if ($thirdResult['status'] == 1 && !empty($thirdResult['data'])) {
|
||
$goods_stock = $thirdResult['data'];
|
||
foreach ($list as &$val) {
|
||
if (!empty($val['sku_id'])) {
|
||
$val['goods_num'] = $goods_stock[$val['gid'] . '_' . $val['sku_id']] ? $goods_stock[$val['gid'] . '_' . $val['sku_id']] : 0;
|
||
} else {
|
||
$val['goods_num'] = $goods_stock[$val['gid']] ? $goods_stock[$val['gid']] : 0;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
$res['status'] = 1;
|
||
$res['msg'] = $list ? '获取成功' : '暂无数据';
|
||
$res['data'] = $list;
|
||
$res['count'] = $count;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 更改秒杀库存
|
||
* @param id 活动id
|
||
* @param type 操作类型 1增加 2减少
|
||
* @param operate_num 操作数量
|
||
*/
|
||
public function updateSpikeInventory()
|
||
{
|
||
$platform_type = $this->role_info['platform_type'];
|
||
$RetailSpikeModel = new RetailSpikeModel();
|
||
$Inventory = new \Api\Controller\InventoryController();
|
||
$id = I('post.id');
|
||
$type = I('post.type');
|
||
$operateNum = I('post.operate_num');
|
||
if (!$id) {
|
||
$this->ajaxReturn(['status' => 0, 'msg' => '必要参数缺失']);
|
||
}
|
||
if (!verifyNumber($operateNum)) {
|
||
$this->ajaxReturn(['status' => 0, 'msg' => '请输入正确的数量']);
|
||
}
|
||
|
||
$where['id'] = $id;
|
||
$spikeInfo = $RetailSpikeModel->getFind($where);
|
||
if (!$spikeInfo) {
|
||
$this->ajaxReturn(['status' => 0, 'msg' => '数据有误,请刷新重试']);
|
||
}
|
||
|
||
if ($type == 1) {
|
||
// 库存验证
|
||
if ($platform_type != 2) {
|
||
$saleGoodsNum = $Inventory->goods_num(2, $this->store_id, $spikeInfo['gid'], $spikeInfo['skuid']);
|
||
if ($operateNum > $saleGoodsNum) {
|
||
$this->ajaxReturn(['status' => 0, 'msg' => '商品库存不足']);
|
||
}
|
||
}
|
||
$result = $RetailSpikeModel->toSetInc(['id' => $id], 'active_limit_num', $operateNum);
|
||
} else {
|
||
//验证剩余秒杀数量是否足够
|
||
if (0 > bcsub($spikeInfo['active_limit_num'], $operateNum)) {
|
||
$this->ajaxReturn(['status' => 0, 'msg' => '秒杀商品活动库存不足']);
|
||
}
|
||
$result = $RetailSpikeModel->toSetDec(['id' => $id], 'active_limit_num', $operateNum);
|
||
}
|
||
|
||
if ($result) {
|
||
if ($operateNum > 0) {
|
||
if ($type == 1) {
|
||
// 秒杀库存增加商品库存减少
|
||
A('Api/Inventory')->Inventory(2, $operateNum, $spikeInfo['gid'], $spikeInfo['skuid']);
|
||
} else {
|
||
// 秒杀库存减少商品库存增加
|
||
A('Api/Inventory')->Inventory(1, $operateNum, $spikeInfo['gid'], $spikeInfo['skuid']);
|
||
}
|
||
}
|
||
$res = ['status' => 1, 'msg' => '数据更新成功'];
|
||
} else {
|
||
$res = ['status' => 0, 'msg' => '操作失败,请稍后'];
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
// 添加封面操作
|
||
public function add_seckill_cover()
|
||
{
|
||
$cover_id = I('post.cover_id');
|
||
if (!$cover_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '未选择图片';
|
||
} else {
|
||
$StoreXcxConfigModel = new RetailStoreXcxConfigModel();
|
||
$map = array(
|
||
'storeid' => $this->store_id,
|
||
);
|
||
$save = $StoreXcxConfigModel->updateOrder($map, array('xcx_seckill_cover_id' => $cover_id));
|
||
if ($save) {
|
||
//操作日志记录
|
||
$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'] = 2;
|
||
$res['msg'] = '设置失败';
|
||
}
|
||
}
|
||
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
// 设置秒杀详情
|
||
public function createSeckill()
|
||
{
|
||
$DeliveryTemplateModel = new DeliveryTemplateModel();
|
||
$where = array(
|
||
'store_id' => $this->store_id,
|
||
'status' => 1,
|
||
'state' => 1,
|
||
);
|
||
$delivery_template = $DeliveryTemplateModel->getSelect($where, "id,title");
|
||
$this->assign('delivery_template', $delivery_template);
|
||
$this->display();
|
||
}
|
||
|
||
// 选择秒杀商品
|
||
public function chooseGoods()
|
||
{
|
||
$this->display();
|
||
}
|
||
|
||
// 商品秒杀列表
|
||
public function addSeckill()
|
||
{
|
||
$platform_type = $this->role_info['platform_type'] ? $this->role_info['platform_type'] : 1;//商户平台类型 1默认系统 2微礼平台
|
||
$page = I('post.page') ? I('post.page') : 1;
|
||
$limit = I('post.limit') ? I('post.limit') : 1;
|
||
$map = array(
|
||
'store_id' => $this->store_id,
|
||
'merchant_id' => $this->merchant_id,
|
||
'status' => 0,
|
||
'online_state' => 1,
|
||
'advance_sale_status' => 0,
|
||
);
|
||
//接收查询条件
|
||
if (I('post.keyword')) {
|
||
$keyword = I('post.keyword');
|
||
$map[] = array(
|
||
'goods_name' => array('like', '%' . trim($keyword) . '%'),
|
||
'goods_number|goods_code' => trim($keyword),
|
||
'_logic' => 'OR',
|
||
);
|
||
}
|
||
//商品列表
|
||
$GoodsModel = new RetailGoodsModel();
|
||
$goods = $GoodsModel->getSelect($map, '*', 'id asc', "{$page},{$limit}");
|
||
$count = $GoodsModel->getCount($map);
|
||
$ImageGalleryModel = new ImageGalleryModel();
|
||
$Inventory = new \Api\Controller\InventoryController();
|
||
if ($platform_type == 2) {
|
||
//第三方平台
|
||
$code_arr = [];
|
||
}
|
||
foreach ($goods as &$val) {
|
||
$val['goods_img_id'] = $ImageGalleryModel->getOneField(array('id' => $val['goods_img_id']), 'path');
|
||
if ($platform_type == 2) {
|
||
if ($val['attribute_state'] == 1) {
|
||
$val['goods_num'] = 0;
|
||
$code_arr[$val['id']] = $val['third_goods_code'];
|
||
} else {
|
||
$val['goods_num'] = '规格库存';
|
||
}
|
||
} else {
|
||
$val['goods_num'] = $Inventory->goods_num(2, $this->store_id, $val['id']);
|
||
}
|
||
}
|
||
if ($platform_type == 2 && !empty($code_arr)) {
|
||
//第三方平台
|
||
$ThirdGoodsClass = new Goods();
|
||
$storeResult = $ThirdGoodsClass->storeCode($this->store_id);
|
||
$Customer_Codes = $storeResult['data'];
|
||
if (!empty($Customer_Codes)) {
|
||
$thirdResult = $ThirdGoodsClass->goodsNumQuery([
|
||
'merchant_id' => $this->merchant_id,
|
||
'type' => 2,
|
||
'code_arr' => $code_arr,
|
||
'Customer_Codes' => $Customer_Codes
|
||
]);
|
||
if ($thirdResult['status'] == 1 && !empty($thirdResult['data'])) {
|
||
$goods_stock = $thirdResult['data'];
|
||
foreach ($goods as &$val) {
|
||
if ($val['attribute_state'] == 1 && !empty($goods_stock[$val['id']])) {
|
||
$val['goods_num'] = $goods_stock[$val['id']];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
$res['code'] = 0;
|
||
$res['msg'] = '';
|
||
$res['count'] = $count;
|
||
$res['data'] = $goods;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
// 添加活动
|
||
public function add()
|
||
{
|
||
$goods_data = I('post.');
|
||
$gid = I('post.gid');
|
||
$sku_id = I('post.skuid');
|
||
$active_limit_num = I('post.active_limit_num');
|
||
if (!empty($goods_data) && !empty($gid) && !empty($active_limit_num)) {
|
||
// 秒杀商品 出库明细
|
||
$GoodsModel = new RetailGoodsModel();
|
||
$SkuGoodsModel = new RetailSkuGoodsModel();
|
||
$goods = $GoodsModel->getFind(array('id' => $gid));
|
||
if (!empty($goods)) {
|
||
$Inventory = new \Api\Controller\InventoryController();
|
||
// 减库存
|
||
if ($sku_id != 0) { // 规格商品
|
||
$sMap = array(
|
||
'id' => $sku_id,
|
||
'goods_id' => $gid,
|
||
);
|
||
$goods_sku_find = $SkuGoodsModel->getFind($sMap);
|
||
if (!$goods_sku_find) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '规格查询失败';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$goods_sku_num = $Inventory->Inventory(2, $active_limit_num, $gid, $sku_id);
|
||
if (!$goods_sku_num) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = 'sku规格库存未修改';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
} else { // 非规格商品
|
||
$goods_num1 = $Inventory->Inventory(2, $active_limit_num, $gid);
|
||
if (!$goods_num1) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品库存未修改';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
// 添加活动
|
||
$data = array(
|
||
'gid' => $gid,
|
||
'skuid' => $sku_id,
|
||
'storeid' => $this->store_id,
|
||
'active_limit_num' => $active_limit_num,
|
||
'goods_seckill_price' => $goods_data['goods_seckill_price'],
|
||
'active_starttime' => strtotime($goods_data['active_starttime']),
|
||
'active_endtime' => strtotime($goods_data['active_endtime']),
|
||
'active_title' => $goods_data['active_title'],
|
||
'active_personal_limit_num' => $goods_data['active_personal_limit_num'] ? $goods_data['active_personal_limit_num'] : 0,
|
||
'rise_num' => $goods_data['rise_num'] ? $goods_data['rise_num'] : 0, //起购数量
|
||
'addtime' => time(),
|
||
'send_type' => $goods_data['send_type'],
|
||
'delivery_template_id' => $goods_data['delivery_template_id'],
|
||
);
|
||
$SpikeModel = new RetailSpikeModel();
|
||
$list = $SpikeModel->addOrder($data);
|
||
if (!empty($list)) {
|
||
//操作日志记录
|
||
$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'] = '活动设置失败';
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品查询失败';
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数不全';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//查看信息
|
||
public function see($id)
|
||
{
|
||
if (!empty($id)) {
|
||
$SpikeViewModel = new RetailSpikeViewModel();
|
||
$map = array(
|
||
'RetailSpike.id' => $id
|
||
);
|
||
$fields = array(
|
||
'RetailSpike.*',
|
||
'RetailGoods.goods_img_id'
|
||
);
|
||
$seckill_res = $SpikeViewModel->getFind($map, $fields);
|
||
if (!empty($seckill_res)) {
|
||
$seckill_res['active_starttime'] = date('Y-m-d H:i:s', $seckill_res['active_starttime']);
|
||
$seckill_res['active_endtime'] = date('Y-m-d H:i:s', $seckill_res['active_endtime']);
|
||
$seckill_res['rise_num'] = $seckill_res['rise_num'] ? floatval($seckill_res['rise_num']) : '';
|
||
$seckill_res['goods_img'] = getImage($seckill_res['goods_img_id']);
|
||
$this->assign('seckill_res', $seckill_res);
|
||
$this->display();
|
||
}
|
||
}
|
||
}
|
||
|
||
// 取消活动
|
||
public function ban_v1()
|
||
{
|
||
$id = I('post.id');
|
||
if (!$id) {
|
||
$res = array('status' => 0, 'msg' => '参数缺失');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 查询活动
|
||
$SpikeModel = new RetailSpikeModel();
|
||
$map = array(
|
||
'id' => $id,
|
||
'storeid' => $this->store_id,
|
||
);
|
||
$spike_res = $SpikeModel->getFind($map);
|
||
if (!$spike_res) {
|
||
$res = array('status' => 0, 'msg' => '活动查询失败,请刷新重试');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$save_res = $SpikeModel->updateOrder($map, array('active_status' => 2));
|
||
if ($save_res) {
|
||
//操作日志记录
|
||
$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 = array('status' => 1, 'msg' => '你已经成功取消活动');
|
||
} else {
|
||
$res = array('status' => 0, 'msg' => '活动取消失败');
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//恢复库存
|
||
public function recovery()
|
||
{
|
||
// 接受数据
|
||
$id = I('post.id');
|
||
if (!$id) {
|
||
$res = array('status' => 0, 'msg' => '参数缺失');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 查询活动
|
||
$RSViewModel = new RetailSpikeViewModel();
|
||
$spike_res = $RSViewModel->getFind(array('id' => $id, 'storeid' => $this->store_id));
|
||
if (!$spike_res) {
|
||
$res = array('status' => 0, 'msg' => '活动查询失败,请刷新重试');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 查询订单
|
||
$RBOModel = new RetailBillOrderModel();
|
||
$map = array(
|
||
'b.' . $RBOModel::STORE_ID => $this->store_id,
|
||
'b.' . $RBOModel::MERCHANT_ID => $this->merchant_id,
|
||
'b.' . $RBOModel::PAY_STATE => 1,
|
||
'b.' . $RBOModel::TYPE => 1,
|
||
'b.' . $RBOModel::REFUND_STATUS => array('not in', array(0, 1, 2)),
|
||
'o.status' => 1,
|
||
'o.order_genre' => 3,
|
||
's.state' => 0,
|
||
's.spike_id' => $id
|
||
);
|
||
$select = $RBOModel->getSelectSpike($map);
|
||
if ($select) {
|
||
$res = array('status' => 0, 'msg' => '请先处理订单');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
if (!$spike_res['stock'] || $spike_res['stock'] <= 0) {
|
||
$res = array('status' => 0, '活动已经售出完毕,无需恢复');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 判断规格
|
||
$Inventory = new \Api\Controller\InventoryController();
|
||
if ($spike_res['sku_id'] && $spike_res['sku_id'] != 0) {
|
||
// 查询规格
|
||
$sMap = array(
|
||
'id' => $spike_res['sku_id'],
|
||
'goods_id' => $spike_res['gid'],
|
||
);
|
||
$SkuGoodsModel = new RetailSkuGoodsModel();
|
||
$sku = $SkuGoodsModel->getFind($sMap);
|
||
if ($sku) {
|
||
// 规格加库存
|
||
$sku_res = $Inventory->Inventory(1, $spike_res['stock'], $spike_res['gid'], $spike_res['sku_id']);
|
||
if (!$sku_res) {
|
||
$res = array('status' => 0, 'msg' => '规格库存出现异常,恢复失败');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
} else {
|
||
// 商品恢复库存
|
||
$goods_res = $Inventory->Inventory(1, $spike_res['stock'], $spike_res['gid']);
|
||
if (!$goods_res) {
|
||
$res = array('status' => 0, 'msg' => '商品库存出现异常,恢复失败');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
// 请空库存
|
||
$SpikeModel = new RetailSpikeModel();
|
||
$act_res = $SpikeModel->updateOrder(array('id' => $id), array('active_limit_num' => 0));
|
||
if (!$act_res) {
|
||
$res = array('status' => 0, 'msg' => '库存清空失败');
|
||
} else {
|
||
//操作日志记录
|
||
$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 = array('status' => 1, 'msg' => '库存已成功恢复至商品档案');
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
// 删除
|
||
public function delete()
|
||
{
|
||
// 接受参数
|
||
$id = I('post.id');
|
||
if (!$id) {
|
||
$res = array('status' => 0, 'msg' => '参数缺失');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 删除活动
|
||
$SpikeModel = new RetailSpikeModel();
|
||
$del_res = $SpikeModel->updateOrder(array('id' => $id), array('active_status' => 3));
|
||
if ($del_res) {
|
||
//操作日志记录
|
||
$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 = array('status' => 1, 'msg' => '删除成功');
|
||
} else {
|
||
$res = array('status' => 0, 'msg' => '删除失败');
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
|
||
/**
|
||
* 秒杀订单,加载页面
|
||
*/
|
||
public function order()
|
||
{
|
||
$this->display();
|
||
}
|
||
|
||
//规格
|
||
public function getsku()
|
||
{
|
||
$platform_type = $this->role_info['platform_type'];
|
||
$goods_id = I('post.goods_id');
|
||
if (!$goods_id) {
|
||
$res = array(
|
||
'code' => 0,
|
||
'data' => array(),
|
||
'msg' => '缺少参数'
|
||
);
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$page = I('post.page');
|
||
$limit = I('post.limit');
|
||
// 实例化模型
|
||
$RSGModel = new RetailSkuGoodsModel();
|
||
$map = array(
|
||
$RSGModel::STORE_ID => $this->store_id,
|
||
$RSGModel::STATUS => 1,
|
||
$RSGModel::STATE => 0,
|
||
$RSGModel::GOODS_ID => $goods_id
|
||
);
|
||
$sku_info = $RSGModel->getSelect($map, '*', 'id asc', $page . ',' . $limit);
|
||
$count = $RSGModel->getCount($map);
|
||
if (!$sku_info) {
|
||
$res = array(
|
||
'code' => 0,
|
||
'data' => array(),
|
||
'msg' => '暂无数据'
|
||
);
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$RSLModel = new RetailSkuListModel();
|
||
$Inventory = new \Api\Controller\InventoryController();
|
||
if ($platform_type == 2) {
|
||
//第三方
|
||
$code_arr = [];
|
||
}
|
||
foreach ($sku_info as &$val) {
|
||
if ($platform_type == 2) {
|
||
$code_arr[$val['id']] = $val['third_goods_code'];
|
||
$val['goods_num'] = 0;
|
||
} else {
|
||
$val['goods_num'] = $Inventory->goods_num(1, $this->store_id, $goods_id, $val['id']);
|
||
}
|
||
// 规格名称
|
||
$sku_name = $RSLModel->getFindField(array($RSLModel::ID => array('in', $val['sku_id_list'])), $RSLModel::NAME, true);
|
||
$val['sku'] = implode(',', $sku_name);
|
||
// 规格图片
|
||
$val['goods_img'] = getImage($val['goods_img_id']);
|
||
}
|
||
if (!empty($code_arr) && $platform_type == 2) {
|
||
$ThirdGoodsClass = new Goods();
|
||
$storeResult = $ThirdGoodsClass->storeCode($this->store_id);
|
||
$third_goods_code = $storeResult['data'];
|
||
if (!empty($third_goods_code)) {
|
||
$thirdResult = $ThirdGoodsClass->goodsNumQuery([
|
||
'merchant_id' => $this->merchant_id,
|
||
'type' => 2,
|
||
'code_arr' => $code_arr,
|
||
'Customer_Codes' => $third_goods_code
|
||
]);
|
||
if ($thirdResult['status'] == 1 && !empty($thirdResult['data'])) {
|
||
$goods_stock = $thirdResult['data'];
|
||
foreach ($sku_info as &$val) {
|
||
if (!empty($goods_stock[$val['id']])) {
|
||
$val['goods_num'] = $goods_stock[$val['id']];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
$res = array(
|
||
'code' => 0,
|
||
'data' => $sku_info,
|
||
'count' => $count,
|
||
'msg' => '暂无数据'
|
||
);
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
*秒杀订单导出
|
||
*/
|
||
public function secKillExport()
|
||
{
|
||
$RSOViewModel = new RetailSpikeOrderViewModel();
|
||
$map = array(
|
||
'RetailBillOrder.pay_state' => 1,
|
||
'RetailBillOrder.store_id' => $this->store_id,
|
||
'RetailBillOrder.type' => 1,
|
||
'RetailBillOnline.order_genre' => 3,
|
||
'RetailBillOrder.order_type' => 1
|
||
);
|
||
// 接受数据
|
||
$order_no = I('get.out_trade_no'); // 订单搜索
|
||
if ($order_no) {
|
||
$map['RetailBillOrder.order_no'] = array('like', "%" . $order_no);
|
||
}
|
||
$state = I('get.secKillStatus'); // 秒杀状态 0.失败 1.成功 2.所有
|
||
switch ($state) {
|
||
case '0':
|
||
$map['RetailBillSpike.state'] = 0;
|
||
break;
|
||
case '1':
|
||
$map['RetailBillSpike.state'] = 1;
|
||
break;
|
||
case '2':
|
||
$map['RetailBillSpike.state'] = array('in', array('0', '1'));
|
||
break;
|
||
default:
|
||
$map['RetailBillSpike.state'] = array('in', array('0', '1'));
|
||
break;
|
||
}
|
||
$date = I('get.time');
|
||
if ($date) {
|
||
$date = explode(',', $date);
|
||
$start_date = strtotime($date[0]);
|
||
$end_date = strtotime($date[1]);
|
||
$map['RetailBillOrder.add_time'] = array("between", array($start_date, $end_date));
|
||
}
|
||
$field = array(
|
||
'id', 'all_money', 'pay_type', 'refund_status', 'order_type', 'finish_time', 'vid', 'uid', 'order_no', 'status', 'pickup_type', 'user_name', 'user_phone',
|
||
'user_address', 'state', 'buy_number', 'remind_state', 'remark', 'add_time','pay_coupon_fee'
|
||
);
|
||
$order_list = $RSOViewModel->getSelect($map, $field);
|
||
if ($order_list) {
|
||
$RVModel = new RetailVipModel();
|
||
$RetailPayOrderModel = new RetailPayOrderModel();
|
||
foreach ($order_list as $key => &$val) {
|
||
$val['index'] = $key + 1;
|
||
$val['out_trade_no'] = $RetailPayOrderModel->getFindField(array('bill_id' => $val['id']), "out_trade_no");
|
||
if ($val['vid']) {
|
||
$vip_name = $RVModel->getFindField(array($RVModel::ID => $val['vid']), $RVModel::NAME);
|
||
$val['vip_name'] = $vip_name ? $vip_name : '未设置';
|
||
} else {
|
||
$val['vip_name'] = '非会员';
|
||
}
|
||
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
|
||
$val['pickup_name'] = $val['pickup_type'] == 1 ? '自提' : '配送';
|
||
switch ($val['status']) {
|
||
case 1:
|
||
$val['status_name'] = '未发货';
|
||
break;
|
||
case 2:
|
||
$val['status_name'] = '未收货';
|
||
break;
|
||
case 3:
|
||
$val['status_name'] = '交易完成';
|
||
break;
|
||
default:
|
||
$val['status_name'] = '未知类型';
|
||
}
|
||
if ($val['state'] == 1) {
|
||
$val['state_name'] = '秒杀成功';
|
||
} else {
|
||
$val['state_name'] = '秒杀失败';
|
||
}
|
||
$val['remind_name'] = $val['remind_state'] == 1 ? '是' : '否';
|
||
$val['order_name'] = $val['order_type'] == 1 ? '购买' : '退款';
|
||
$val['pay_coupon_fee'] = $val['pay_coupon_fee']>0?floatval($val['pay_coupon_fee']):'';
|
||
}
|
||
} else {
|
||
$order_list = array();
|
||
}
|
||
|
||
$filename = "秒杀订单列表";
|
||
$arr = array(
|
||
array('index', '序号'),
|
||
array('order_no', '门店订单号'),
|
||
array('out_trade_no', '内部订单号'),
|
||
array('order_name', '订单类型'),
|
||
array('vip_name', '会员'),
|
||
array('all_money', '支付金额'),
|
||
array('pay_coupon_fee', '代金券优惠金额'),
|
||
array('add_time', '下单时间'),
|
||
array('pickup_name', '自提/配送'),
|
||
array('user_name', '姓名'),
|
||
array('user_phone', '手机'),
|
||
array('user_address', '地址'),
|
||
array('status_name', '发货状态'),
|
||
array('state_name', '拼团状态'),
|
||
array('remind_name', '提醒发货'),
|
||
array('remark', '买家留言'),
|
||
);
|
||
$str = "导出时间" . date('Y-m-d H:i:s', time());
|
||
getExcel($filename, $arr, $order_list, $str);
|
||
}
|
||
|
||
//获取订单列表
|
||
public function getOrdertwo()
|
||
{
|
||
$RSOViewModel = new RetailSpikeOrderViewModel();
|
||
$map = array(
|
||
'RetailBillOrder.pay_state' => 1,
|
||
'RetailBillOrder.store_id' => $this->store_id,
|
||
'RetailBillOrder.type' => 1,
|
||
'RetailBillOnline.order_genre' => 3,
|
||
'RetailBillOrder.order_type' => 1,
|
||
);
|
||
// 接受数据
|
||
$order_no = I('post.out_trade_no'); // 订单搜索
|
||
if ($order_no) {
|
||
$map['RetailBillOrder.order_no'] = array('like', "%" . $order_no);
|
||
}
|
||
$state = I('post.secKillStatus'); // 秒杀状态 0.失败 1.成功 2.所有
|
||
switch ($state) {
|
||
case '0':
|
||
$map['RetailBillSpike.state'] = 0;
|
||
break;
|
||
case '1':
|
||
$map['RetailBillSpike.state'] = 1;
|
||
break;
|
||
case '2':
|
||
$map['RetailBillSpike.state'] = array('in', array('0', '1'));
|
||
break;
|
||
default:
|
||
$map['RetailBillSpike.state'] = array('in', array('0', '1'));
|
||
break;
|
||
}
|
||
$date = I('post.time');
|
||
if ($date) {
|
||
$start_date = strtotime($date[0]);
|
||
$end_date = strtotime($date[1]);
|
||
$map['RetailBillOrder.add_time'] = array("between", array($start_date, $end_date));
|
||
}
|
||
|
||
$postOne = I('post.');
|
||
if (isset($postOne['status']) && $postOne['status'] !== '') {
|
||
//ls_retail_bill_online -> status 1未发货 2已发货 3已收货 (自提没有类型2)
|
||
if ($postOne['status'] == 4) {
|
||
//待自提
|
||
$map['RetailBillOnline.pickup_type'] = 1;
|
||
$map['RetailBillOnline.status'] = 1;
|
||
} else if ($postOne['status'] == 5) {
|
||
//已自提
|
||
$map['RetailBillOnline.pickup_type'] = 1;
|
||
$map['RetailBillOnline.status'] = 3;
|
||
} else {
|
||
$map['RetailBillOnline.pickup_type'] = array('in', '2,3');
|
||
$map['RetailBillOnline.status'] = $postOne['status'];
|
||
}
|
||
}
|
||
if (isset($postOne['pickupType']) && $postOne['pickupType'] !== '') {
|
||
//ls_retail_bill_online -> pickup_type 是否需要配送 1:自提 2:配送 3快递发货
|
||
$map['RetailBillOnline.pickup_type'] = $postOne['pickupType'];
|
||
}
|
||
|
||
$field = array(
|
||
'id',
|
||
'all_money',
|
||
'pay_type',
|
||
'refund_status',
|
||
'order_type',
|
||
'finish_time',
|
||
'vid',
|
||
'uid',
|
||
'order_no',
|
||
'status',
|
||
'pickup_type',
|
||
'user_name',
|
||
'user_phone',
|
||
'user_address',
|
||
'state',
|
||
'buy_number',
|
||
'remind_state',
|
||
'remark',
|
||
'add_time',
|
||
'delivery_type',
|
||
'user_select_time',
|
||
'pay_coupon_fee'
|
||
);
|
||
|
||
$order_list = $RSOViewModel->getSelect($map, $field, (int)$_POST['page'], (int)$_POST['limit']);
|
||
if ($order_list) {
|
||
|
||
$whereRoutine = array(
|
||
'RetailBillOrder.pay_state' => 1,
|
||
'RetailBillOrder.store_id' => $this->store_id,
|
||
'RetailBillOrder.type' => 1,
|
||
'RetailBillOnline.order_genre' => 3,
|
||
'RetailBillOrder.order_type' => 1,
|
||
'RetailBillOnline.status' => 1,
|
||
);
|
||
//待,数量,秒杀订单
|
||
$whereOne = [
|
||
'RetailBillOnline.pickup_type' => 1,
|
||
$whereRoutine,
|
||
];
|
||
$whereTwo = [
|
||
'RetailBillOnline.pickup_type' => 2,
|
||
$whereRoutine,
|
||
];
|
||
$whereThree = [
|
||
'RetailBillOnline.pickup_type' => 3,
|
||
$whereRoutine,
|
||
];
|
||
$pickup_type_one = $RSOViewModel->getCount($whereOne); //待自提数量
|
||
$pickup_type_two = $RSOViewModel->getCount($whereTwo); //待配送订单数量
|
||
$pickup_type_three = $RSOViewModel->getCount($whereThree); //待发货订单数量
|
||
|
||
$count = $RSOViewModel->getCount($map);
|
||
$RVModel = new RetailVipModel();
|
||
foreach ($order_list as &$val) {
|
||
if ($val['vid']) {
|
||
$vip_name = $RVModel->getFindField(array($RVModel::ID => $val['vid']), $RVModel::NAME);
|
||
$val['vip_name'] = $vip_name ? $vip_name : '未设置';
|
||
} else {
|
||
$val['vip_name'] = '非会员';
|
||
}
|
||
$val['user_select_time'] = $val['user_select_time'] ? date('Y-m-d H:i', $val['user_select_time']) : '';
|
||
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
|
||
$val['pickup_name'] = $val['pickup_type'] == 1 ? '自提' : ($val['pickup_type'] == 2 ? '同城' : '快递');
|
||
switch ($val['status']) {
|
||
case 1:
|
||
$val['status_name'] = '未发货';
|
||
break;
|
||
case 2:
|
||
$val['status_name'] = '未收货';
|
||
break;
|
||
case 3:
|
||
$val['status_name'] = '交易完成';
|
||
break;
|
||
default:
|
||
$val['status_name'] = '交易完成';
|
||
}
|
||
if ($val['state'] == 1) {
|
||
$val['state_name'] = '秒杀成功';
|
||
} else {
|
||
$val['state_name'] = '秒杀失败';
|
||
}
|
||
$val['remind_name'] = $val['remind_state'] == 1 ? '是' : '否';
|
||
$val['order_name'] = $val['order_type'] == 1 ? '购买' : '';
|
||
$val['pay_coupon_fee'] = $val['pay_coupon_fee'] > 0 ? floatval($val['pay_coupon_fee']) : '';
|
||
}
|
||
}
|
||
|
||
$plugClass = new Plug();
|
||
//订单获取祝福码,判断该门店是否,有,并且开启
|
||
$storePlugStatusPost = [
|
||
'store_id' => $this->store_id,
|
||
'identification_arr' => ['blessing'],
|
||
];
|
||
$storePlugStatus = $plugClass->plugStoreStatus($storePlugStatusPost);//获取状态
|
||
if ($storePlugStatus === true) {
|
||
//有权限
|
||
$jurisdictionBlessing = 1;
|
||
} else {
|
||
//无权限
|
||
$jurisdictionBlessing = 2;
|
||
}
|
||
|
||
$res = array(
|
||
'code' => 0,
|
||
'data' => $order_list,
|
||
'count' => $count ? $count : 0,
|
||
'pickup_type_one' => $pickup_type_one ? $pickup_type_one : 0,//待自提数量,秒杀订单
|
||
'pickup_type_two' => $pickup_type_two ? $pickup_type_two : 0,//待配送数量,秒杀订单
|
||
'pickup_type_three' => $pickup_type_three ? $pickup_type_three : 0,//待送货数量,秒杀订单
|
||
'jurisdiction_blessing' => $jurisdictionBlessing,//1有权限,2无权限
|
||
);
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
// 编辑活动 (加载模板)
|
||
public function edit($id)
|
||
{
|
||
if (!empty($id)) {
|
||
$SpikeViewModel = new RetailSpikeViewModel();
|
||
$map = array(
|
||
'id' => $id
|
||
);
|
||
$fields = array(
|
||
'id',
|
||
'gid',
|
||
'id',
|
||
'gid',
|
||
'sku_id',
|
||
'store_id',
|
||
'spike_price',
|
||
'name',
|
||
'start_time',
|
||
'end_time',
|
||
'stock',
|
||
'limit_num',
|
||
'status',
|
||
'add_time',
|
||
'send_type',
|
||
'sell_number',
|
||
'delivery_template_id',
|
||
'rise_num',
|
||
'goods_img_id',
|
||
'online_price',
|
||
);
|
||
$seckill_res = $SpikeViewModel->getFind($map, $fields);
|
||
if (!empty($seckill_res)) {
|
||
$seckill_res['start_time'] = date('Y-m-d H:i:s', $seckill_res['start_time']);
|
||
$seckill_res['end_time'] = date('Y-m-d H:i:s', $seckill_res['end_time']);
|
||
$seckill_res['send_type'] = explode(',', $seckill_res['send_type']);
|
||
$seckill_res['rise_num'] = $seckill_res['rise_num'] ? floatval($seckill_res['rise_num']) : '';
|
||
$seckill_res['goods_img'] = getImage($seckill_res['goods_img_id']);
|
||
//配送模板
|
||
$DeliveryTemplateModel = new DeliveryTemplateModel();
|
||
$where = array(
|
||
'store_id' => $this->store_id,
|
||
'status' => 1,
|
||
'state' => 1,
|
||
);
|
||
$delivery_template = $DeliveryTemplateModel->getSelect($where, "id,title");
|
||
$this->assign('delivery_template', $delivery_template);
|
||
|
||
$this->assign('seckill_res', $seckill_res);
|
||
$this->assign('send_type', json_encode($seckill_res['send_type']));
|
||
$this->display();
|
||
}
|
||
}
|
||
}
|
||
|
||
// 编辑操作
|
||
public function update()
|
||
{
|
||
$id = I('post.id');
|
||
$gid = I('post.gid');
|
||
$goods_seckill_price = I('post.goods_seckill_price');
|
||
$active_endtime = I('post.active_endtime');
|
||
$active_title = I('post.active_title');
|
||
$send_type = I('post.send_type');
|
||
$delivery_template_id = I('post.delivery_template_id');
|
||
$active_personal_limit_num = I('post.active_personal_limit_num');
|
||
$rise_num = I('post.rise_num'); //起购数量
|
||
if (!empty($id) && !empty($gid) && !empty($goods_seckill_price) && !empty($active_endtime) && !empty($active_title)) {
|
||
$SpikeModel = new RetailSpikeModel();
|
||
$map = array(
|
||
'id' => $id,
|
||
);
|
||
$seckill_data = $SpikeModel->getFind($map);
|
||
if (!empty($seckill_data)) {
|
||
if ($seckill_data['active_personal_limit_num'] != $active_personal_limit_num) {
|
||
$update['active_personal_limit_num'] = $active_personal_limit_num ? $active_personal_limit_num : 0;
|
||
}
|
||
if ($seckill_data['rise_num'] != $rise_num) {
|
||
$update['rise_num'] = $rise_num;
|
||
}
|
||
$active_endtime1 = strtotime($active_endtime);
|
||
if ($seckill_data['active_endtime'] != $active_endtime1 && $seckill_data['active_starttime'] < $active_endtime1) {
|
||
$update['active_endtime'] = $active_endtime1;
|
||
}
|
||
if ($seckill_data['active_title'] != $active_title) {
|
||
$update['active_title'] = $active_title;
|
||
}
|
||
if ($seckill_data['goods_seckill_price'] != $goods_seckill_price) {
|
||
$update['goods_seckill_price'] = $goods_seckill_price;
|
||
}
|
||
if ($seckill_data['send_type'] != $send_type) {
|
||
$update['send_type'] = $send_type;
|
||
}
|
||
if ($seckill_data['delivery_template_id'] != $delivery_template_id) {
|
||
$update['delivery_template_id'] = $delivery_template_id;
|
||
}
|
||
$update_seckill = $SpikeModel->updateOrder($map, $update);
|
||
if (!empty($update_seckill)) {
|
||
//操作日志记录
|
||
$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'] = '修改失败';
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '活动查询失败';
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数缺失';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//开启或关闭秒杀
|
||
public function storeOnOrOff()
|
||
{
|
||
$data['seckill_status'] = I('post.state');
|
||
$StoreXcxConfigModel = new RetailStoreXcxConfigModel();
|
||
$map = array(
|
||
'storeid' => $this->store_id
|
||
);
|
||
$store_config = $StoreXcxConfigModel->getFind($map);
|
||
if (empty($store_config)) {
|
||
$data['storeid'] = $this->store_id;
|
||
$data['addtime'] = time();
|
||
$add = $StoreXcxConfigModel->addOrder($data);
|
||
if ($add) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '修改成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '修改失败';
|
||
}
|
||
} else {
|
||
$save_res = $StoreXcxConfigModel->updateOrder($map, $data);
|
||
if ($save_res) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '修改成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '修改失败';
|
||
}
|
||
}
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = '秒杀-开启秒杀'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//开启或关闭商城首页显示秒杀
|
||
public function homeShowOrHide()
|
||
{
|
||
if (IS_POST) {
|
||
$status = I('post.status');
|
||
if (!empty($status)) {
|
||
$StoreXcxConfigModel = new RetailStoreXcxConfigModel();
|
||
$map = array(
|
||
'storeid' => $this->store_id,
|
||
);
|
||
$xcx_config = $StoreXcxConfigModel->getFind($map);
|
||
if (empty($xcx_config)) {
|
||
$data['storeid'] = $this->store_id;
|
||
$data['home_seckill_status'] = $status;
|
||
$data['addtime'] = time();
|
||
$add_store = $StoreXcxConfigModel->addOrder($data);
|
||
if (!empty($add_store)) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '修改成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '修改失败';
|
||
}
|
||
} else {
|
||
$save_res = $StoreXcxConfigModel->updateOrder($map, array('home_seckill_status' => $status));
|
||
if (!empty($save_res)) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '修改成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '修改失败';
|
||
}
|
||
}
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = '秒杀-开启在首页列表显示'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '缺少参数';
|
||
}
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
// 使失败
|
||
public function fail()
|
||
{
|
||
$platform_type = $this->role_info['platform_type'];
|
||
$bill_id = I('post.bill_id');
|
||
if (!$bill_id) {
|
||
$res = array('status' => 0, 'msg' => '参数缺失');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 查询订单
|
||
$RBOModel = new RetailBillOrderModel();
|
||
$map = array(
|
||
'b.' . $RBOModel::STORE_ID => $this->store_id,
|
||
'b.' . $RBOModel::MERCHANT_ID => $this->merchant_id,
|
||
'b.' . $RBOModel::PAY_STATE => 1,
|
||
'b.' . $RBOModel::TYPE => 1,
|
||
'b.' . $RBOModel::ID => $bill_id,
|
||
'o.order_genre' => 3,
|
||
's.state' => 1,
|
||
);
|
||
$fields = [
|
||
'b.' . $RBOModel::ID,
|
||
'b.' . $RBOModel::ORDER_NO,
|
||
];
|
||
if ($platform_type == 2) {
|
||
//第三方平台
|
||
$fields[] = 'b.third_order';
|
||
}
|
||
$find = $RBOModel->getFindSpike($map, $fields);
|
||
if (!$find) {
|
||
$res = array('status' => 0, 'msg' => '查询失败');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 处理数据
|
||
if ($platform_type == 2) {
|
||
//第三方平台
|
||
$ThirdClass = new Order();
|
||
$ThirdResult = $ThirdClass->orderCancel([
|
||
'merchant_id' => $this->merchant_id,
|
||
'third_order' => $find['third_order']
|
||
]);
|
||
if ($ThirdResult['status'] == 0) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '第三方平台取消订单失败' . $ThirdResult['message'];
|
||
return $result;
|
||
}
|
||
}
|
||
$ActivityOrder = new ActivityOrderController();
|
||
$res = $ActivityOrder->doRefund_v1($find[$RBOModel::ORDER_NO]);
|
||
if ($res['status'] == 1) {
|
||
$RBSModel = new RetailBillSpikeModel();
|
||
$save_result = $RBSModel->updateOrder(array($RBSModel::BILL_ID => $find[$RBOModel::ID]), array($RBSModel::STATE => 0));
|
||
if (!$save_result) {
|
||
$res = array('status' => 0, 'msg' => '操作失败');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = '秒杀订单使失败'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 后台退款
|
||
* @param $order_no string 订单号
|
||
* @return $res array $res['status] 状态
|
||
*/
|
||
public function refund()
|
||
{
|
||
// 接受数据
|
||
$order_no = strval(I('post.order_no'));
|
||
// 判断参数
|
||
if (!$order_no) {
|
||
$res = array('status' => 0, 'msg' => '参数缺失');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 查询订单
|
||
$RSOViewModel = new RetailSpikeOrderViewModel();
|
||
$map = array(
|
||
'RetailBillOrder.order_no' => strval($order_no),
|
||
'RetailBillOrder.pay_state' => 1,
|
||
'RetailBillOrder.type' => 1,
|
||
'RetailBillOrder.merchant_id' => $this->merchant_id,
|
||
'RetailBillOrder.store_id' => $this->store_id,
|
||
'RetailBillOrder.order_type' => 2,
|
||
'RetailBillOnline.order_genre' => 3
|
||
);
|
||
$field = array('id', 'pickup_type');
|
||
$spike_order = $RSOViewModel->getFind($map, $field);
|
||
if (!$spike_order) {
|
||
$res = array('status' => 0, 'msg' => '订单查询失败');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$data = array(
|
||
'store_id' => $this->store_id,
|
||
'merchant_id' => $this->merchant_id,
|
||
'order_no' => $order_no,
|
||
'user_type' => 3,
|
||
'return_delivery_fee' => $spike_order['pickup_type'] == 1 ? 2 : 1, // 是否退还配送费 1.退还 2.不退还
|
||
'platform_type' => $this->role_info['platform_type']
|
||
);
|
||
// 退款
|
||
$Refund = new RefundController();
|
||
$res = $Refund->onlineOrderRefund_v2($data);
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = '秒杀订单退款'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/*
|
||
* 门店id打印机
|
||
*/
|
||
public function linePrint()
|
||
{
|
||
$order_id = I('post.order_id');
|
||
if (!$order_id) {
|
||
$res = array('status' => 0, 'msg' => '参数缺失');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$Printer = new \PayApi\Controller\PrinterController();
|
||
$res = $Printer->linePrinting_v1($this->store_id, $order_id, true);
|
||
if ($res['status'] == 0) {
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
}
|