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

1018 行
40 KiB
PHP
可执行文件

<?php
namespace Retail\Controller;
use Common\Model\AdvanceGoodsModel;
use Common\Model\AdvanceSkuGoodsModel;
use Common\Model\DeliveryTemplateModel;
use Common\Model\FaceBackGroundModel;
use Common\Model\ImageGalleryModel;
use Common\Model\RetailBillAdvanceModel;
use Common\Model\RetailGoodsModel;
use Common\Model\RetailSkuGoodsModel;
use Common\Model\RetailStoreXcxConfigModel;
use Common\Model\SSaleMGoodsModel;
use LittleGift\Business\Goods;
//[1.8.50]
/**
* 预售
* Class AdvanceSaleController
* @package Retail\Controller
*/
class AdvanceSaleController extends BaseController
{
public function index()
{
$arr = array(
'advance_sale_status' => '/index.php/Retail/AdvanceSale/changeSate',
'addAdvance' => '/index.php/Retail/AdvanceSale/addAdvance',
'imgSet' => '/index.php/Retail/AdvanceSale/add_advance_image',
'Delete' => '/index.php/Retail/AdvanceSale/deleteAct',
);
$authArr = checkFunction($arr);
$store_id = $this->store_id;
$info = M("store_xcx_config")->field("advance_sale_status,advance_sale_index_status")->where(array('storeid' => $store_id))->find();
$this->assign('authArr', $authArr);
$this->assign('advance_sale_status', $info['advance_sale_status']);
$this->assign('advance_sale_index_status', $info['advance_sale_index_status']);
$this->display();
}
/**
* 轮播图
*/
public function banner()
{
$this->display();
}
/*轮播列表
*
*/
public function advanceImgList()
{
$data = I("post.");
$page = $data['page'] . ',' . $data['limit'];
$where = array(
'store_id' => $this->store_id,
'status' => array('in', '0,1'),
'scene_type' => 3
);
$FaceBackGroundModel = new FaceBackGroundModel();
$list = $FaceBackGroundModel->getSelect($where, "*", "id desc", $page);
if ($list) {
$ImageGalleryModel = new ImageGalleryModel();
$count = $FaceBackGroundModel->getCount($where);
foreach ($list as $key => &$val) {
$val['key'] = $key + 1;
$val['img'] = $ImageGalleryModel->getFieldPath(array('id' => $val['img_id']));
}
}
$res['status'] = 1;
$res['imgList'] = $list;
$res['count'] = $count ? $count : 0;
$this->ajaxReturn($res);
}
/*
* 轮播添加
*/
public function advanceImgAdd()
{
$editId = json_decode($_POST['editId'], true);
$order = json_decode($_POST['order'], true);
$label_img_id = I('post.label_img_id');
if (!$label_img_id) {
$label_img = $_FILES['label_img'];
if ($label_img['error'] == 0) {
/* 上传图片 */
$upData = array(
'add_time' => time(),
'from_type_id' => 45,
'localUrl' => 'Store/Advance',
'user_type' => 4,
'merchant_id' => $this->merchant_id,
'store_id' => $this->store_id
);
$uploads = uploadFiles($upData);
if ($uploads['label_img']['savePath'] && $uploads['label_img']['id']) {
$data['img_id'] = $uploads['label_img']['id'];
} else {
$res = array('status' => 0, 'msg' => '图片上传失败,请重试');
$this->ajaxReturn($res);
}
} else {
$res = array('status' => 0, 'msg' => '请上传图片');
$this->ajaxReturn($res);
}
} else {
$data['img_id'] = $label_img_id;
}
$data['sort'] = $order;
$FaceBackGroundModel = new FaceBackGroundModel();
if (!empty($editId)) {
$map['id'] = $editId;
$success = $FaceBackGroundModel->updateOrder($map, $data);
$desc = '预售轮播图编辑';
} else {
$data['store_id'] = $this->store_id;
$data['merchant_id'] = $this->merchant_id;
$data['scene_type'] = 3;
$success = $FaceBackGroundModel->addOrder($data);
$desc = '预售轮播图添加';
}
if ($success) {
$Journal_parameter = array(
'source' => 0,
'type' => 4,
'desc' => $desc,
'request_data' => json_encode($_POST),
);
action_log_v2($Journal_parameter); //日志
$res = array('status' => 1, 'msg' => '操作成功');
} else {
$res = array('status' => 0, 'msg' => '暂无修改');
}
$this->ajaxReturn($res);
}
/*轮播开启关闭
*
*/
public function advanceChange()
{
$data = I("post.");
$id = $data['id'];
$status = $data['status'];
if (!$id || !isset($status)) {
$res = array('status' => 0, 'msg' => '参数缺失');
$this->ajaxReturn($res);
}
$FaceBackGroundModel = new FaceBackGroundModel();
$save = $FaceBackGroundModel->updateOrder(array('id' => $id), array('status' => $status));
if ($save) {
$Journal_parameter = array(
'source' => 0,
'type' => 4,
'desc' => "预售轮播图关闭",
'request_data' => json_encode($_POST),
);
action_log_v2($Journal_parameter); //日志
$res = array('status' => 1, 'msg' => '操作成功');
} else {
$res = array('status' => 0, 'msg' => '暂无修改');
}
$this->ajaxReturn($res);
}
/*轮播删除
*
*/
public function advanceDelList()
{
$id = I("post.id");
if (!$id) {
$res = array('status' => 0, 'msg' => '参数缺失');
$this->ajaxReturn($res);
}
$FaceBackGroundModel = new FaceBackGroundModel();
$del = $FaceBackGroundModel->updateOrder(array('id' => $id), array('status' => 2));
if ($del) {
$Journal_parameter = array(
'source' => 0,
'type' => 4,
'desc' => "预售轮播图删除",
'request_data' => json_encode($_POST),
);
action_log_v2($Journal_parameter); //日志
$res = array('status' => 1, 'msg' => '操作成功');
} else {
$res = array('status' => 0, 'msg' => '请勿重复操作');
}
$this->ajaxReturn($res);
}
/**
* 修改设置
*/
public function changeSate()
{
$store_id = $this->store_id;
$data = I("post.");
$type = $data['type'];
$state = $data['state'];
if ($type == 1) {
//是否开启预售
$content['advance_sale_status'] = $state;
} else if ($type == 2) {
//是否在首页展示
$content['advance_sale_index_status'] = $state;
}
$StoreXcxConfigModel = new RetailStoreXcxConfigModel();
$map = array(
'storeid' => $store_id
);
$info = $StoreXcxConfigModel->getFind($map);
if ($info) {
$save = $StoreXcxConfigModel->updateOrder($map, $content);
} else {
$content['storeid'] = $store_id;
$save = $StoreXcxConfigModel->addOrder($content);
}
if ($save) {
$Journal_parameter = array(
'source' => 0,
'type' => 4,
'desc' => "预售模块开启关闭",
'request_data' => json_encode($_POST),
);
action_log_v2($Journal_parameter); //日志
$res = array('status' => 1, 'msg' => '操作成功');
} else {
$res = array('status' => 0, 'msg' => '暂无修改');
}
$this->ajaxReturn($res);
}
/**
* 开启关闭
*/
public function advance_state_modify()
{
$AdvanceGoodsModel = new AdvanceGoodsModel();
$AdvanceSkuGoodsModel = new AdvanceSkuGoodsModel();
$data = I("post.");
//验证参数
$verify_info = $AdvanceGoodsModel->existence_id(array("id" => $data['id']));
if ($verify_info['status'] == 0) {
$this->ajaxReturn($verify_info);
}
$advance_state = $data['advance_state'];
if ($advance_state == 1) {
//验证是否可以开启
$RetailGoodsModel = new RetailGoodsModel();
$advance_open_verify = $RetailGoodsModel->advance_open_verify(array("store_id" => $this->store_id, "goods_id" => $data['goods_id']));
if ($advance_open_verify['status'] == 0) {
$this->ajaxReturn($advance_open_verify);
}
$advance_sale_status = $RetailGoodsModel->getFindField([
'store_id' => $this->store_id,
'id' => $data['goods_id']
], 'advance_sale_status');
if ($advance_sale_status == 0) {
$res = array('status' => 0, 'msg' => '该商品已关闭预售,无法开启该活动');
$this->ajaxReturn($res);
}
}
$save = $AdvanceGoodsModel->updateOrder(array('id' => $data['id']), array('advance_state' => $advance_state));
if ($save) {
$AdvanceSkuGoodsModel->updateOrder(array('advance_id' => $data['id']), array('advance_state' => $advance_state));
$Journal_parameter = array(
'source' => 0,
'type' => 4,
'desc' => "预售活动开启关闭",
'request_data' => json_encode($_POST),
);
action_log_v2($Journal_parameter); //日志
$res = array('status' => 1, 'msg' => '操作成功');
} else {
$res = array('status' => 0, 'msg' => '请勿重复操作');
}
$this->ajaxReturn($res);
}
/**
* 预售列表
*/
public function advanceList()
{
$store_id = $this->store_id;
$advanceModel = new AdvanceGoodsModel();
$AdvanceSkuGoods = new AdvanceSkuGoodsModel();
$data = I("post.");
$order_number = $data["order_number"];
$price = $data['price'];
$advance_type = $data['advance_type'];
$advance_state = $data['advance_state'];
$add_time = $data['add_time'];
$page = $data['page'];
$limit = $data['limit'];
$where = array(
'a.store_id' => $store_id,
'a.advance_state' => array('neq', 2)
);
if (!empty($order_number)) {
//名称货号条码
$where['g.goods_number | g.goods_name | g.goods_code'] = array('like', '%' . $order_number . '%');
}
if (!empty($price)) {
$wap = array(
'store_id' => $store_id,
'advance_state' => array('neq', 2)
);
switch ($price) {
case 1:
//50以下
$wap['advance_price'] = array('lt', '50');
$tap['a.advance_price'] = array('lt', '50');
break;
case 2:
$wap['advance_price'] = array('between', array('50', '200'));
$tap['a.advance_price'] = array('between', array('50', '200'));
break;
case 3:
$wap['advance_price'] = array('between', array('200', '500'));
$tap['a.advance_price'] = array('between', array('200', '500'));
break;
case 4:
$wap['advance_price'] = array('between', array('500', '1000'));
$tap['a.advance_price'] = array('between', array('500', '1000'));
break;
case 5:
$wap['advance_price'] = array('gt', '1000');
$tap['a.advance_price'] = array('gt', '1000');
break;
}
$advance_id_arr = $AdvanceSkuGoods->where($wap)->group("advance_id")->getField("advance_id", true);
if (!empty($advance_id_arr)) {
$tap['a.id'] = array('in', $advance_id_arr);
$tap['_logic'] = 'or';
$where['_complex'] = $tap;
} else {
$where['a.advance_price'] = $tap['a.advance_price'];
}
}
if (!empty($advance_type)) {
$where['a.advance_type'] = $advance_type;
}
if ($advance_state != "") {
$where['a.advance_state'] = $advance_state;
}
if (!empty($add_time)) {
$start_time = strtotime($add_time[0]);
$end_time = strtotime($add_time[1]);
$where['a.add_time'] = array('between', array($start_time, $end_time));
}
$parameter = array(
'where' => $where,
'page' => $page,
'limit' => $limit,
'field' => array(
'a.id',
'a.goods_id',
'a.advance_num',
'a.surplus_num',
'a.advance_start_time',
'a.advance_end_time',
'a.advance_state',
'a.advance_type',
'a.attribute_state',
'g.goods_name',
'g.goods_number',
'g.goods_code',
)
);
$info = $advanceModel->getList($parameter);
if ($info['status'] == 1) {
$count = $advanceModel->getListCount(array('where' => $where));
$list = $info['data']['list'];
foreach ($list as $key => &$val) {
$val['index'] = $key + 1;
$val['advance_num'] = round($val['advance_num'], 3);
if (C('IS_SET_REDIS')) {
$frozen_param = array(
'id' => $val['id'],
'goods_id' => $val['goods_id'],
'sku_id' => '',
'attribute_state' => $val['attribute_state'],
);
$frozen_num = $advanceModel->frozen_num($frozen_param);
$val['surplus_num'] = round($val['surplus_num'] - $frozen_num, 3);
}
$val['surplus_num'] = round($val['surplus_num'], 3);
$val['advance_start_time'] = date('Y-m-d H:i:s', $val['advance_start_time']);
$val['advance_end_time'] = date('Y-m-d H:i:s', $val['advance_end_time']);
switch ($val['advance_type']) {
case 1:
$val['type_name'] = "全额";
break;
case 2:
$val['type_name'] = "定金";
break;
}
switch ($val['advance_state']) {
case 0:
$val['advance_name'] = "关闭";
break;
case 1:
$val['advance_name'] = "开启";
break;
}
}
}
$res['status'] = 1;
$res['msg'] = '查询成功';
$res['data'] = $list ? $list : array();
$res['count'] = $count ? $count : 0;
$this->ajaxReturn($res);
}
/**
* 预售商品
*/
public function addAdvance()
{
$id = I("get.id");
if (!empty($id)) {
$this->assign('id', $id);
$this->assign("edit", true);
} else {
$this->assign('id', "");
$this->assign("edit", false);
}
//配送模板
$where = array(
'store_id' => $this->store_id,
'status' => 1,
'state' => 1,
);
$DeliveryTemplateModel = new DeliveryTemplateModel();
$delivery_template = $DeliveryTemplateModel->getSelect($where, "id,title");
$delivery_template = $delivery_template ? $delivery_template : array();
$this->assign("delivery_template", json_encode($delivery_template));
$this->display();
}
/**
* 商品列表
*/
public function goodsList()
{
$platform_type = $this->role_info['platform_type']; //商户平台类型 1默认系统 2微礼平台
$store_id = $this->store_id;
$GoodsModel = new RetailGoodsModel();
$page = I("post.page") . "," . I("post.limit");
$order_number = I("post.order_number");
$AdvanceGoodsModel = new AdvanceGoodsModel();
$advance_goods_ids = $AdvanceGoodsModel->getFindField(array('advance_state' => array('neq', 2), 'advance_end_time'=>['gt',time()],'store_id' => $store_id), "goods_id", true);
$where = array(
'g.store_id' => $store_id,
'g.status' => 0,
'g.online_state' => 1,
'g.advance_sale_status' => 1
);
if (!empty($advance_goods_ids)) {
$where['g.id'] = array('not in', $advance_goods_ids);
}
if (!empty($order_number)) {
$where['g.goods_number | g.goods_name | g.goods_code'] = array('like', "%" . $order_number . "%");
}
$fields = [
'g.id',
'g.goods_img_id',
'g.goods_name',
'g.goods_number',
'g.goods_code',
'g.online_price',
'g.attribute_state',
'g.status',
'g.pricing_method',
's.goods_num'
];
if ($platform_type == 2) {
$fields[] = 'g.third_goods_code';
}
$list = $GoodsModel->getOnlineGoods($where, $fields, "g.id desc", $page);
if ($list) {
$count = $GoodsModel->getOnlineCount($where);
$ImageGalleryModel = new ImageGalleryModel();
if ($platform_type == 2) {
//第三方平台
$code_arr = [];
}
foreach ($list as &$val) {
$val['online_price'] = round($val['online_price'], 2);
$val['image'] = $ImageGalleryModel->getOneField(array('id' => $val['goods_img_id']), 'path');
if ($platform_type == 2) {
//第三方平台
if ($val['attribute_state'] == 2) {
$val['goods_num'] = '规格库存';
} else {
$val['goods_num'] = 0;
$code_arr[$val['id']] = $val['third_goods_code'];
}
} else {
if ($val['attribute_state'] == 2) {
$val['goods_num'] = A("Api/Inventory")->goods_num(2, $store_id, $val['id']);
} else {
$val['goods_num'] = round($val['goods_num'], 3);
}
}
switch ($val['status']) {
case 0:
$val['status_name'] = "上架";
break;
case 1:
$val['status_name'] = "下架";
break;
}
}
if ($platform_type == 2 && !empty($code_arr)) {
//第三方平台
$ThirdGoodsClass = new Goods();
$storeResult = $ThirdGoodsClass->storeCode($this->store_id);
$Customer_Codes = $storeResult['data'];
$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 ($list as &$val) {
if ($val['attribute_state'] == 1 && !empty($goods_stock[$val['id']])) {
$val['goods_num'] = $goods_stock[$val['id']];
}
}
}
}
} else {
$count = 0;
}
$res['data'] = $list;
$res['count'] = $count;
$this->ajaxReturn($res);
}
/**
* 规格信息
*/
public function getSkuList()
{
$platform_type = $this->role_info['platform_type'];
$goods_id = I("post.goods_id");
$where = array(
'k.goods_id' => $goods_id,
'k.status' => 1,
'k.state' => 0
);
$fields = [
'k.id as sku_id',
'k.online_price',
's.goods_num',
's.sku_name'
];
if ($platform_type == 2) {
//第三方平台
$fields[] = 'k.third_goods_code';
}
$RetailSkuGoodsModel = new RetailSkuGoodsModel();
$list = $RetailSkuGoodsModel->getSkuGoodsList($where, $fields);
if ($list) {
if ($platform_type == 2) {
$code_arr = [];
}
foreach ($list as &$val) {
if ($platform_type == 2) {
$val['goods_num'] = 0;
$code_arr[$val['sku_id']] = $val['third_goods_code'];
} else {
$val['goods_num'] = round($val['goods_num'], 3);
}
$val['online_price'] = round($val['online_price'], 2);
}
if ($platform_type == 2 && !empty($code_arr)) {
//第三方平台
$ThirdGoodsClass = new Goods();
$storeResult = $ThirdGoodsClass->storeCode($this->store_id);
$Customer_Codes = $storeResult['data'];
$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 ($list as &$val) {
if (!empty($goods_stock[$val['sku_id']])) {
$val['goods_num'] = $goods_stock[$val['sku_id']];
}
}
}
}
$res['status'] = 1;
$res['data'] = $list;
} else {
$res['status'] = 0;
$res['msg'] = "未找到改规格信息";
}
$this->ajaxReturn($res);
}
/**
* 添加/编辑 商品
*/
public function addSet()
{
$merchant_id = $this->merchant_id;
$store_id = $this->store_id;
$data = json_decode(htmlspecialchars_decode(I("post.goods")), true);
$advance_id = I("post.id"); //预售主键id 编辑可用
$verify_param = array(
'merchant_id' => $merchant_id,
'store_id' => $store_id,
'data' => $data
);
//验证参数
$AdvanceGoodsModel = new AdvanceGoodsModel();
$add_param_verify = $AdvanceGoodsModel->add_param_verify($verify_param);
if ($add_param_verify['status'] == 0) {
$this->ajaxReturn($add_param_verify);
}
$ruleList = $data['ruleList'];
//商品验证
$goods_verify = $AdvanceGoodsModel->goods_verify(array('advance_id' => $advance_id, 'rule_list' => $ruleList, 'data' => $data, 'store_id' => $store_id));
if ($goods_verify['status'] == 0) {
$this->ajaxReturn($goods_verify);
}
asort($data['delivery_type']); //配送方式排序
if (in_array(3, $data['delivery_type'])) {
$delivery_template_id = $data['delivery_template_id'];
} else {
$delivery_template_id = 0;
}
$content = array(
'merchant_id' => $merchant_id,
'store_id' => $store_id,
'goods_id' => $data['goods_id'],
'restrict_num' => $data['restrict_num'] ? $data['restrict_num'] : null,
'rise_num' => $data['rise_num'] ? $data['rise_num'] : null,
'advance_start_time' => strtotime($data['advance_time'][0]),
'advance_end_time' => strtotime($data['advance_time'][1]),
'tail_start_time' => strtotime($data['tail_time'][0]),
'tail_end_time' => strtotime($data['tail_time'][1]),
'deliver_start_time' => strtotime($data['deliver_time'][0]),
'deliver_end_time' => strtotime($data['deliver_time'][1]),
'advance_type' => $data['advance_type'],
'advance_state' => 1,
'delivery_type' => implode(',', $data['delivery_type']),
'delivery_template_id' => $delivery_template_id,
'refuse_earnest_price' => $data['refuse_earnest_price'],
'add_time' => time(),
'attribute_state' => $data['attribute_state']
);
if (!empty($advance_id)) {
unset($content['refuse_earnest_price']);
unset($content['advance_type']);
}
$res = $AdvanceGoodsModel->advance_add(array('advance_id' => $advance_id, 'data' => $data, 'rule_list' => $ruleList, 'content' => $content));
if ($res['status'] == 1) {
$Journal_parameter = array(
'source' => 0,
'type' => 4,
'desc' => $advance_id ? "预售活动编辑" : "预售活动添加",
'request_data' => json_encode($_POST),
);
action_log_v2($Journal_parameter); //日志
}
$this->ajaxReturn($res);
}
/**
* 编辑信息
*/
public function editInfo()
{
$platform_type = $this->role_info['platform_type'];
$store_id = $this->store_id;
$id = I("post.id");
$AdvanceGoodsModel = new AdvanceGoodsModel();
if ($platform_type == 2) {
$ThirdGoodsClass = new Goods();
$storeResult = $ThirdGoodsClass->storeCode($this->store_id);
$Customer_Codes = $storeResult['data'];
$third_data = [
'merchant_id' => $this->merchant_id,
'type' => 2,
'Customer_Codes' => $Customer_Codes
];
}
if (!empty($id)) {
$where['a.id'] = $id;
$fields = [
'a.*',
'g.goods_name',
'g.attribute_state',
'g.online_price',
'g.goods_img_id',
];
if ($platform_type == 2) {
$fields[] = 'g.third_goods_code';
}
$goods_info = M("retail_advance_goods as a")
->join("ls_retail_goods as g on a.goods_id=g.id")
->where($where)
->field($fields)
->find();
$ImageGalleryModel = new ImageGalleryModel();
$path = $ImageGalleryModel->getOneField(array('id' => $goods_info['goods_img_id']), 'path');
if ($goods_info['attribute_state'] == 1) {
$map = array(
'store_id' => $store_id,
'goods_id' => $goods_info['goods_id'],
);
$SSaleMGoodsModel = new SSaleMGoodsModel();
if ($platform_type == 2) {
//第三方平台
$goods_num = 0;
$third_data['code_arr'] = [$goods_info['third_goods_code']];
$thirdResult = $ThirdGoodsClass->goodsNumQuery($third_data);
if ($thirdResult['status'] == 1 && !empty($thirdResult['data'])) {
$goods_num = $thirdResult['data'][0];
}
} else {
$goods_num = $SSaleMGoodsModel->getFindField($map, "goods_num");
}
if (C('IS_SET_REDIS')) {
$frozen_param = array(
'id' => $id,
'goods_id' => $goods_info['goods_id'],
'sku_id' => '',
'attribute_state' => 1
);
$frozen_num = $AdvanceGoodsModel->frozen_num($frozen_param);
$goods_info['surplus_num'] = round($goods_info['surplus_num'] - $frozen_num, 3);
}
$ruleList = array(array(
'goods_num' => round($goods_num, 3),
'surplus_num' => round($goods_info['surplus_num'], 3),
'online_price' => round($goods_info['online_price'], 2),
'advance_price' => round($goods_info['advance_price'], 2),
'advance_num' => round($goods_info['advance_num'], 3),
'sold_num' => round(($goods_info['advance_num'] - $goods_info['surplus_num']), 3),
'earnest_price' => round($goods_info['earnest_price'], 2),
'arrive_price' => $goods_info['arrive_price'] ? round($goods_info['arrive_price'], 2) : '',
'edit_type' => true
));
} else if ($goods_info['attribute_state'] == 2) {
$map = array(
'a.goods_id' => $goods_info['goods_id'],
'a.advance_id' => $id,
);
$fields = [
'a.sku_id',
'a.advance_num',
'a.surplus_num',
'a.earnest_price',
'a.advance_price',
'a.arrive_price',
's.sku_name',
's.goods_num',
'k.online_price'
];
if ($platform_type == 2) {
//第三方平台
$fields[] = 'k.third_goods_code';
}
$ruleList = M("retail_advance_sku_goods as a")
->join("ls_retail_store_sale_goods as s on a.sku_id=s.sku_id")
->join("ls_retail_sku_goods as k on s.sku_id = k.id")
->where($map)
->field($fields)
->order("a.id asc")
->select();
if ($platform_type == 2) {
//第三方平台
$code_arr = [];
}
foreach ($ruleList as &$val) {
$sku_id_arr[] = $val["sku_id"];
if (C('IS_SET_REDIS')) {
$frozen_param = array(
'id' => $id,
'goods_id' => $goods_info['goods_id'],
'sku_id' => $val['sku_id'],
'attribute_state' => 2
);
$frozen_num = $AdvanceGoodsModel->frozen_num($frozen_param);
$val['surplus_num'] = round($val['surplus_num'] - $frozen_num, 3);
}
$val['advance_num'] = round($val['advance_num'], 3);
if($platform_type == 2){
//第三方平台
$code_arr[$val['sku_id']] = $val['third_goods_code'];
}else{
$val['goods_num'] = round($val['goods_num'], 3);
}
$val['surplus_num'] = round($val['surplus_num'], 3);
$val['sold_num'] = round(($val['advance_num'] - $val['surplus_num']), 3);
$val['earnest_price'] = round($val['earnest_price'], 2);
$val['advance_price'] = round($val['advance_price'], 2);
$val['arrive_price'] = $val['arrive_price'] ? round($val['arrive_price'], 2) : '';
$val['online_price'] = round($val['online_price'], 2);
$val['edit_type'] = true;
}
if ($platform_type == 2 && !empty($code_arr)) {
//第三方平台
$third_data['code_arr'] = $code_arr;
$thirdResult = $ThirdGoodsClass->goodsNumQuery($third_data);
if ($thirdResult['status'] == 1 && !empty($thirdResult['data'])) {
$goods_stock = $thirdResult['data'];
foreach ($ruleList as &$val) {
if (!empty($goods_stock[$val['sku_id']])) {
$val['goods_num'] = $goods_stock[$val['sku_id']];
}
}
}
}
$map = array(
'k.goods_id' => $goods_info['goods_id'],
'k.status' => 1,
'k.state' => 0,
'k.id' => array('not in', $sku_id_arr)
);
$fields = [
'k.online_price',
's.sku_id',
's.sku_name',
's.goods_num',
];
if ($platform_type == 2) {
//第三方平台
$fields[] = 'k.third_goods_code';
}
$SkuGoodsModel = new RetailSkuGoodsModel();
$old_sku_info = $SkuGoodsModel->getSkuGoodsList($map, $fields);
if ($old_sku_info) {
if ($platform_type == 2) {
//第三方平台
$code_arr = [];
}
foreach ($old_sku_info as &$v) {
if ($platform_type == 2) {
//第三方平台
$v['goods_num'] = 0;
$code_arr[$v['sku_id']] = $v['third_goods_code'];
} else {
$v['goods_num'] = round($v['goods_num'], 3);
}
$v['online_price'] = round($v['online_price'], 2);
$v['edit_type'] = false;
}
if ($platform_type == 2 && !empty($code_arr)) {
//第三方平台
$third_data['code_arr'] = $code_arr;
$thirdResult = $ThirdGoodsClass->goodsNumQuery($third_data);
if ($thirdResult['status'] == 1 && !empty($thirdResult['data'])) {
$goods_stock = $thirdResult['data'];
foreach ($old_sku_info as &$val) {
if (!empty($goods_stock[$val['sku_id']])) {
$val['goods_num'] = $goods_stock[$val['sku_id']];
}
}
}
}
$ruleList = array_merge($ruleList, $old_sku_info);
}
}
$delivery_type = explode(',', $goods_info['delivery_type']);
$express_state = false; //是否显示配送模板
if (in_array(3, $delivery_type)) {
$express_state = true;
}
//配送模板
$where = array(
'store_id' => $store_id,
'status' => 1,
'state' => 1,
);
$DeliveryTemplateModel = new DeliveryTemplateModel();
$delivery_template = $DeliveryTemplateModel->getSelect($where, "id,title");
$delivery_template = $delivery_template ? $delivery_template : array();
$advance_time = array(date('Y-m-d H:i:s', $goods_info['advance_start_time']), date('Y-m-d H:i:s', $goods_info['advance_end_time']));
$tail_time = array(date('Y-m-d H:i:s', $goods_info['tail_start_time']), date('Y-m-d H:i:s', $goods_info['tail_end_time']));
$deliver_time = array(date('Y-m-d H:i:s', $goods_info['deliver_start_time']), date('Y-m-d H:i:s', $goods_info['deliver_end_time']));
$info = array(
'goods_id' => $goods_info['goods_id'],
'goods_name' => $goods_info['goods_name'],
'advance_type' => $goods_info['advance_type'],
'attribute_state' => $goods_info['attribute_state'],
'restrict_num' => $goods_info['restrict_num'] ? floatval($goods_info['restrict_num']) : '',
'rise_num' => $goods_info['rise_num'] ? floatval($goods_info['rise_num']) : '',
'advance_time' => $advance_time,
'tail_time' => $tail_time,
'deliver_time' => $deliver_time,
'delivery_type' => $goods_info['delivery_type'] ? json_decode('[' . join(',', $delivery_type) . ']', true) : array(),
'refuse_earnest_price' => $goods_info['refuse_earnest_price'],
'ruleList' => $ruleList,
'delivery_list' => array(
array('type' => 1, 'title' => '自提'),
array('type' => 2, 'title' => '同城配送'),
array('type' => 3, 'title' => '快递配送'),
),
'delivery_template' => $delivery_template,
'delivery_template_id' => $goods_info['delivery_template_id'] ? $goods_info['delivery_template_id'] : '',
'express_state' => $express_state
);
$content = array(
'path' => $path,
'goods' => $info
);
$res['status'] = 1;
$res['info'] = $content;
} else {
$res['status'] = 0;
}
$this->ajaxReturn($res);
}
/**
*活动删除
*/
public function deleteAct()
{
$id = I("post.id");
$goods_id = I("post.goods_id");
if (!$id) {
$res['status'] = 0;
$res['msg'] = "参数缺失";
$this->ajaxReturn($res);
}
$GoodsModel = new RetailGoodsModel();
$AdvanceGoodsModel = new AdvanceGoodsModel();
$AdvanceSkuGoodsModel = new AdvanceSkuGoodsModel();
$aMap = array(
'id' => $id,
);
$advance_info = $AdvanceGoodsModel->getFind($aMap);
if (!$advance_info) {
$res = array(
'status' => 0,
'msg' => '未找到该活动'
);
$this->ajaxReturn($res);
}
//判断是否存在售卖订单
$AdvanceOrderModel = new RetailBillAdvanceModel();
$order_info = $AdvanceOrderModel->getFind([
'state' => ['gt', 0],
'advance_id' => $id
]);
if (!empty($order_info)) {
//有售卖情况
if (round($advance_info['advance_num'], 3) != round($advance_info['surplus_num'], 3)) {
if ($advance_info['deliver_end_time'] > time() || $advance_info['tail_end_time'] > time()) {
$res = array(
'status' => 0,
'msg' => '预售活动未结束暂不能删除'
);
$this->ajaxReturn($res);
}
}
}
$save = $AdvanceGoodsModel->updateOrder($aMap, array('advance_state' => 2));
if ($save) {
$AdvanceSkuGoodsModel->updateOrder(array('advance_id' => $id), array('advance_state' => 2));
$surplus_num = $AdvanceGoodsModel->getFindField(array('id' => $id), "surplus_num");
if ($surplus_num > 0) {
$attribute_state = $GoodsModel->getFindField(array('id' => $goods_id), "attribute_state");
if ($attribute_state == 1) {
A("Api/Inventory")->Inventory(1, $surplus_num, $goods_id);
} else if ($attribute_state == 2) {
$map = array(
'advance_id' => $id,
'goods_id' => $goods_id,
'surplus_num' => array('gt', 0)
);
$skuList = $AdvanceSkuGoodsModel->getSelect($map);
if ($skuList) {
foreach ($skuList as $val) {
A("Api/Inventory")->Inventory(1, $val['surplus_num'], $goods_id, $val['sku_id']);
}
}
}
}
$Journal_parameter = array(
'source' => 0,
'type' => 4,
'desc' => "预售活动删除",
'request_data' => json_encode($_POST),
);
action_log_v2($Journal_parameter); //日志
$res['status'] = 1;
$res['msg'] = "操作成功";
} else {
$res['status'] = 0;
$res['msg'] = '请勿重复操作';
}
$this->ajaxReturn($res);
}
}