3783 行
155 KiB
PHP
可执行文件
3783 行
155 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Retail\Controller;
|
||
|
||
use CashierApi\Business\OffLineCashier;
|
||
use Common\Business\Banner;
|
||
use Common\Business\DownFile;
|
||
use Common\Business\Goods;
|
||
use Common\Business\GoodsClassify;
|
||
use Common\Business\LabelInventory;
|
||
use Common\Business\OperateGoods;
|
||
use Common\Business\SkuAttribute;
|
||
use Common\Business\UnitLibrary;
|
||
use Common\Business\Yieldly;
|
||
use Common\Model\MGoodsBannerModel;
|
||
use Common\Model\RetailGoodsBannerModel;
|
||
use Common\Model\RetailGoodsClassModel;
|
||
use Common\Model\RetailGoodsModel;
|
||
use Common\Model\RetailMerchantModel;
|
||
use Common\Model\RetailMgoodsModel;
|
||
use Common\Model\RetailSkuGoodsModel;
|
||
use Common\Model\SkuGoodsViewModel;
|
||
use Common\Model\SSaleMGoodsModel;
|
||
use Common\Business\GoodsSplit;
|
||
use Retail\Business\Goods as GoodsClass;
|
||
|
||
//[1.9.3]
|
||
|
||
/**
|
||
* 门店商品档案管理
|
||
* Class GoodsController
|
||
* @package Retail\Controller
|
||
*/
|
||
class GoodsController extends BaseController
|
||
{
|
||
/* @var array $allowAllAction 登录验证白名单 无需检测身份类型 */
|
||
protected $allowAllAction = array(
|
||
'getGoodsYieldlyList', //获取产地列表
|
||
'addGoodsYieldly', //新增产地
|
||
);
|
||
|
||
public function _initialize()
|
||
{
|
||
parent::_initialize(); // TODO: Change the autogenerated stub
|
||
if (!$this->store_id && !in_array(ACTION_NAME, $this->allowAllAction)) {
|
||
if (IS_GET) {
|
||
$this->error('登录超时,请重新登录');
|
||
exit;
|
||
} else if (IS_POST) {
|
||
$res = array('status' => 0, 'msg' => '登录超时,请重新登录');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
//获取商户平台类型 1默认系统 2微礼平台
|
||
public function getPlatformType()
|
||
{
|
||
$result = [
|
||
'status' => 1,
|
||
'message' => '获取成功',
|
||
'platform_type' => $this->role_info['platform_type'] ? $this->role_info['platform_type'] : 1
|
||
];
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
/**
|
||
* 商品分类 页面
|
||
*/
|
||
public function goods_cate()
|
||
{
|
||
$arr = array(
|
||
'goodsclass' => '/index.php/Retail/exporttable/goodsclass',
|
||
'changeClassOnlineState' => '/index.php/Retail/Goods/changeClassOnlineState',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$this->assign('identity', self::$identity);
|
||
$this->assign("global_store_jurisdiction", self::$global_store_jurisdiction);
|
||
$this->display();
|
||
}
|
||
|
||
/**
|
||
* 获取分类列表接口
|
||
*/
|
||
public function getGoodsClass()
|
||
{
|
||
$type = I('post.type');
|
||
$pid = I('post.pid');
|
||
$page = I('post.page');
|
||
if (!empty($type) && (!empty($pid) || empty($pid) && $type == 1) && !empty($page)) {
|
||
$GoodsClassModel = new RetailGoodsClassModel();
|
||
$map = array(
|
||
'c.' . $GoodsClassModel::MERCHANT_ID => $this->merchant_id,
|
||
'c.' . $GoodsClassModel::TYPE => $type,
|
||
'c.' . $GoodsClassModel::STATUS => 0,
|
||
);
|
||
if (!empty($pid)) {
|
||
$map['c.' . $GoodsClassModel::PID] = $pid;
|
||
}
|
||
$limit = 20;
|
||
$fields = array(
|
||
'c.' . $GoodsClassModel::ID,
|
||
'c.' . $GoodsClassModel::CLASS_NAME,
|
||
'c.' . $GoodsClassModel::CODE,
|
||
'c.' . $GoodsClassModel::PID,
|
||
's.online_state',
|
||
);
|
||
$list = $GoodsClassModel->alias('c')
|
||
->join('ls_store_goods_class as s on c.id=s.class_id AND s.store_id=' . $this->store_id, 'LEFT')
|
||
->field($fields)
|
||
->where($map)
|
||
->order('c.' . $GoodsClassModel::CODE . ' asc')
|
||
->page($page, $limit)
|
||
->select();
|
||
foreach ($list as &$value) {
|
||
if ($type == 1 || $type == 2) {
|
||
$value['page'] = 0;
|
||
$value['list'] = array();
|
||
}
|
||
$value['online_state'] = $value['online_state'] == 1 ? '1' : '0';
|
||
}
|
||
|
||
$res['status'] = 1;
|
||
$res['msg'] = $list ? '获取成功' : '暂无分类';
|
||
$res['limit'] = $limit;
|
||
$res['data'] = $list;
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请求参数有误';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 修改分类线上显示状态
|
||
*/
|
||
public function changeClassOnlineState()
|
||
{
|
||
$id = I('post.id');
|
||
$state = I('post.state');
|
||
if (!$id || !isset($state)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请求参数有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$StoreClassModel = D('StoreGoodsClass');
|
||
$map = array(
|
||
$StoreClassModel::STORE_ID => $this->store_id,
|
||
$StoreClassModel::CLASS_ID => $id,
|
||
);
|
||
$old = $StoreClassModel->getFind($map);
|
||
if (empty($old)) {
|
||
$item = array(
|
||
$StoreClassModel::MERCHANT_ID => $this->merchant_id,
|
||
$StoreClassModel::STORE_ID => $this->store_id,
|
||
$StoreClassModel::CLASS_ID => $id,
|
||
$StoreClassModel::ONLINE_STATE => $state,
|
||
$StoreClassModel::ADD_TIME => time(),
|
||
);
|
||
$res = $StoreClassModel->addOrder($item);
|
||
} else {
|
||
$save = array(
|
||
$StoreClassModel::ONLINE_STATE => $state,
|
||
);
|
||
$res = $StoreClassModel->updateOrder($map, $save);
|
||
}
|
||
if ($res) {
|
||
//操作日志记录
|
||
$source = 0;//请求来源: 0pc系统 1小助手
|
||
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST);//请求参数 json数据
|
||
if ($state == 1) {
|
||
$desc = '商品分类-开启商城显示';//操作行为描述
|
||
} elseif ($state == 0) {
|
||
$desc = '商品分类-关闭商城显示';//操作行为描述
|
||
}
|
||
action_log($source, $type, $request_data, $desc);
|
||
|
||
$result['status'] = 1;
|
||
$result['msg'] = '保存成功';
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '保存失败';
|
||
}
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
/**
|
||
* 商品案例(列表)
|
||
*/
|
||
public function goods()
|
||
{
|
||
$this->display();
|
||
}
|
||
|
||
public function createss()
|
||
{
|
||
$data = [];
|
||
for ($i = 0; $i < 30; $i++) {
|
||
$data[] = $i;
|
||
}
|
||
return $data;
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取商品列表
|
||
*/
|
||
public function goodsList()
|
||
{
|
||
$param = array(
|
||
'platform_type' => $this->role_info['platform_type'],
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'showpurch_price' => self::$global_store_jurisdiction['showpurch_price'], //进价查看权限
|
||
'identity' => I('session.identity'), //用户身份
|
||
'page' => I('post.page') ? I('post.page') : 1, //页
|
||
'limit' => I('post.limit') ? I('post.limit') : 10, //每页数量
|
||
'need_img' => true, //是否需要图片
|
||
'need_goods_num' => true, //是否需要库存
|
||
'need_count' => true, //是否需要总数量
|
||
'status' => I('post.status'), //是否需要总数量
|
||
'order_type' => I("post.order_type"), //排序规则
|
||
'condition_name' => I("post.condition_name"), //排序规则关键词
|
||
'recovery_type' => I('post.recovery_type'), //2回收站
|
||
'attribute_state' => I('post.attribute_state'), //规格 1无规格 2多规格
|
||
'online_state' => I('post.online_state'), //规格 1商城出售 0非商城出售 空不限制
|
||
'advance_sale_status' => I('post.advance_sale_status'), //预售 1商城预售 0非商城预售 空不限制
|
||
// 按照商品类别搜索
|
||
'person1' => I('post.person1'),
|
||
'person2' => I('post.person2'),
|
||
'person3' => I('post.person3'),
|
||
'pricing_method' => I('post.pricing_method'),
|
||
'keyword_type' => I('post.keyword_type'), //关键词搜索类型 1货号 2条码 3名称
|
||
'keyword' => I('post.keyword'), //搜索关键词
|
||
);
|
||
$SkuGoodsViewModel = new SkuGoodsViewModel();
|
||
$ret = $SkuGoodsViewModel->getGoodsList($param);
|
||
$this->ajaxReturn($ret);
|
||
}
|
||
|
||
/**
|
||
* 删除单个商品
|
||
*/
|
||
public function singleDelete()
|
||
{
|
||
if (IS_POST) {
|
||
$id = I('post.id');
|
||
$goodsInfo = M('retail_goods')->where(array('id' => $id))->find();
|
||
if ($goodsInfo) {
|
||
$delete = M('retail_goods')->where(array('id' => $id))->setField('status', 2);
|
||
if ($delete) {
|
||
//同步删除推荐商品
|
||
M("retail_host")->where(array('goods_id' => $id))->delete();
|
||
if ($goodsInfo['attribute_state'] == 2) {
|
||
//规格状态修改
|
||
M('retail_sku_goods')->where(array('goods_id' => $id))->save(array('state' => 1));
|
||
}
|
||
//删除销售库商品
|
||
$success = $this->updateSaleGoods($id, $sku_id = '', 2);
|
||
if ($success) {
|
||
//操作日志记录
|
||
$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 xcxgoods()
|
||
{
|
||
//查询出该门店可用分类
|
||
$class_name = M('retail_goods_class')->where(array('merchantid' => $this->merchant_id, 'status' => 0, 'type' => 1))->order('code desc')->select();
|
||
$this->assign('class_name', $class_name);
|
||
$this->display();
|
||
}
|
||
|
||
//小程序商城商品明细 异步获取数据 渲染layer表格
|
||
public function xcxgoodsList()
|
||
{
|
||
//接收查询条件
|
||
$goodnumber = $_POST['goods_number'];
|
||
if (!empty($goodnumber)) {
|
||
$where['goods_number|goods_name'] = array('like', '%' . $goodnumber . '%');
|
||
}
|
||
//按照商品类别搜索
|
||
$person1 = I('post.person1');
|
||
$person2 = I('post.person2');
|
||
$person3 = I('post.person3');
|
||
$flag = 0;
|
||
if (!empty($person3)) {
|
||
$where['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);
|
||
$where['goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1));
|
||
} else if ($flag == 1) {
|
||
$where['goods_class_id'] = $person2 ? $person2 : $person1;
|
||
}
|
||
$where['online_state'] = 1;
|
||
$where['store_id'] = $this->store_id;
|
||
$where['status'] = array('in', array(0, 1));
|
||
//商品列表
|
||
$goods = M('retail_goods')->page($_POST['page'], $_POST['limit'])->order('status asc')->where($where)->order('id asc')->select();
|
||
$goods_count = M('retail_goods')->where($where)->count();
|
||
foreach ($goods as $key => &$value) {
|
||
//查询出分类名称
|
||
$value['cate_name'] = M('retail_goods_class')->where(array('id' => $value['goods_class_id']))->getField('class_name');
|
||
//判断出商品的状态以及是否允许修改折扣价
|
||
//商品状态
|
||
if ($value['status'] == 0) {
|
||
$value['status_name'] = '正常';
|
||
} elseif ($value['status'] == 1) {
|
||
$value['status_name'] = '已下架';
|
||
} elseif ($value['status'] == 2) {
|
||
$value['status_name'] = '已删除';
|
||
}
|
||
if ($value['plus_mem_status'] == 2) {
|
||
$value['plus_price'] = '未开启';
|
||
} else if ($value['plus_mem_status'] == 1 && $value['attribute'] == 2) {
|
||
$value['plus_price'] = '规格plus会员价';
|
||
}
|
||
//是否允许修改折扣价
|
||
if ($value['canchangeprice'] == 1) {
|
||
$value['canchangeprice_name'] = '是';
|
||
} else {
|
||
$value['canchangeprice_name'] = '不允许';
|
||
}
|
||
if ($value['online_state'] == 0) {
|
||
$value['issellonline_name'] = '否';
|
||
} else {
|
||
$value['issellonline_name'] = '是';
|
||
}
|
||
//线上积分购
|
||
if ($value['vip_online_state'] == 1) {
|
||
$value['vip_online_state'] = '开启';
|
||
} else {
|
||
$value['vip_online_state'] = '关闭';
|
||
}
|
||
$value['goods_code'] = $value['goods_code'] ? $value['goods_code'] : '';
|
||
$value['goods_number'] = $value['goods_number'] ? $value['goods_number'] : '';
|
||
$value['goods_num'] = A('Api/Inventory')->goods_num(2, $this->store_id, $value['id']);
|
||
if ($value['attribute_state'] == 2) {
|
||
$value['purchase_price'] = '规格成本价';
|
||
}
|
||
}
|
||
$rt['code'] = 0;
|
||
$rt['msg'] = '';
|
||
$rt['count'] = $goods_count;
|
||
$rt['data'] = $goods;
|
||
$this->ajaxReturn($rt);
|
||
}
|
||
|
||
// 编辑商品商城出售状态
|
||
public function changeissellonline()
|
||
{
|
||
if (IS_POST) {
|
||
$id = I('post.id');
|
||
$ist = I('post.online_state');
|
||
$goods_class_id = I('post.goods_class_id');
|
||
$ret = M('retail_goods')->where(array('store_id' => $this->store_id, 'id' => $id))->save(array('online_state' => $ist));
|
||
if ($ret) {
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
if ($ist == 0) {
|
||
$desc = '商品档案-关闭商城出售'; //操作行为描述
|
||
} elseif ($ist == 1) {
|
||
$desc = '商品档案-开启商城出售'; //操作行为描述
|
||
}
|
||
action_log($source, $type, $request_data, $desc);
|
||
|
||
if ($ist) {
|
||
$this->goodsClassSwitch($goods_class_id);
|
||
}
|
||
$rt['status'] = 1;
|
||
$rt['msg'] = '操作成功';
|
||
} else {
|
||
$rt['status'] = 2;
|
||
$rt['msg'] = '操作失败';
|
||
}
|
||
$this->ajaxReturn($rt);
|
||
}
|
||
}
|
||
|
||
// 编辑商品店内出售状态
|
||
public function changeRetailState()
|
||
{
|
||
if (IS_POST) {
|
||
$id = I('post.id');
|
||
$retail_state = I('post.retail_state');
|
||
$goods_class_id = I('post.goods_class_id');
|
||
$GoodsModel = new RetailGoodsModel();
|
||
$ret = $GoodsModel->updateOrder(array('store_id' => $this->store_id, 'id' => $id), array('retail_state' => $retail_state));
|
||
if ($ret) {
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
if ($retail_state == 0) {
|
||
$desc = '商品档案-关闭店内出售'; //操作行为描述
|
||
} elseif ($retail_state == 1) {
|
||
$desc = '商品档案-开启店内出售'; //操作行为描述
|
||
}
|
||
action_log($source, $type, $request_data, $desc);
|
||
|
||
if ($retail_state) {
|
||
$this->goodsClassSwitch($goods_class_id);
|
||
}
|
||
$rt['status'] = 1;
|
||
$rt['msg'] = '操作成功';
|
||
} else {
|
||
$rt['status'] = 2;
|
||
$rt['msg'] = '操作失败';
|
||
}
|
||
$this->ajaxReturn($rt);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 门店商品分类开启
|
||
* $goods_clas_id 门店分类id
|
||
*/
|
||
public function goodsClassSwitch($goods_class_id)
|
||
{
|
||
$StoreGoodsClassModel = D("StoreGoodsClass");
|
||
$where = array(
|
||
$StoreGoodsClassModel::CLASS_ID => $goods_class_id,
|
||
$StoreGoodsClassModel::STORE_ID => $this->store_id
|
||
);
|
||
$inline_state = $StoreGoodsClassModel->getFindField($where, $StoreGoodsClassModel::ONLINE_STATE);
|
||
if (!$inline_state) {
|
||
$GoodsClassModel = D("RetailGoodsClass");
|
||
$where = array(
|
||
$GoodsClassModel::ID => $goods_class_id
|
||
);
|
||
$fields = $GoodsClassModel::PID . ',' . $GoodsClassModel::TYPE;
|
||
$goods_class = $GoodsClassModel->getFind($where, $fields);
|
||
if ($inline_state == '0') {
|
||
//关闭状态
|
||
$class_id = array(); //修改状态的分类id
|
||
$class_id[] = $goods_class_id;
|
||
} else {
|
||
//添加新的分类
|
||
$add_class_id = array(); //要添加的分类id
|
||
$add_class_id[] = $goods_class_id;
|
||
}
|
||
switch ($goods_class[$GoodsClassModel::TYPE]) {
|
||
case 2:
|
||
if ($inline_state == '0') {
|
||
$class_id[] = $goods_class[$GoodsClassModel::PID];
|
||
} else {
|
||
$where = array(
|
||
$StoreGoodsClassModel::CLASS_ID => $goods_class[$GoodsClassModel::PID],
|
||
$StoreGoodsClassModel::STORE_ID => $this->store_id
|
||
);
|
||
$store_class_id = $StoreGoodsClassModel->getFind($where, $StoreGoodsClassModel::ID);
|
||
if (!$store_class_id) {
|
||
$add_class_id[] = $goods_class[$GoodsClassModel::PID];
|
||
}
|
||
}
|
||
break;
|
||
case 3:
|
||
if ($inline_state == '0') {
|
||
$class_id[] = $goods_class[$GoodsClassModel::PID];
|
||
$where = array(
|
||
$GoodsClassModel::ID => $goods_class[$GoodsClassModel::PID]
|
||
);
|
||
$class_id[] = $GoodsClassModel->getFindField($where, $GoodsClassModel::PID);
|
||
} else {
|
||
$where = array(
|
||
$StoreGoodsClassModel::CLASS_ID => $goods_class[$GoodsClassModel::PID],
|
||
$StoreGoodsClassModel::STORE_ID => $this->store_id
|
||
);
|
||
$store_class_id = $StoreGoodsClassModel->getFind($where, $StoreGoodsClassModel::ID);
|
||
if (!$store_class_id) {
|
||
$add_class_id[] = $goods_class[$GoodsClassModel::PID];
|
||
}
|
||
$where = array(
|
||
$GoodsClassModel::ID => $goods_class[$GoodsClassModel::PID]
|
||
);
|
||
$class_pid = $GoodsClassModel->getFindField($where, $GoodsClassModel::PID);
|
||
$where = array(
|
||
$StoreGoodsClassModel::CLASS_ID => $class_pid,
|
||
$StoreGoodsClassModel::STORE_ID => $this->store_id
|
||
);
|
||
$store_class_id = $StoreGoodsClassModel->getFind($where, $StoreGoodsClassModel::ID);
|
||
if (!$store_class_id) {
|
||
$add_class_id[] = $class_pid;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
if (!empty($add_class_id)) {
|
||
$data = array(
|
||
$StoreGoodsClassModel::STORE_ID => $this->store_id,
|
||
$StoreGoodsClassModel::MERCHANT_ID => $this->merchant_id,
|
||
$StoreGoodsClassModel::ONLINE_STATE => 1,
|
||
);
|
||
foreach ($add_class_id as $val) {
|
||
$data[$StoreGoodsClassModel::CLASS_ID] = $val;
|
||
$StoreGoodsClassModel->addOrder($data);
|
||
}
|
||
} else if (!empty($class_id)) {
|
||
$where = array(
|
||
$StoreGoodsClassModel::CLASS_ID => array('in', $class_id),
|
||
$StoreGoodsClassModel::STORE_ID => $this->store_id
|
||
);
|
||
$save = $StoreGoodsClassModel->updateOrder($where, array($StoreGoodsClassModel::ONLINE_STATE => 1));
|
||
}
|
||
return $save;
|
||
} else {
|
||
return $inline_state;
|
||
}
|
||
}
|
||
|
||
// 编辑商品上下架状态
|
||
public function changestatus()
|
||
{
|
||
if (IS_POST) {
|
||
$id = I('post.id');
|
||
$ist = I('post.status');
|
||
$ret = M('retail_goods')->where(array('store_id' => $this->store_id, 'id' => $id))->save(array('status' => $ist));
|
||
if ($ret) {
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
if ($ist == 0) {
|
||
$desc = '商品档案-开启状态'; //操作行为描述
|
||
} elseif ($ist == 1) {
|
||
$desc = '商品档案-关闭状态'; //操作行为描述
|
||
}
|
||
action_log($source, $type, $request_data, $desc);
|
||
|
||
$this->updateSaleGoods($id, $sku_id = "", $ist);
|
||
$rt['status'] = 1;
|
||
$rt['msg'] = '操作成功';
|
||
} else {
|
||
$rt['status'] = 2;
|
||
$rt['msg'] = '操作失败';
|
||
}
|
||
$this->ajaxReturn($rt);
|
||
}
|
||
}
|
||
|
||
// 编辑状态 常用商品设置
|
||
public function changeusualDemo()
|
||
{
|
||
if (IS_POST) {
|
||
$id = I('post.id');
|
||
$ist = I('post.usual_state');
|
||
$ret = M('retail_goods')->where(array('store_id' => $this->store_id, 'id' => $id))->save(array('usual_state' => $ist));
|
||
if ($ret) {
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
if ($ist == 1) {
|
||
$desc = '商品档案-关闭常用'; //操作行为描述
|
||
} elseif ($ist == 2) {
|
||
$desc = '商品档案-开启常用'; //操作行为描述
|
||
}
|
||
action_log($source, $type, $request_data, $desc);
|
||
|
||
$rt['status'] = 1;
|
||
$rt['msg'] = '操作成功';
|
||
} else {
|
||
$rt['status'] = 2;
|
||
$rt['msg'] = '操作失败';
|
||
}
|
||
$this->ajaxReturn($rt);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 同步商户商品
|
||
*/
|
||
public function sync_goods()
|
||
{
|
||
$GoodsClassify = new GoodsClassify();
|
||
$result = $GoodsClassify->getGoodsClassTopLevel($this->merchant_id);
|
||
$this->assign('goodsClass1', json_encode($result['data']['list']));
|
||
$this->display();
|
||
}
|
||
|
||
/**
|
||
* 更新已同步的商品
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @throws \think\exception\DbException
|
||
*/
|
||
public function two_sync_goods()
|
||
{
|
||
//查询出该门店可用分类
|
||
$class_name = M('retail_goods_class')->where(array('merchantid' => $this->merchant_id, 'status' => 0, 'type' => 1))->order('code asc')->select();
|
||
|
||
$this->assign('class_name', $class_name);
|
||
$this->display();
|
||
}
|
||
|
||
// 编辑会员线上打折状态
|
||
public function changevip_online_state()
|
||
{
|
||
if (IS_POST) {
|
||
$id = I('post.id');
|
||
$ist = I('post.vip_online_state');
|
||
$ret = M('retail_goods')->where(array('store_id' => $this->store_id, 'id' => $id))->save(array('vip_online_state' => $ist));
|
||
if ($ret) {
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
if ($ist == 0) {
|
||
$desc = '商品档案-关闭线上打折'; //操作行为描述
|
||
} elseif ($ist == 1) {
|
||
$desc = '商品档案-开启线上打折'; //操作行为描述
|
||
}
|
||
action_log($source, $type, $request_data, $desc);
|
||
|
||
$rt['status'] = 1;
|
||
$rt['msg'] = '操作成功';
|
||
} else {
|
||
$rt['status'] = 2;
|
||
$rt['msg'] = '操作失败';
|
||
}
|
||
$this->ajaxReturn($rt);
|
||
}
|
||
}
|
||
|
||
// 编辑会员线下打折状态
|
||
public function changevip_retail_state()
|
||
{
|
||
if (IS_POST) {
|
||
$id = I('post.id');
|
||
$ist = I('post.vip_retail_state');
|
||
$ret = M('retail_goods')->where(array('store_id' => $this->store_id, 'id' => $id))->save(array('vip_retail_state' => $ist));
|
||
if ($ret) {
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
if ($ist == 0) {
|
||
$desc = '商品档案-关闭线下打折'; //操作行为描述
|
||
} elseif ($ist == 1) {
|
||
$desc = '商品档案-开启线下打折'; //操作行为描述
|
||
}
|
||
action_log($source, $type, $request_data, $desc);
|
||
|
||
$rt['status'] = 1;
|
||
$rt['msg'] = '操作成功';
|
||
} else {
|
||
$rt['status'] = 2;
|
||
$rt['msg'] = '操作失败';
|
||
}
|
||
$this->ajaxReturn($rt);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 10-27 查询商品库信息
|
||
* */
|
||
public function checkgoods()
|
||
{
|
||
$code = I('post.code');
|
||
if (empty($code)) {
|
||
$this->ajaxReturn(['status' => 0, 'msg' => '请输入条码']);
|
||
}
|
||
$merchantModel = new RetailMerchantModel();
|
||
$partner_id = $merchantModel->getFindField(['id' => $this->merchant_id], "partnerid");
|
||
$goods = new Goods();
|
||
$result = $goods->basisCodeGetGoodsInfo($code, $partner_id); //2表示门店查询
|
||
if ($result['status'] == 1) {
|
||
$res = [
|
||
'status' => 1,
|
||
'msg' => '查询成功',
|
||
'data' => $result['data']['goods']
|
||
];
|
||
} else {
|
||
$res = [
|
||
'status' => 0,
|
||
'msg' => '未找到该商品'
|
||
];
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
|
||
//+=======================================================================
|
||
//- usb标签打印机批量打印商品标签 2018-12-22
|
||
//+=======================================================================
|
||
public function downloadLabel()
|
||
{
|
||
$class_name = M('retail_goods_class')->where(array('merchantid' => $this->merchant_id, 'status' => 0, 'type' => 1))->order('code asc')->select();
|
||
|
||
|
||
$this->assign('class_name', $class_name);
|
||
$arr = array(
|
||
'downloadSkuLabel' => '/index.php/Retail/Goods/downloadSkuLabel',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$this->display();
|
||
}
|
||
|
||
/**
|
||
* 批量更换商品分类
|
||
*/
|
||
public function move_class()
|
||
{
|
||
//查询出该门店可用分类
|
||
$class_name = M('retail_goods_class')->where(array('merchantid' => $this->merchant_id, 'status' => 0, 'type' => 1))->order('code asc')->select();
|
||
$this->assign('class_name', $class_name);
|
||
$this->display();
|
||
}
|
||
|
||
/**
|
||
* 获取某个分类下的商品
|
||
* @throws \think\Exception
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @throws \think\exception\DbException
|
||
*/
|
||
public function goodsMoveList()
|
||
{
|
||
//接收查询条件
|
||
$keyword = I('get.keyword');
|
||
if (!empty($keyword)) {
|
||
$keyword = trim($keyword, ' ');
|
||
$where['g.goods_name|g.goods_number|g.goods_code'] = array('like', '%' . $keyword . '%');
|
||
}
|
||
//按照商品类别搜索
|
||
$person1 = I('get.person1');
|
||
$person2 = I('get.person2');
|
||
$person3 = I('get.person3');
|
||
$flag = 0;
|
||
if (!empty($person3)) {
|
||
$where['g.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);
|
||
$where['g.goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1));
|
||
} else if ($flag == 1) {
|
||
$where['g.goods_class_id'] = $person2 ? $person2 : $person1;
|
||
}
|
||
$where['g.store_id'] = $this->store_id;
|
||
$where['g.status'] = array('in', '0,1');
|
||
$goods_count = M('retail_goods as g')->where($where)->count();
|
||
$goods = M('retail_goods as g')
|
||
->join('ls_retail_goods_class as c on c.id=g.goods_class_id')
|
||
->where($where)->page($_GET['page'], $_GET['limit'])
|
||
->order('g.goods_number desc')
|
||
->field('g.goods_name,g.goods_number,g.goods_code,g.id,c.class_name,c.id as c_id,c.pid,c.type,c.class_name')
|
||
->select();
|
||
foreach ($goods as &$val) {
|
||
if ($val['type'] == 2) {
|
||
$class1 = M('retail_goods_class')->where(array('id' => $val['pid']))->getField('class_name');
|
||
$val['class_name'] = $class1 . '/' . $val['class_name'];
|
||
} else if ($val['type'] == 3) {
|
||
$class1 = M('retail_goods_class as c1')
|
||
->join('ls_retail_goods_class as c2 on c2.pid=c1.id')
|
||
->where(array('c2.id' => $val['pid']))
|
||
->field('c1.class_name,c2.class_name as c2_class_name')
|
||
->find();
|
||
$val['class_name'] = $class1['class_name'] . '/' . $class1['c2_class_name'] . '/' . $val['class_name'];
|
||
}
|
||
}
|
||
$rt['code'] = 0;
|
||
$rt['msg'] = '';
|
||
$rt['count'] = $goods_count;
|
||
$rt['data'] = $goods;
|
||
$this->ajaxReturn($rt);
|
||
}
|
||
|
||
//修改商品分类
|
||
public function moveGoodsClass()
|
||
{
|
||
$goodsIds = I('post.goodsIds');
|
||
$class_id = I('post.class_id');
|
||
if (empty($goodsIds) || empty($class_id)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '缺少参数';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$class = M('retail_goods_class as c')
|
||
->join('ls_retail_goods_class as c1 on c1.pid=c.id AND c1.status=0', 'LEFT')
|
||
->where(array('c.id' => $class_id, 'c.status' => 0))
|
||
->field('c.*,c1.id as c1_id')
|
||
->select();
|
||
if (empty($class)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '分类不存在';
|
||
} else if (!empty($class['c1_id'])) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请选择到底级分类';
|
||
} else {
|
||
$update = M('retail_goods')->where(array('id' => array('in', $goodsIds), 'store_id' => $this->store_id))->save(array('goods_class_id' => $class_id));
|
||
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);
|
||
|
||
$this->moveSaleClass($goodsIds, $class_id);
|
||
$res['status'] = 1;
|
||
$res['msg'] = '修改成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '修改失败请重试';
|
||
}
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 供给仓批量修改分类
|
||
* @param $goodsIds 商品id
|
||
* @param $class_id 分类id
|
||
*
|
||
*/
|
||
protected function moveSaleClass($goodsIds, $class_id)
|
||
{
|
||
if (!empty($goodsIds) && !empty($class_id)) {
|
||
$where = array(
|
||
'store_id' => $this->store_id,
|
||
'goods_id' => array('in', $goodsIds),
|
||
);
|
||
$data = array(
|
||
'goods_class_id' => $class_id
|
||
);
|
||
$save = D("SSaleMGoods")->updateData($where, $data);
|
||
}
|
||
return $save;
|
||
}
|
||
|
||
/**
|
||
* 批量删除商品
|
||
* */
|
||
public function delete_goods()
|
||
{
|
||
//查询出该门店可用分类
|
||
$class_name = M('retail_goods_class')->where(array('merchantid' => $this->merchant_id, 'status' => 0, 'type' => 1))->order('code asc')->select();
|
||
$this->assign('class_name', $class_name);
|
||
$this->display();
|
||
}
|
||
|
||
//获取需要批量删除的商品列表
|
||
public function delete_goods_list()
|
||
{
|
||
$keyword = I('get.keyword');
|
||
if (!empty($keyword)) {
|
||
$keyword = trim($keyword, ' ');
|
||
$where['goods_name|goods_number|goods_code'] = array('like', '%' . $keyword . '%');
|
||
}
|
||
//按照商品类别搜索
|
||
$person1 = I('get.person1');
|
||
$person2 = I('get.person2');
|
||
$person3 = I('get.person3');
|
||
$flag = 0;
|
||
if (!empty($person3)) {
|
||
$where['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);
|
||
$where['goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1));
|
||
} else if ($flag == 1) {
|
||
$where['goods_class_id'] = $person2 ? $person2 : $person1;
|
||
}
|
||
$where['store_id'] = $this->store_id;
|
||
$where['status'] = array('in', '0,1');
|
||
$page = I('get.page');
|
||
$limit = I('get.limit');
|
||
$goods_info = M('retail_goods')->where($where)->page($page, $limit)->order('add_time desc')->select();
|
||
$count = M('retail_goods')->where($where)->count();
|
||
if ($goods_info) {
|
||
$data['code'] = 0;
|
||
$data['data'] = $goods_info;
|
||
$data['count'] = $count;
|
||
$data['msg'] = '';
|
||
} else {
|
||
$data['code'] = 0;
|
||
$data['data'] = array();
|
||
$data['count'] = 0;
|
||
$data['msg'] = '';
|
||
}
|
||
$this->ajaxReturn($data);
|
||
}
|
||
|
||
//批量删除商品
|
||
public function delete_goods_act()
|
||
{
|
||
$goodslist = I('post.delList');
|
||
$where['id'] = array('in', $goodslist);
|
||
$save = M('retail_goods')->where($where)->save(array('status' => 2));
|
||
if ($save) {
|
||
M("retail_host")->where(array('goods_id' => array('in', $goodslist)))->delete();
|
||
//规格删除
|
||
M('retail_sku_goods')->where(array('goods_id' => array('in', $goodslist)))->save(array('state' => 1));
|
||
$success = $this->updateSaleGoods($goodslist, $sku_id = "", 2);
|
||
if ($success) {
|
||
//操作日志记录
|
||
$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'] = '操作失败';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//商品价格批量修改页面
|
||
public function updateGoods($id)
|
||
{
|
||
$ids = trim($id, ',');
|
||
$this->assign('ids', $ids);
|
||
$this->display();
|
||
}
|
||
|
||
/**
|
||
* 批量下载规格条码
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @throws \think\exception\DbException
|
||
*/
|
||
public function downloadSkuLabel()
|
||
{
|
||
$id = I('get.id');
|
||
$goods = M('retail_goods')->where(array('id' => $id))->field('id,goods_name')->find();
|
||
$this->assign('goods', json_encode($goods));
|
||
$this->display();
|
||
}
|
||
|
||
/**
|
||
* 自动获取获取货号
|
||
*/
|
||
public function auto_number()
|
||
{
|
||
if (IS_POST) {
|
||
$i = 0;
|
||
while (1) {
|
||
$num = rand(1000, 99999);
|
||
$where['store_id'] = $this->store_id;
|
||
$where['goods_number'] = $num;
|
||
$where['status'] = array('in', '0,1');
|
||
$info = M('retail_goods')->where($where)->field('id')->find();
|
||
if (empty($info)) {
|
||
$res['status'] = 1;
|
||
$res['info'] = $num;
|
||
$res['msg'] = '获取成功';
|
||
$this->ajaxReturn($res);
|
||
break;
|
||
}
|
||
$i++;
|
||
if ($i > 30) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '获取失败,请重试';
|
||
$this->ajaxReturn($res);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取批量修改的商品
|
||
* ids 商品id
|
||
* return Array
|
||
* */
|
||
public function get_update_goods_list()
|
||
{
|
||
$user = I('session.ls_userinfo');
|
||
$ids = I('post.ids');
|
||
if (!$ids) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数缺失';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$map['id'] = array('in', $ids);
|
||
$map['store_id'] = $this->store_id;
|
||
$map['merchant_id'] = $this->merchant_id;
|
||
$goods_list = M('retail_goods')->field('id,goods_name,goods_number,goods_code,retail_price,online_price,store_mem_status,store_mem_price,shop_mem_status,shop_mem_price,pricing_method,attribute_state,plus_price,plus_mem_status')->where($map)->select();
|
||
if (!$goods_list) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '未查询到修改数据';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
foreach ($goods_list as &$val) {
|
||
$val['retail_price'] = floatval($val['retail_price']);
|
||
$val['online_price'] = floatval($val['online_price']);
|
||
$val['store_mem_price'] = floatval($val['store_mem_price']);
|
||
$val['shop_mem_price'] = floatval($val['shop_mem_price']);
|
||
$val['attribute_name'] = $val['attribute_state'] == 1 ? '无规格' : '有规格';
|
||
$val['goods_num'] = A('Api/Inventory')->goods_num(2, $this->store_id, $val['id']);
|
||
}
|
||
$res['status'] = 1;
|
||
$res['goods_list'] = $goods_list;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 批量修改商品数据
|
||
* goods_list Array
|
||
* return Array
|
||
* */
|
||
public function batch_save_goods()
|
||
{
|
||
$goods_list = I('post.goods_list');
|
||
if (!$goods_list) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数缺失';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$msg = '';
|
||
$msg_code = '';
|
||
$msg_goods_num = '';
|
||
$msg_sku_weigh = '';
|
||
$codeArr = array();
|
||
$numberArr = array();
|
||
$reg1 = "/^\+?[0-9][0-9]*$/";
|
||
$reg2 = "/^[0-9]+(.[0-9]{1,3})?$/";
|
||
foreach ($goods_list as $key => &$val) {
|
||
$find = M('retail_goods')->where(array('goods_number' => $val['goods_number'], 'store_id' => $this->store_id, 'id' => array('neq', $val['id']), 'status' => 0))->find();
|
||
if ($find || in_array($val['goods_number'], $numberArr)) {
|
||
$msg .= ($key + 1) . ',';
|
||
} else {
|
||
$numberArr[] = $val['goods_number'];
|
||
}
|
||
unset($find);
|
||
if (!empty($val['goods_code'])) {
|
||
$find = M('retail_goods')->where(array('goods_code' => $val['goods_code'], 'store_id' => $this->store_id, 'id' => array('neq', $val['id']), 'status' => 0))->find();
|
||
if ($find || in_array($val['goods_code'], $codeArr)) {
|
||
$msg_code .= ($key + 1) . ',';
|
||
} else {
|
||
$codeArr[] = $val['goods_code'];
|
||
}
|
||
}
|
||
if ($val['pricing_method'] == 2 && !preg_match($reg2, abs($val['goods_num']))) {
|
||
$msg_goods_num .= ($key + 1) . ',';
|
||
} else if ($val['pricing_method'] == 1 && !preg_match($reg1, abs($val['goods_num']))) {
|
||
$msg_goods_num .= ($key + 1) . ',';
|
||
}
|
||
if ($val['attribute_state'] == 2 && $val['pricing_method'] == 2) {
|
||
$msg_sku_weigh .= ($key + 1) . ',';
|
||
}
|
||
}
|
||
if (trim($msg, ',')) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '第' . trim($msg, ',') . '条商品货号已存在';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
if (trim($msg_code, ',')) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '第' . trim($msg_code, ',') . '条商品条码已存在';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$result = $this->batch_update_goods($goods_list);
|
||
if ($result['status'] == 1) {
|
||
//操作日志记录
|
||
$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'] = $result['msg'];
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = $result['msg'];
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 批量修改商品数据
|
||
* goods_list Array
|
||
* return Array
|
||
* */
|
||
protected function batch_update_goods($goods_list)
|
||
{
|
||
$record = 0;
|
||
foreach ($goods_list as $key => &$val) {
|
||
$content = array();
|
||
$find = M('retail_goods')->where(array('id' => $val['id']))->find();
|
||
if (!$find) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '第' . ($key + 1) . '条查询失败';
|
||
return $res;
|
||
}
|
||
if ($val['goods_name'] != $find['goods_name']) {
|
||
$up['goods_name'] = $val['goods_name'];
|
||
$content['goods_name'] = $val['goods_name'];
|
||
}
|
||
if ($val['goods_number'] != $find['goods_number']) {
|
||
$up['goods_number'] = $val['goods_number'];
|
||
$content['goods_number'] = $val['goods_number'];
|
||
}
|
||
if ($val['goods_code'] != $find['goods_code']) {
|
||
$up['goods_code'] = $val['goods_code'];
|
||
$content['goods_code'] = $val['goods_code'];
|
||
}
|
||
if ($val['pricing_method'] != $find['pricing_method']) {
|
||
$up['pricing_method'] = $val['pricing_method'];
|
||
$content['pricing_method'] = $val['pricing_method'];
|
||
}
|
||
if ($val['retail_price'] != $find['retail_price']) {
|
||
$up['retail_price'] = round($val['retail_price'], 2);
|
||
}
|
||
if ($val['online_price'] != $find['online_price']) {
|
||
$up['online_price'] = round($val['online_price'], 2);
|
||
}
|
||
if ($val['store_mem_status'] != $find['store_mem_status']) {
|
||
$up['store_mem_status'] = $val['store_mem_status'];
|
||
}
|
||
if ($val['store_mem_price'] != $find['store_mem_price']) {
|
||
$up['store_mem_price'] = round($val['store_mem_price'], 2);
|
||
}
|
||
if ($val['shop_mem_status'] != $find['shop_mem_status']) {
|
||
$up['shop_mem_status'] = $val['shop_mem_status'];
|
||
}
|
||
if ($val['shop_mem_price'] != $find['shop_mem_price']) {
|
||
$up['shop_mem_price'] = round($val['shop_mem_price'], 2);
|
||
}
|
||
if ($val['plus_mem_status'] != $find['plus_mem_status']) {
|
||
$up['plus_mem_status'] = $val['plus_mem_status'];
|
||
}
|
||
if ($val['plus_price'] != $find['plus_price']) {
|
||
$up['plus_price'] = round($val['plus_price'], 2);
|
||
}
|
||
if ($up) {
|
||
$record += 1;
|
||
$save = M('retail_goods')->where(array('id' => $val['id']))->save($up);
|
||
if (!$save) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '第' . ($key + 1) . '条修改失败';
|
||
return $res;
|
||
}
|
||
if ($content) {
|
||
$where = array();
|
||
$where['goods_id'] = $val['id'];
|
||
$where['status'] = array('in', '0,1');
|
||
$save = D('SSaleMGoods')->updateData($where, $content);
|
||
if (!$save) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '第' . ($key + 1) . '条供给仓商品信息修改失败';
|
||
return $res;
|
||
}
|
||
unset($where['status']);
|
||
$where['type'] = 7; //初始化入库的商品修改信息
|
||
D('SWarehousingGoods')->updateData($where, $content);
|
||
}
|
||
unset($save);
|
||
unset($up);
|
||
}
|
||
unset($find);
|
||
}
|
||
$res['status'] = 1;
|
||
$res['msg'] = $record > 0 ? '修改成功' : '请先修改数据再提交';
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 新增、编辑商品页面 获取商品详情
|
||
*/
|
||
public function goodsSet()
|
||
{
|
||
if (IS_POST) {
|
||
//获取商品详情
|
||
$OperateGoodsApi = new OperateGoods();
|
||
$data = $OperateGoodsApi->getGoodsDetails(array(
|
||
'user_type' => 4,
|
||
'merchant_id' => $this->merchant_id,
|
||
'platform_type' => $this->role_info['platform_type'],
|
||
'store_id' => $this->store_id,
|
||
'goods_id' => I('post.id'),
|
||
));
|
||
$this->ajaxReturn($data);
|
||
} else {
|
||
$this->display();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取商品规格信息
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @throws \think\exception\DbException
|
||
*/
|
||
public function getGoodsSkuAttr()
|
||
{
|
||
$id = I('post.id');
|
||
$SkuAttribute = new SkuAttribute();
|
||
$param = array(
|
||
'user_type' => 4,
|
||
'platform_type' => $this->role_info['platform_type'],
|
||
'store_id' => $this->store_id,
|
||
'merchant_id' => $this->merchant_id,
|
||
'goods_id' => $id,
|
||
);
|
||
$data = $SkuAttribute->getStoreGoodsSkuInfo($param);
|
||
$this->ajaxReturn($data);
|
||
}
|
||
|
||
/**
|
||
* 获取添加编辑商品时的基本权限及配置信息
|
||
*/
|
||
public function getEditGoodsBaseSet()
|
||
{
|
||
$user = session('jurisdiction_user');
|
||
$OperateGoodsApi = new OperateGoods();
|
||
$config = $OperateGoodsApi->getEditGoodsConfig([
|
||
'store_id' => $this->store_id,
|
||
'merchant_id' => $this->merchant_id,
|
||
'user_type' => $user['login_type'],
|
||
]);
|
||
$this->ajaxReturn(array(
|
||
'status' => 1,
|
||
'msg' => '获取成功',
|
||
'data' => $config,
|
||
));
|
||
}
|
||
|
||
|
||
/**
|
||
* 提交新增或编辑商品
|
||
*/
|
||
public function doGoodsSet_v1()
|
||
{
|
||
if (IS_POST) {
|
||
$platform_type = $this->role_info['platform_type'] ? $this->role_info['platform_type'] : 1;
|
||
$user = session('jurisdiction_user');
|
||
$OperateGoodsApi = new OperateGoods();
|
||
$item = array(
|
||
'store_id' => $this->store_id,
|
||
'merchant_id' => $this->merchant_id,
|
||
'user_type' => $user['login_type'],
|
||
'operate_id' => $user['id'],
|
||
'platform_type' => $platform_type,
|
||
'goodsInfo' => I('post.'),
|
||
);
|
||
$editGoods = $OperateGoodsApi->editStoreGoods($item);
|
||
$this->ajaxReturn($editGoods);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 同步商品
|
||
* param [string] $page 分页
|
||
* param [string] $limit 数量
|
||
* return [array] $res
|
||
*/
|
||
public function getSyncGoods()
|
||
{
|
||
if (!$this->store_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '登陆超时';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 门店已同步的商品
|
||
$goods_ids = M('retail_goods')->where(array('store_id' => $this->store_id, 'merchant_id' => $this->merchant_id, 'source_type' => 2, 'status' => array('in', '0,1')))->getField('m_goods_id', true);
|
||
if ($goods_ids) {
|
||
$map['id'] = array('not in', $goods_ids);
|
||
}
|
||
// 搜索
|
||
$data = I('post.');
|
||
$goods_name = $data['seek_data']['goods_name'];
|
||
$keyword = $data['seek_data']['keyword'];
|
||
if (!empty($goods_name)) { // 商品名称
|
||
$map['goods_name'] = array('like', '%' . trim($goods_name) . '%');
|
||
}
|
||
if (!empty($keyword)) { // 货号、条码
|
||
$map['good_number|goods_code'] = array('like', '%' . trim($keyword) . '%');
|
||
}
|
||
$map['status'] = array('in', '0,1');
|
||
$map['merchantid'] = $this->merchant_id;
|
||
$GoodsClassify = new GoodsClassify();
|
||
$map = $GoodsClassify->getGoodsClassId($data, $map, "goods_class_id");
|
||
if (!empty($data['industry_id']) && empty($map['goods_class_id'])) {
|
||
$GoodsClass = new GoodsClassify();
|
||
$classResult = $GoodsClass->basisIndustryGetClass([
|
||
'industry_id' => ['in', [0, $data['industry_id']]],
|
||
'merchant_id' => $this->merchant_id
|
||
]);
|
||
if (!empty($classResult['data'])) {
|
||
$map['goods_class_id'] = ['in', $classResult['data']];
|
||
}
|
||
}
|
||
$sync_goods = M('retail_mgoods')
|
||
->where($map)
|
||
->page((int)I('post.page'), (int)I('post.limit'))
|
||
->order('id desc')
|
||
->select();
|
||
if (!$sync_goods) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '暂无可同步商品';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$total = M('retail_mgoods')->where($map)->count();
|
||
foreach ($sync_goods as &$val) {
|
||
// 获取浮点值
|
||
$val['retail_price'] = floatval($val['retail_price']);
|
||
$val['online_price'] = floatval($val['online_price']);
|
||
$val['shop_vip_price'] = $val['shop_mem_status'] == 1 && floatval($val['shop_mem_price']) > 0 ? floatval($val['shop_mem_price']) : '暂未开启';
|
||
$val['store_vip_price'] = $val['store_mem_status'] == 1 && floatval($val['store_mem_price']) > 0 ? floatval($val['store_mem_price']) : '暂未开启';
|
||
$val['plus_price_state'] = $val['plus_mem_status'] == 1 && floatval($val['plus_price']) > 0 ? floatval($val['plus_price']) : '暂未开启';
|
||
$val['code_name'] = $val['goods_code'] ? $val['goods_code'] : '暂无条码';
|
||
$val['weigh_type'] = $val['can_exchange_weigh'] == 1 ? '计件商品' : '称重商品';
|
||
// 分类
|
||
$val['class_name'] = M('retail_goods_class')->where(array('id' => $val['goods_class_id']))->getField('class_name');
|
||
// 规格
|
||
if ($val['attribute'] == 2) {
|
||
$sku_res = $this->getSku($val['id'], $val['shop_mem_status'], $val['store_mem_status'], $val['plus_mem_status']);
|
||
if ($sku_res['status'] == 1) {
|
||
$val['sku'] = $sku_res['sku'];
|
||
} else { // 暂无规格
|
||
$val['attribute'] = 1;
|
||
}
|
||
}
|
||
$val['sync_num'] = 0; // 同步数量
|
||
}
|
||
$res['status'] = 1;
|
||
$res['sync_goods'] = $sync_goods;
|
||
$res['total'] = (int)$total;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 获取商品规格
|
||
* @param [int] $goods_id 商品id
|
||
* @return [array] $res
|
||
*/
|
||
private function getSku($mgoods_id, $shop_mem_status, $store_mem_status, $plus_mem_status)
|
||
{
|
||
$sku = M('retail_sku_mgoods')
|
||
->field('mgoods_id,merchantid', true)
|
||
->where(array('merchantid' => $this->merchant_id, 'mgoods_id' => $mgoods_id, 'status' => 1, 'state' => 0))
|
||
->select();
|
||
if (!$sku) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '暂无规格';
|
||
return $res;
|
||
}
|
||
foreach ($sku as &$val) {
|
||
// 获取浮点
|
||
$val['retail_price'] = floatval($val['retail_price']);
|
||
$val['online_price'] = floatval($val['online_price']);
|
||
$val['sku_num'] = floatval($val['sku_num']);
|
||
$val['shop_vip_price'] = $shop_mem_status == 1 && floatval($val['shop_mem_price']) > 0 ? floatval($val['shop_mem_price']) : '暂未开启';
|
||
$val['store_vip_price'] = $store_mem_status == 1 && floatval($val['store_mem_price']) > 0 ? floatval($val['store_mem_price']) : '暂未开启';
|
||
$val['plus_price_state'] = $plus_mem_status == 1 && floatval($val['plus_price']) > 0 ? floatval($val['plus_price']) : '暂未开启';
|
||
$sku_name = M('retail_sku_list')->where(array('id' => array('in', $val['sku_id_list'])))->getField('name', true);
|
||
$val['sku_name'] = implode(',', $sku_name);
|
||
$val['code_name'] = $val['sku_code'] ? $val['sku_code'] : '暂无条码';
|
||
$val['sync_num'] = 0; // 同步数量
|
||
}
|
||
$res['status'] = 1;
|
||
$res['sku'] = $sku;
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 批量同步商品
|
||
* @param [string] $stroreid 门店id
|
||
* @param [array] $chose_goods 同步商品
|
||
* @return [array] $res
|
||
*/
|
||
public function batchSync()
|
||
{
|
||
$user = session("ls_userinfo");
|
||
$platform_type = $user['platform_type'] ? $user['platform_type'] : 1; //商户平台类型 1默认系统 2微礼平台
|
||
$cost_price = I('session.global_store_jurisdiction')['cost_price']; //成本价
|
||
if (!$this->store_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '提示:同步失败,请刷新重试';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$chose_goods = I('post.chose_goods');
|
||
if (!$chose_goods) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请勾选需要同步的商品';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$warehouse_id = D('SSaleWarehouse')->getFindField(array("store_id" => $this->store_id, "status" => 1), "id"); //供给仓id
|
||
if (!$warehouse_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请先创建供给仓';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$chose_goods = htmlspecialchars_decode($chose_goods);
|
||
$chose_goods = json_decode($chose_goods, true);
|
||
$error_journal = array();
|
||
$editRecord = []; //更新记录
|
||
$edit_arr = [
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'add_time' => $_SERVER['REQUEST_TIME']
|
||
];
|
||
$company_arr = []; //单位集合
|
||
$relation_arr = []; //门店与商户的商品关联信息
|
||
$add_id_arr = []; //新增商品的商户商品id集合
|
||
$GoodsModel = new RetailGoodsModel();
|
||
$SkuGoodsModel = new RetailSkuGoodsModel();
|
||
foreach ($chose_goods as &$val) {
|
||
if (!empty($val['company']) && !in_array($val['company'], $company_arr)) {
|
||
$company_arr[] = $val['company'];
|
||
}
|
||
$mgoods_id = $val['id'];
|
||
if ($val['attribute'] == 2) { // 规格商品
|
||
if (!$val['sku']) {
|
||
$arr = array('goods_name' => $val['goods_name'], 'error' => '规格参数缺失');
|
||
array_push($error_journal, $arr);
|
||
unset($arr);
|
||
continue;
|
||
}
|
||
$sku = $val['sku'];
|
||
}
|
||
unset($val['id']);
|
||
unset($val['sku']);
|
||
unset($val['code_name']);
|
||
unset($val['shop_vip_price']);
|
||
unset($val['store_vip_price']);
|
||
if ($val['good_number']) { // 验证货号
|
||
$goods_number = M('retail_goods')->where(array('store_id' => $this->store_id, 'goods_number' => $val['good_number'], 'status' => array('in', '0,1')))->getField('goods_number');
|
||
if ($goods_number) {
|
||
$arr = array('goods_name' => $val['goods_name'], 'error' => '商品档案中已存在该货号');
|
||
array_push($error_journal, $arr);
|
||
unset($arr);
|
||
continue;
|
||
}
|
||
}
|
||
if ($val['goods_code']) {
|
||
$goods_code = M('retail_goods')->where(array('store_id' => $this->store_id, 'goods_code' => $val['goods_code'], 'status' => array('in', '0,1')))->getField('goods_code');
|
||
if ($goods_code) {
|
||
$arr = array('goods_name' => $val['goods_name'], 'error' => '商品档案中已存在该条码');
|
||
array_push($error_journal, $arr);
|
||
unset($arr);
|
||
continue;
|
||
}
|
||
}
|
||
//第三方平台商品编码
|
||
if ($platform_type == 2 && $val['attribute'] == 1) {
|
||
if (empty($val['third_goods_code'])) {
|
||
$arr = array('goods_name' => $val['goods_name'], 'error' => 'Q3 ERP平台商品编码未设置');
|
||
array_push($error_journal, $arr);
|
||
unset($arr);
|
||
continue;
|
||
}
|
||
$third_goods_code = $GoodsModel->getFindField([
|
||
'store_id' => $this->store_id,
|
||
'third_goods_code' => $val['third_goods_code'],
|
||
'status' => array('in', '0,1')
|
||
], 'third_goods_code');
|
||
if (!empty($third_goods_code)) {
|
||
$arr = array('goods_name' => $val['goods_name'] . $val['third_goods_code'], 'error' => 'Q3 ERP平台商品编码重复');
|
||
array_push($error_journal, $arr);
|
||
unset($arr);
|
||
continue;
|
||
}
|
||
$third_goods_code = $SkuGoodsModel->getFindField([
|
||
'status' => 1,
|
||
'store_id' => $this->store_id,
|
||
'state' => 0,
|
||
'third_goods_code' => $val['third_goods_code']
|
||
]);
|
||
if (!empty($third_goods_code)) {
|
||
$arr = array('goods_name' => $val['goods_name'] . $val['third_goods_code'], 'error' => 'Q3 ERP平台商品编码重复');
|
||
array_push($error_journal, $arr);
|
||
unset($arr);
|
||
continue;
|
||
}
|
||
}
|
||
// 添加门店商品
|
||
$cr = $val;
|
||
$cr['weight_value'] = $cr['weight_value'] ? round($cr['weight_value'], 3) : null;
|
||
$cr['online_state'] = $val['issellonline'] ? $val['issellonline'] : 0;
|
||
$cr['goods_number'] = $val['good_number'];
|
||
if ($cost_price == 2) {
|
||
//禁止同步成本价
|
||
$cr['purchase_price'] = 0;
|
||
} else {
|
||
$cr['purchase_price'] = $val['purch_price'];
|
||
}
|
||
$cr['pricing_method'] = $val['can_exchange_weigh'];
|
||
$cr['attribute_state'] = $val['attribute'];
|
||
$cr['vip_online_price'] = $cr['vip_online_price'] ? $cr['vip_online_price'] : 0;
|
||
$cr['vip_online_integral'] = $cr['vip_online_integral'] ? $cr['vip_online_integral'] : 0;
|
||
$cr['vip_retail_price'] = $cr['vip_retail_price'] ? $cr['vip_retail_price'] : 0;
|
||
$cr['plus_price'] = $cr['plus_price'] ? $cr['plus_price'] : null;
|
||
$cr['vip_retail_integral'] = $cr['vip_retail_integral'] ? $cr['vip_retail_integral'] : 0;
|
||
$cr['more_num'] = $cr['more_num'] ? $cr['more_num'] : 0;
|
||
$cr['less_num'] = $cr['less_num'] ? $cr['less_num'] : 0;
|
||
$cr['goods_img_id'] = $cr['goods_image_id'] ? $cr['goods_image_id'] : 0;
|
||
$cr['goods_num'] = 0;
|
||
$cr['status'] = 0;
|
||
$cr['store_id'] = $this->store_id;
|
||
$cr['source_type'] = 2;
|
||
$cr['m_goods_id'] = $mgoods_id;
|
||
$cr['sync_state'] = 1;
|
||
$cr['add_time'] = time();
|
||
$cr['merchant_id'] = $this->merchant_id;
|
||
$add = M('retail_goods')->add($cr);
|
||
if (!$add) {
|
||
$arr = array('goods_name' => $val['goods_name'] . '4', 'error' => '同步失败');
|
||
array_push($error_journal, $arr);
|
||
unset($arr);
|
||
continue;
|
||
}
|
||
$relation_arr[$mgoods_id] = $add;
|
||
$add_id_arr[] = $mgoods_id;
|
||
$saleGoods = $cr;
|
||
$saleGoods['merchant_id'] = $this->merchant_id;
|
||
$saleGoods['warehouse_id'] = $warehouse_id;
|
||
$saleGoods['goods_id'] = $add;
|
||
if ($val['attribute'] == 1) {
|
||
A('Api/Inventory')->addSaleGoods($saleGoods, 1); //供给仓 1增加
|
||
}
|
||
// 同步规格
|
||
if ($val['attribute'] == 2) {
|
||
$add_sku = $this->addSku($add, $sku, $saleGoods, $platform_type);
|
||
if ($add_sku['status'] == 0) {
|
||
$arr = array('goods_name' => $val['goods_name'], 'error' => $add_sku['msg']);
|
||
array_push($error_journal, $arr);
|
||
unset($arr);
|
||
}
|
||
} // 规格同步,终止不会结束当前商品同步
|
||
$add_banner = $this->addBanner($add, $mgoods_id); // 轮播图同步,终止不会结束当前商品同步
|
||
// 同步轮播图
|
||
if ($add_banner['status'] == 0) {
|
||
$arr = array('goods_name' => $val['goods_name'] . '5', 'error' => $add_banner['msg']);
|
||
array_push($error_journal, $arr);
|
||
unset($arr);
|
||
}
|
||
$edit_arr['goods_id'] = $add;
|
||
$editRecord[] = $edit_arr;
|
||
}
|
||
//单位库添加
|
||
if (!empty($company_arr)) {
|
||
$UnitClass = new UnitLibrary();
|
||
$UnitClass->addUnit([
|
||
'user_type' => 4,
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'company_arr' => json_encode($company_arr)
|
||
]);
|
||
}
|
||
//标签处理
|
||
if (!empty($relation_arr)) {
|
||
$LabelClass = new LabelInventory();
|
||
$labelResult = $LabelClass->basisGoodsIdGetLabelList([
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'goods_id_arr' => json_encode($add_id_arr),
|
||
'user_type' => 3
|
||
]);
|
||
if ($labelResult['status'] == 1 && !empty($labelResult['data'])) {
|
||
$LabelClass->addLabel([
|
||
'user_type' => 4,
|
||
'operate_id' => session('jurisdiction_user')['id'],
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'label_arr' => json_encode($labelResult['data']),
|
||
'relation_arr' => json_encode($relation_arr)
|
||
]);
|
||
}
|
||
}
|
||
if (!empty($editRecord)) {
|
||
$GoodsClass = new Goods();
|
||
$GoodsClass->goodsEditRecord([
|
||
'store_id' => $this->store_id,
|
||
'merchant_id' => $this->merchant_id,
|
||
'goods_id' => $editRecord
|
||
]);
|
||
}
|
||
if (!$error_journal) {
|
||
//操作日志记录
|
||
$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['error_journal'] = $error_journal;
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 同步规格商品
|
||
* @param [int] $goods_id 商品id
|
||
* @param [array] $sku 规格
|
||
* @param $platform_type 商户平台类型 1默认系统 2微礼平台
|
||
* @saleGoods
|
||
* @return [array] $res
|
||
*/
|
||
protected function addSku($goods_id, $sku, $saleGoods, $platform_type = 1)
|
||
{
|
||
$cost_price = I('session.global_store_jurisdiction')['cost_price']; //成本价
|
||
$SkuGoodsModel = new RetailSkuGoodsModel();
|
||
$GoodsModel = new RetailGoodsModel();
|
||
foreach ($sku as &$val) {
|
||
$sku_name = $val['sku_name'];
|
||
$sku_mgoods_id = $val['id'];
|
||
unset($val['id']);
|
||
unset($val['sku_name']);
|
||
if ($val['sku_goods_number']) { // 验证货号
|
||
$sku_goods_number = M('retail_sku_goods')->where(array('store_id' => $this->store_id, 'sku_goods_number' => $val['sku_goods_number'], 'state' => 0))->getField('sku_goods_number');
|
||
if ($sku_goods_number) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '规格【' . $sku_name . '】同步失败,规格货号已存在';
|
||
return $res;
|
||
break;
|
||
}
|
||
}
|
||
if ($val['sku_code']) { // 验证货号
|
||
$sku_code = M('retail_sku_goods')->where(array('store_id' => $this->store_id, 'sku_code' => $val['sku_code'], 'state' => 0))->getField('sku_code');
|
||
if ($sku_code) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '规格【' . $sku_name . '】同步失败,规格条码已存在';
|
||
return $res;
|
||
break;
|
||
}
|
||
}
|
||
//第三方平台商品编码验证
|
||
if ($platform_type == 2) {
|
||
$third_goods_code = $SkuGoodsModel->getFindField([
|
||
'store_id' => $this->store_id,
|
||
'third_goods_code' => $val['third_goods_code'],
|
||
'state' => 0
|
||
], 'third_goods_code');
|
||
if (!empty($third_goods_code)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '规格【' . $sku_name . '】同步失败,规格Q3 ERP平台商品编码已存在';
|
||
return $res;
|
||
}
|
||
$third_goods_code = $GoodsModel->getFindField([
|
||
'store_id' => $this->store_id,
|
||
'third_goods_code' => $val['third_goods_code'],
|
||
'status' => array('in', '0,1')
|
||
], 'third_goods_code');
|
||
if (!empty($third_goods_code)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '规格【' . $sku_name . '】同步失败,规格Q3 ERP平台商品编码已存在';
|
||
return $res;
|
||
}
|
||
}
|
||
$cr = $val;
|
||
if ($cost_price == 2) {
|
||
$cr['purchase_price'] = 0;
|
||
} else {
|
||
$cr['purchase_price'] = $val['purch_price'];
|
||
}
|
||
$cr['weight_value'] = $cr['weight_value'] ? round($cr['weight_value'], 3) : null;
|
||
$cr['goods_num'] = 0;
|
||
$cr['goods_id'] = $goods_id;
|
||
$cr['store_id'] = $this->store_id;
|
||
$cr['sku_mgoods_id'] = $sku_mgoods_id;
|
||
$add = M('retail_sku_goods')->add($cr);
|
||
if (!$add) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '规格【' . $sku_name . '】同步失败,中断规格同步';
|
||
return $res;
|
||
break;
|
||
}
|
||
$saleGoods['purchase_price'] = $cr['purchase_price'];
|
||
$saleGoods['goods_num'] = $cr['goods_num'];
|
||
$saleGoods['sku_name'] = $sku_name;
|
||
$saleGoods['goods_id'] = $cr['goods_id'];
|
||
$saleGoods['sku_id'] = $add;
|
||
$saleGoods['sku_id_list'] = $cr['sku_id_list'];
|
||
$saleGoods['sku_goods_number'] = $cr['sku_goods_number'];
|
||
$saleGoods['sku_code'] = $cr['sku_code'];
|
||
$saleGoods['sku_num'] = $cr['sku_num'];
|
||
$saleGoods['more_num'] = $cr['more_num'];
|
||
$saleGoods['less_num'] = $cr['less_num'];
|
||
$saleGoods['cost_price'] = $cr['purchase_price'];
|
||
$saleGoods['third_goods_code'] = $cr['third_goods_code'];
|
||
A('Api/Inventory')->addSaleGoods($saleGoods, 1); //供给仓 1增加
|
||
unset($sku_name);
|
||
unset($cr);
|
||
unset($add);
|
||
}
|
||
$res['status'] = 1;
|
||
$res['msg'] = '规格同步成功';
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 同步轮播图
|
||
* @param $goods_id 门店商品id
|
||
* @param $mgoods_id 商户商品id
|
||
* @return [array] $res
|
||
*/
|
||
protected function addBanner($goods_id, $mgoods_id)
|
||
{
|
||
$banner = M('retail_mgoods_banner')->where(array('mgoods_id' => $mgoods_id))->select();
|
||
if (!$banner) {
|
||
$res['status'] = 2;
|
||
$res['msg'] = '暂无轮播图';
|
||
return $res;
|
||
}
|
||
foreach ($banner as &$val) {
|
||
$mgoods_banner_id = $val['id'];
|
||
unset($val['id']);
|
||
unset($val['mgoods_id']);
|
||
$cr = $val;
|
||
$cr['goods_id'] = $goods_id;
|
||
$cr['storeid'] = $this->store_id;
|
||
$cr['mgoods_banner_id'] = $mgoods_banner_id;
|
||
$add = M('retail_goods_banner')->add($cr);
|
||
if (!$add) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '同步失败';
|
||
return $res;
|
||
break;
|
||
}
|
||
}
|
||
$res['status'] = 1;
|
||
$res['msg'] = '同步成功';
|
||
return $res;
|
||
}
|
||
|
||
|
||
/**新商品更新
|
||
* 更新商品,获取商品分类
|
||
* @return [array] $res
|
||
*/
|
||
public function getClassList()
|
||
{
|
||
/* 商品分类 */
|
||
$class_data = M('retail_goods_class')->field('id,class_name')->where(array('pid' => 0, 'status' => 0, 'merchantid' => $this->merchant_id))->order('id asc')->select();
|
||
if (!$class_data) {
|
||
$res = array('status' => 0, 'msg' => '暂无分类');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
foreach ($class_data as &$val) {
|
||
$children1 = M('retail_goods_class')->field('id,class_name')->where(array('pid' => $val['id'], 'status' => 0, 'merchantid' => $this->merchant_id))->order('id asc')->select();
|
||
if ($children1) {
|
||
foreach ($children1 as &$value) {
|
||
$children2 = M('retail_goods_class')->field('id,class_name')->where(array('pid' => $value['id'], 'status' => 0, 'merchantid' => $this->merchant_id))->order('id asc')->select();
|
||
$value['children'] = $children2;
|
||
}
|
||
}
|
||
$val['children'] = $children1;
|
||
}
|
||
$res = array('status' => 1, 'class_data' => $class_data);
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 获取更新列表
|
||
* $seek_data 搜索条件
|
||
* $res
|
||
*/
|
||
public function getUpdateGoods()
|
||
{
|
||
// 搜索条件
|
||
$seek_data = I('post.seek_data');
|
||
// 名称搜索
|
||
if (trim($seek_data['goods_name'])) { // 商品名称搜索
|
||
$map['m.goods_name'] = array('like', '%' . trim($seek_data['goods_name']) . '%');
|
||
}
|
||
// 货号,条码搜索
|
||
if (trim($seek_data['keyword'])) { // 商品货号、条码
|
||
$map['m.good_number|m.goods_code'] = array('like', '%' . trim($seek_data['keyword']) . '%');
|
||
}
|
||
// 分类搜索
|
||
$GoodsClassify = new GoodsClassify();
|
||
$map = $GoodsClassify->getGoodsClassId($seek_data, $map, "m.goods_class_id");
|
||
if (!empty($data['industry_id']) && empty($map['m.goods_class_id'])) {
|
||
$GoodsClass = new GoodsClassify();
|
||
$classResult = $GoodsClass->basisIndustryGetClass([
|
||
'industry_id' => ['in', [0, $data['industry_id']]],
|
||
'merchant_id' => $this->merchant_id
|
||
]);
|
||
if (!empty($classResult['data'])) {
|
||
$map['m.goods_class_id'] = ['in', $classResult['data']];
|
||
}
|
||
}
|
||
$map['m.status'] = array('in', '0,1');
|
||
$map['m.merchantid'] = $this->merchant_id;
|
||
$map['g.status'] = array('in', '0,1');
|
||
$map['g.store_id'] = $this->store_id;
|
||
$map['g.source_type'] = 2;
|
||
$map['g.sync_state'] = 0;
|
||
$update_goods = M('retail_mgoods as m')
|
||
->join('ls_retail_goods as g on g.m_goods_id=m.id AND g.pricing_method = m.can_exchange_weigh')
|
||
->field('m.*,g.id as goods_id')
|
||
->where($map)
|
||
->page((int)I('post.page'), (int)I('post.limit'))
|
||
->order('m.id desc')
|
||
->select();
|
||
if (!$update_goods) {
|
||
$res = array('status' => 0, 'msg' => '暂无更新商品');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$total = M('retail_mgoods as m')->join('ls_retail_goods as g on g.m_goods_id=m.id')->where($map)->count();
|
||
foreach ($update_goods as &$val) {
|
||
if ($val['goods_img_id'] && ($val['goods_img_id'] != 0 || $val['goods_img_id'] != '0')) {
|
||
$val['goods_image'] = D('ImageGallery')->getFieldPath(array('id' => $val['goods_image_id']));
|
||
} else {
|
||
$val['goods_image'] = $val['goods_image'] && $val['goods_image'] != '/Uploads' ? $val['goods_image'] : '';
|
||
}
|
||
$val['class_name'] = M('retail_goods_class')->where(array('id' => $val['goods_class_id']))->getField('class_name');
|
||
$val['online_price'] = floatval($val['online_price']);
|
||
$val['retail_price'] = floatval($val['retail_price']);
|
||
$val['code_name'] = $val['goods_code'] ? $val['goods_code'] : '暂无条码';
|
||
if ($val['store_mem_status'] == 1) {
|
||
$val['store_vip_price'] = !$val['store_mem_price'] || $val['store_mem_price'] <= 0 ? '未设置' : floatval($val['store_mem_price']);
|
||
} else {
|
||
$val['store_vip_price'] = '未开启';
|
||
}
|
||
if ($val['shop_mem_status'] == 1) {
|
||
$val['shop_vip_price'] = !$val['shop_mem_price'] || $val['shop_mem_price'] <= 0 ? '未设置' : floatval($val['shop_mem_price']);
|
||
} else {
|
||
$val['shop_vip_price'] = '未开启';
|
||
}
|
||
if ($val['plus_mem_status'] == 1) {
|
||
$val['plus_price'] = $val['plus_price'] ? floatval($val['plus_price']) : '未设置';
|
||
} else {
|
||
$val['plus_price'] = '未开启';
|
||
}
|
||
/* 品牌 */
|
||
if ($val['goods_brand_id']) {
|
||
$goods_brand = M('retail_goods_brand')->where(array('id' => $val['goods_brand_id'], 'state' => 0))->getField('name');
|
||
if ($goods_brand) {
|
||
$val['goods_brand'] = $goods_brand;
|
||
} else {
|
||
$val['goods_brand'] = '未设置';
|
||
}
|
||
} else {
|
||
$val['goods_brand'] = '未设置';
|
||
}
|
||
/* 产地 */
|
||
if ($val['goods_yieldly_id']) {
|
||
$goods_brand = M('retail_goods_yieldly')->where(array('id' => $val['goods_yieldly_id'], 'state' => 0))->getField('name');
|
||
if ($goods_brand) {
|
||
$val['goods_yieldly'] = $goods_brand;
|
||
} else {
|
||
$val['goods_yieldly'] = '未设置';
|
||
}
|
||
} else {
|
||
$val['goods_yieldly'] = '未设置';
|
||
}
|
||
/* 单位 */
|
||
$val['company'] = $val['company'] ? $val['company'] : '';
|
||
$val['weight_value'] = $val['weight_value'] ? round($val['weight_value'], 3) : '';
|
||
/* 规格(描述) */
|
||
$val['specifications'] = $val['specifications'] ? $val['specifications'] : '';
|
||
}
|
||
$res['status'] = 1;
|
||
$res['update_goods'] = $update_goods;
|
||
$res['total'] = $total ? (int)$total : 0;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 获取规格
|
||
* @param [int] $mgoods_id 商户商品id
|
||
* @return [array] $res
|
||
*/
|
||
public function getMgoodsSku()
|
||
{
|
||
// 商户商品id
|
||
$mgoods_id = I('post.mgoods_id');
|
||
if (!$mgoods_id) {
|
||
$res = array('status' => 0, 'msg' => '参数缺失');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 会员价状态
|
||
$shop_mem_status = I('post.shop_mem_status') ? I('post.shop_mem_status') : 2;
|
||
$store_mem_status = I('post.store_mem_status') ? I('post.store_mem_status') : 2;
|
||
$map['merchantid'] = $this->merchant_id;
|
||
$map['mgoods_id'] = $mgoods_id;
|
||
$map['status'] = 1;
|
||
$map['state'] = 0;
|
||
$sku = M('retail_sku_mgoods')->where($map)->order('addtime desc')->select();
|
||
if (!$sku) {
|
||
$res = array('status' => 0, 'msg' => '暂无规格');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
foreach ($sku as &$val) {
|
||
if ($val['goods_image_id'] && ($val['goods_image_id'] != 0 || $val['goods_image_id'] != '0')) {
|
||
$val['goods_image'] = D('ImageGallery')->getFieldPath(array('id' => $val['goods_image_id']));
|
||
} else {
|
||
$val['goods_image'] = $val['goods_img'] && $val['goods_img'] != '/Uploads' ? $val['goods_img'] : '';
|
||
}
|
||
$sku_name = M('retail_sku_list')->where(array('id' => array('in', $val['sku_id_list'])))->getField('name', true);
|
||
$val['sku_name'] = implode(',', $sku_name);
|
||
$val['weight_value'] = $val['weight_value'] ? round($val['weight_value'], 3) : '';
|
||
$val['purch_price'] = floatval($val['purch_price']);
|
||
$val['online_price'] = floatval($val['online_price']);
|
||
$val['retail_price'] = floatval($val['retail_price']);
|
||
$val['plus_price'] = floatval($val['plus_price']);
|
||
if ($store_mem_status == 1) {
|
||
$val['store_vip_price'] = !$val['store_mem_price'] || $val['store_mem_price'] <= 0 ? '未设置' : floatval($val['store_mem_price']);
|
||
} else {
|
||
$val['store_vip_price'] = '未开启';
|
||
}
|
||
if ($shop_mem_status == 1) {
|
||
$val['shop_vip_price'] = !$val['shop_mem_price'] || $val['shop_mem_price'] <= 0 ? '未设置' : floatval($val['shop_mem_price']);
|
||
} else {
|
||
$val['shop_vip_price'] = '未开启';
|
||
}
|
||
$val['sku_num'] = floatval($val['sku_num']); // 库存基数
|
||
$val['sku_code'] = $val['sku_code'] ? $val['sku_code'] : '暂无条码';
|
||
}
|
||
$res = array('status' => 1, 'sku' => $sku);
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 批量更新
|
||
* [array] $check_list 更新字段
|
||
* [array] $chose_goods 更新商品
|
||
* [array] $res
|
||
*/
|
||
public function batchUpdate()
|
||
{
|
||
// 更新字段
|
||
$check_list = I('post.check_list');
|
||
if (!$check_list) {
|
||
$res = array('status' => 0, 'msg' => '请选择更新字段');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 更新商品
|
||
$chose_goods = json_decode(htmlspecialchars_decode(I('post.chose_goods')), true);
|
||
if (!$chose_goods) {
|
||
$res = array('status' => 0, 'msg' => '请选择更新商品');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$editRecord = []; //更新记录
|
||
$edit_arr = [
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'add_time' => $_SERVER['REQUEST_TIME']
|
||
];
|
||
$error_journal = array();
|
||
$MGoodsModel = new RetailMgoodsModel();
|
||
$GoodsModel = new RetailGoodsModel();
|
||
$company_arr = []; //单位集合
|
||
$relation_arr = []; //门店与商户的商品关联信息
|
||
$add_id_arr = []; //新增商品的商户商品id集合
|
||
foreach ($chose_goods as &$val) {
|
||
$content = array(); //供给仓更新
|
||
// 商户商品查询
|
||
$mMap = array('id' => $val['id'], 'status' => array('in', '0,1'), 'merchantid' => $this->merchant_id);
|
||
$mgoods = $MGoodsModel->getFind($mMap);
|
||
if (!$mgoods) {
|
||
array_push($error_journal, array('goods_name' => $val['goods_name'], 'error' => '商户档案中为查询到该商品'));
|
||
continue;
|
||
}
|
||
// 门店商品查询
|
||
$gMap = array('id' => $val['goods_id'], 'status' => array('in', '0,1'), 'store_id' => $this->store_id);
|
||
$goods = $GoodsModel->getFind($gMap);
|
||
if (!$goods) {
|
||
array_push($error_journal, array('goods_name' => $val['goods_name'], 'error' => '门店商品档案中未查询到该同步商品'));
|
||
continue;
|
||
}
|
||
/* 1-名称 */
|
||
if (in_array('name', $check_list)) {
|
||
if ($mgoods['goods_name'] && $mgoods['goods_name'] != $goods['goods_name']) {
|
||
$up['goods_name'] = $mgoods['goods_name'];
|
||
$content['goods_name'] = $mgoods['goods_name'];
|
||
}
|
||
}
|
||
/* 2-分类 */
|
||
if (in_array('class', $check_list)) {
|
||
if ($mgoods['goods_class_id'] && $mgoods['goods_class_id'] != $goods['goods_class_id']) {
|
||
$up['goods_class_id'] = $mgoods['goods_class_id'];
|
||
$content['goods_class_id'] = $mgoods['goods_class_id'];
|
||
}
|
||
}
|
||
/* 3-商品图片 */
|
||
if (in_array('image', $check_list)) {
|
||
if ($mgoods['goods_image_id'] != $goods['goods_img_id']) {
|
||
$up['goods_img_id'] = $mgoods['goods_image_id'];
|
||
}
|
||
if ($mgoods['good_image'] && $mgoods['good_image'] != '/Uploads' && $mgoods['good_image'] != $goods['good_image']) {
|
||
$up['good_image'] = $mgoods['good_image'];
|
||
}
|
||
}
|
||
/* 4-货号 */
|
||
if (in_array('number', $check_list)) {
|
||
if ($mgoods['good_number'] && $mgoods['good_number'] != $goods['goods_number']) {
|
||
$id = M('retail_goods')->where(array('goods_number' => $mgoods['good_number'], 'store_id' => $this->store_id, 'status' => array('in', '0,1')))->getField('id');
|
||
if ($id) {
|
||
array_push($error_journal, array('goods_name' => $val['goods_name'], 'error' => '货号已存在'));
|
||
continue;
|
||
} else {
|
||
$up['goods_number'] = $mgoods['good_number'];
|
||
$content['goods_number'] = $mgoods['good_number'];
|
||
}
|
||
unset($id);
|
||
}
|
||
}
|
||
/* 5-条码 */
|
||
if (in_array('code', $check_list)) {
|
||
if ($mgoods['goods_code'] && $mgoods['goods_code'] != $goods['goods_code']) {
|
||
$id = M('retail_goods')->where(array('goods_code' => $mgoods['goods_code'], 'store_id' => $this->store_id, 'status' => array('in', '0,1')))->getField('id');
|
||
if ($id) {
|
||
array_push($error_journal, array('goods_name' => $val['goods_name'], 'error' => '条码已存在'));
|
||
continue;
|
||
} else {
|
||
$up['goods_code'] = $mgoods['goods_code'];
|
||
$content['goods_code'] = $mgoods['goods_code'];
|
||
}
|
||
unset($id);
|
||
}
|
||
}
|
||
/* 6-单位 */
|
||
if (in_array('company', $check_list)) {
|
||
if ($mgoods['company'] && ($mgoods['company'] != $goods['company'])) {
|
||
$up['company'] = $mgoods['company'];
|
||
$content['company'] = $mgoods['company'];
|
||
if (!in_array($mgoods['company'], $company_arr)) {
|
||
$company_arr[] = $mgoods['company'];
|
||
}
|
||
}
|
||
}
|
||
//重量
|
||
if (in_array('weight_value', $check_list)) {
|
||
if ($mgoods['weight_value'] && $mgoods['weight_value'] != $goods['weight_value']) {
|
||
$up['weight_value'] = $mgoods['weight_value'];
|
||
}
|
||
}
|
||
/* 7-规格(描述) */
|
||
if (in_array('specifications', $check_list)) {
|
||
if ($mgoods['specifications'] && $mgoods['specifications'] != $goods['specifications']) {
|
||
$up['specifications'] = $mgoods['specifications'];
|
||
$content['specifications'] = $mgoods['specifications'];
|
||
}
|
||
}
|
||
/* 8-供货商 */
|
||
if (in_array('supplier', $check_list)) {
|
||
if ($mgoods['supplier_id'] && $mgoods['supplier_id'] != $goods['supplier_id']) {
|
||
$up['supplier_id'] = $mgoods['supplier_id'];
|
||
}
|
||
}
|
||
/* 9-品牌 */
|
||
if (in_array('brand', $check_list)) {
|
||
if ($mgoods['goods_brand_id'] && $mgoods['goods_brand_id'] != $goods['goods_brand_id']) {
|
||
$up['goods_brand_id'] = $mgoods['goods_brand_id'];
|
||
$content['goods_brand_id'] = $mgoods['goods_brand_id'];
|
||
}
|
||
}
|
||
//副标题
|
||
if (in_array('subheading', $check_list)) {
|
||
if ($mgoods['subheading'] && $mgoods['subheading'] != $goods['subheading']) {
|
||
$up['subheading'] = $mgoods['subheading'];
|
||
}
|
||
}
|
||
/* 10-产地 */
|
||
if (in_array('yieldly', $check_list)) {
|
||
if ($mgoods['goods_yieldly_id'] && $mgoods['goods_yieldly_id'] != $goods['goods_yieldly_id']) {
|
||
$up['goods_yieldly_id'] = $mgoods['goods_yieldly_id'];
|
||
$content['goods_yieldly_id'] = $mgoods['goods_yieldly_id'];
|
||
}
|
||
}
|
||
/* 11-详情 */
|
||
if (in_array('details', $check_list)) {
|
||
if ($mgoods['details'] && $mgoods['details'] != $goods['details']) {
|
||
$up['details'] = $mgoods['details'];
|
||
}
|
||
}
|
||
/* 12-店内价 */
|
||
if (in_array('retail_price', $check_list)) {
|
||
if ($mgoods['retail_price'] && $mgoods['retail_price'] != $goods['retail_price']) {
|
||
$up['retail_price'] = $mgoods['retail_price'];
|
||
}
|
||
}
|
||
/* 13-商城价 */
|
||
if (in_array('online_price', $check_list)) {
|
||
if ($mgoods['online_price'] && $mgoods['online_price'] != $goods['online_price']) {
|
||
$up['online_price'] = $mgoods['online_price'];
|
||
}
|
||
}
|
||
/* 14-门店折扣 */
|
||
if (in_array('retail_state', $check_list)) {
|
||
if ($mgoods['vip_retail_state'] != $goods['vip_retail_state']) {
|
||
$up['vip_retail_state'] = $mgoods['vip_retail_state'];
|
||
}
|
||
}
|
||
/* 15-商城折扣 */
|
||
if (in_array('online_state', $check_list)) {
|
||
if ($mgoods['vip_online_state'] != $goods['vip_online_state']) {
|
||
$up['vip_online_state'] = $mgoods['vip_online_state'];
|
||
}
|
||
}
|
||
/* 16-门店会员价 */
|
||
if (in_array('store_vip_price', $check_list)) {
|
||
if ($mgoods['store_mem_status'] && $mgoods['store_mem_status'] != $goods['store_mem_status']) {
|
||
$up['store_mem_status'] = $mgoods['store_mem_status'];
|
||
}
|
||
if ($mgoods['store_mem_price'] && $mgoods['store_mem_price'] != $goods['store_mem_price']) {
|
||
$up['store_mem_price'] = $mgoods['store_mem_price'];
|
||
}
|
||
}
|
||
/* 17-商城会员价 */
|
||
if (in_array('shop_vip_price', $check_list)) {
|
||
if ($mgoods['shop_mem_status'] && $mgoods['shop_mem_status'] != $goods['shop_mem_status']) {
|
||
$up['shop_mem_status'] = $mgoods['shop_mem_status'];
|
||
}
|
||
if ($mgoods['shop_mem_price'] && $mgoods['shop_mem_price'] != $goods['shop_mem_price']) {
|
||
$up['shop_mem_price'] = $mgoods['shop_mem_price'];
|
||
}
|
||
}
|
||
//plus会员价
|
||
if (in_array('plus_price', $check_list)) {
|
||
if ($mgoods['plus_price'] && $mgoods['plus_price'] != $goods['plus_price']) {
|
||
$up['plus_price'] = round($mgoods['plus_price'], 2);
|
||
}
|
||
if ($mgoods['plus_mem_status'] && $mgoods['plus_mem_status'] != $goods['plus_mem_status']) {
|
||
$up['plus_mem_status'] = $mgoods['plus_mem_status'];
|
||
}
|
||
}
|
||
/* 18-出售类型*/
|
||
if (in_array('issellonline', $check_list)) {
|
||
if ($mgoods['issellonline'] != $goods['online_state']) {
|
||
$up['online_state'] = $mgoods['issellonline'];
|
||
}
|
||
}
|
||
/* 19-称重 */
|
||
if (in_array('weigh', $check_list)) {
|
||
if ($mgoods['can_exchange_weigh'] != $goods['pricing_method']) {
|
||
$up['pricing_method'] = $mgoods['can_exchange_weigh'];
|
||
$content['pricing_method'] = $mgoods['can_exchange_weigh'];
|
||
}
|
||
}
|
||
/* 20-商品状态 */
|
||
if (in_array('status', $check_list)) {
|
||
if ($mgoods['status'] != $goods['status']) {
|
||
$up['status'] = $mgoods['status'];
|
||
$content['status'] = $mgoods['status'];
|
||
}
|
||
}
|
||
/* 21-轮播图 */
|
||
if (in_array('swiper', $check_list)) {
|
||
$swiper_res = $this->updateSwiper($val['id'], $val['goods_id']);
|
||
if ($swiper_res['status'] == 0) {
|
||
array_push($error_journal, array('goods_name' => $val['goods_name'], 'error' => $swiper_res['msg']));
|
||
}
|
||
}
|
||
/* 22-规格 */
|
||
if (in_array('sku', $check_list)) {
|
||
if ($mgoods['attribute'] != $goods['attribute_state']) {
|
||
array_push($error_journal, array('goods_name' => $val['goods_name'], 'error' => '商品规格属性不同'));
|
||
} else if ($mgoods['attribute'] == $goods['attribute_state'] && $mgoods['attribute'] == 2) { // 规格时
|
||
$sku_res = $this->updateSku($val['id'], $val['goods_id'], $check_list, $goods);
|
||
if ($sku_res['status'] == 0) {
|
||
array_push($error_journal, array('goods_name' => $val['goods_name'], 'error' => $sku_res['msg']));
|
||
}
|
||
}
|
||
}
|
||
// 更新状态
|
||
$up['sync_state'] = 1;
|
||
// 更新操作
|
||
if ($up) {
|
||
$save = M('retail_goods')->where(array('id' => $goods['id']))->save($up);
|
||
if (!$save) {
|
||
array_push($error_journal, array('goods_name' => $val['goods_name'], 'error' => '更新失败'));
|
||
continue;
|
||
}
|
||
$relation_arr[$mgoods['id']] = $goods['id'];
|
||
$add_id_arr[] = $mgoods['id'];
|
||
if (!empty($content)) {
|
||
D('SSaleMGoods')->updateData(array('goods_id' => $goods['id'], 'status' => array('in', '0,1')), $content);
|
||
A('Api/Inventory')->SalesWarehouse($content, $this->store_id, $goods['id']);
|
||
}
|
||
$edit_arr['goods_id'] = $goods['id'];
|
||
$editRecord[] = $edit_arr;
|
||
}
|
||
unset($up);
|
||
unset($save);
|
||
unset($mgoods);
|
||
unset($goods);
|
||
}
|
||
//单位库新增单位
|
||
if (!empty($company_arr)) {
|
||
$UnitClass = new UnitLibrary();
|
||
$unitResult = $UnitClass->addUnit([
|
||
'user_type' => 4,
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'company_arr' => json_encode($company_arr)
|
||
]);
|
||
if ($unitResult['status'] != 1) {
|
||
array_push($error_journal, array('error' => '单位库新增单位失败'));
|
||
}
|
||
}
|
||
//标签处理
|
||
if (!empty($relation_arr)) {
|
||
$LabelClass = new LabelInventory();
|
||
$labelResult = $LabelClass->basisGoodsIdGetLabelList([
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'goods_id_arr' => json_encode($add_id_arr),
|
||
'user_type' => 3
|
||
]);
|
||
if ($labelResult['status'] == 1 && !empty($labelResult['data'])) {
|
||
$labelResult = $LabelClass->addLabel([
|
||
'user_type' => 4,
|
||
'operate_id' => session('jurisdiction_user')['id'],
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'label_arr' => json_encode($labelResult['data']),
|
||
'relation_arr' => json_encode($relation_arr)
|
||
]);
|
||
if ($labelResult['status'] != 1) {
|
||
$arr = array('error' => '标签关联失败');
|
||
array_push($error_journal, $arr);
|
||
}
|
||
}
|
||
}
|
||
if (!empty($editRecord)) {
|
||
$GoodsClass = new Goods();
|
||
$GoodsClass->goodsEditRecord([
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'goods_id' => $editRecord
|
||
]);
|
||
}
|
||
if ($error_journal) {
|
||
$res = array('status' => 2, 'error_journal' => $error_journal);
|
||
} 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);
|
||
}
|
||
|
||
/**
|
||
* 更新轮播图
|
||
* @param [$mgoods_id] 商户商品id
|
||
* @param [$goods_id] 门店商品id
|
||
* @return [array] $res
|
||
*/
|
||
protected function updateSwiper($mgoods_id, $goods_id)
|
||
{
|
||
// 查询轮播图
|
||
$MGoodsBannerModel = new MGoodsBannerModel();
|
||
$mBanner = $MGoodsBannerModel->getSelect(['mgoods_id' => $mgoods_id, 'merchantid' => $this->merchant_id]);
|
||
$ids = [];//存储商户设置的轮播图ID列表
|
||
$GoodsBannerModel = new RetailGoodsBannerModel();
|
||
foreach ($mBanner as $val) {
|
||
// 查询门店轮播图
|
||
$id = $GoodsBannerModel->getFindField(['goods_id' => $goods_id, 'storeid' => $this->store_id, 'mgoods_banner_id' => $val['id']], 'id');
|
||
if (!$id) { // 执行添加操作
|
||
$cr = $val;
|
||
unset($cr['mgoods_id']);
|
||
unset($cr['merchantid']);
|
||
unset($cr['id']);
|
||
$cr['goods_id'] = $goods_id;
|
||
$cr['storeid'] = $this->store_id;
|
||
$cr['mgoods_banner_id'] = $val['id'];
|
||
$id = $GoodsBannerModel->addOrder($cr);
|
||
if (!$id) {
|
||
return ['status' => 0, 'msg' => '轮播图更新出现错误,中断轮播图更新'];
|
||
}
|
||
}
|
||
$ids[] = $id;
|
||
}
|
||
if (empty($ids)) {
|
||
$ids = ['0'];
|
||
}
|
||
//删除商户已删除的轮播图
|
||
$GoodsBannerModel->deleteOrder(['goods_id' => $goods_id, 'id' => ['not in', $ids], 'mgoods_banner_id' => ['gt', 0]]);
|
||
return ['status' => 1, 'msg' => '更新成功'];
|
||
}
|
||
|
||
|
||
/**
|
||
* 更新规格
|
||
* @param [$mgoods_id] 商户商品id
|
||
* @param [$goods_id] 门店商品id
|
||
* @param [array]$goods 门店商品信息
|
||
* @return [array] $res
|
||
*/
|
||
protected function updateSku($mgoods_id, $goods_id, $check_list, $goods)
|
||
{
|
||
$map = array(
|
||
'status' => 1,
|
||
'state' => 0
|
||
);
|
||
// 查询商户商品规格
|
||
$map1 = $map;
|
||
$map1['merchantid'] = $this->merchant_id;
|
||
$map1['mgoods_id'] = $mgoods_id;
|
||
$msku_ids = M('retail_sku_mgoods')->where($map1)->getField('id', true);
|
||
if (!$msku_ids) {
|
||
$res = array('status' => 1, 'msg' => '暂无更新规格');
|
||
return $res;
|
||
}
|
||
// 查询门店对应的商户商品规格是否有变动
|
||
$map2 = $map;
|
||
$map2['store_id'] = $this->store_id;
|
||
$map2['goods_id'] = $goods_id;
|
||
$map2['sku_mgoods_id'] = array('not in', $msku_ids);
|
||
$sku_ids = M('retail_sku_goods')->where($map2)->getField('id', true);
|
||
if (!empty($sku_ids)) { // 门店与商户不同的规格信息
|
||
$map3['id'] = array('in', $sku_ids);
|
||
// 删除现有规格
|
||
$del = M('retail_sku_goods')->where($map3)->save(array('state' => 1));
|
||
if (!$del) {
|
||
$res = array('status' => 0, 'msg' => '规格更新出现错误,中断规格更新');
|
||
return $res;
|
||
}
|
||
$sale_map = array();
|
||
$sale_map['merchant_id'] = $this->merchant_id;
|
||
$sale_map['store_id'] = $this->store_id;
|
||
$sale_map['goods_id'] = $goods_id;
|
||
$sale_map['sku_id'] = array('in', $sku_ids);
|
||
$del = D('SSaleMGoods')->updateData($sale_map, array('status' => 2));
|
||
if ($del['status'] == 0) {
|
||
$res = array('status' => 0, 'msg' => '规格更新出现错误,中断规格更新');
|
||
return $res;
|
||
}
|
||
D('SWarehousingGoods')->updateData(array('goods_id' => $goods_id, 'sku_id' => array('in', $sku_ids)), array('surplus_num' => 0));
|
||
}
|
||
foreach ($msku_ids as $val) {
|
||
$content = array();
|
||
$msku = M('retail_sku_mgoods')->where(array('id' => $val, 'status' => 1, 'state' => 0))->find();
|
||
if (!$msku) {
|
||
continue;
|
||
}
|
||
$sku = M('retail_sku_goods')->where(array('sku_mgoods_id' => $val, 'status' => 1, 'state' => 0, 'store_id' => $this->store_id))->find();
|
||
if ($sku) { // 门店存在该规格 判断修改
|
||
/* 1-规格名称 */
|
||
if (in_array('name', $check_list)) {
|
||
if ($msku['sku_id_list'] && $msku['sku_id_list'] != $sku['sku_id_list']) {
|
||
$up['sku_id_list'] = $msku['sku_id_list'];
|
||
$content['sku_id_list'] = $msku['sku_id_list'];
|
||
$sku_name = M('retail_sku_list')->where(array('id' => array('in', $msku['sku_id_list'])))->getField('name', true);
|
||
$content['sku_name'] = implode(',', $sku_name);
|
||
}
|
||
}
|
||
/* 2-规格图片 */
|
||
if (in_array('image', $check_list)) {
|
||
if ($msku['goods_img_id'] != $sku['goods_img_id']) {
|
||
$up['goods_img_id'] = $msku['goods_img_id'];
|
||
}
|
||
if ($msku['goods_img'] && $msku['goods_img'] != '/Uploads' && $msku['goods_img'] != $sku['goods_img']) {
|
||
$up['goods_img'] = $msku['goods_img'];
|
||
}
|
||
}
|
||
/*
|
||
* 规格货号
|
||
*/
|
||
if (in_array('number', $check_list)) {
|
||
if ($msku['sku_goods_number'] && $msku['sku_goods_number'] != $sku['sku_goods_number']) {
|
||
$sku_goods_number = M('retail_sku_goods')->where(array('store_id' => $this->store_id, 'sku_goods_number' => $msku['sku_goods_number'], 'state' => 0))->find();
|
||
if ($sku_goods_number) {
|
||
// 货号已存在
|
||
$res = array('status' => 0, 'msg' => '规格货号出现重复,规格更新失败');
|
||
return $res;
|
||
} else {
|
||
$up['sku_goods_number'] = $msku['sku_goods_number'];
|
||
$content['sku_goods_number'] = $msku['sku_goods_number'];
|
||
}
|
||
}
|
||
}
|
||
/* 3-规格条码 */
|
||
if (in_array('code', $check_list)) {
|
||
if ($msku['sku_code'] && $msku['sku_code'] != $sku['sku_code']) {
|
||
$id = M('retail_sku_goods')->where(array('store_id' => $this->store_id, 'sku_code' => $msku['sku_code'], 'status' => 1, 'state' => 0))->getField('id');
|
||
if ($id) {
|
||
// 条码已存在
|
||
$res = array('status' => 0, 'msg' => '规格条码出现重复,规格更新失败');
|
||
return $res;
|
||
} else {
|
||
$up['sku_code'] = $msku['sku_code'];
|
||
$content['sku_code'] = $msku['sku_code'];
|
||
}
|
||
unset($id);
|
||
}
|
||
}
|
||
//重量
|
||
if (in_array('weight_value', $check_list)) {
|
||
if ($msku['weight_value'] && $msku['weight_value'] != $sku['weight_value']) {
|
||
$up['weight_value'] = $msku['weight_value'];
|
||
}
|
||
}
|
||
/* 4-零售价 */
|
||
if (in_array('retail_price', $check_list)) {
|
||
if ($msku['retail_price'] && $msku['retail_price'] != $sku['retail_price']) {
|
||
$up['retail_price'] = $msku['retail_price'];
|
||
}
|
||
}
|
||
/* 5-商城价 */
|
||
if (in_array('online_price', $check_list)) {
|
||
if ($msku['online_price'] && $msku['online_price'] != $sku['online_price']) {
|
||
$up['online_price'] = $msku['online_price'];
|
||
}
|
||
}
|
||
/* 6-门店会员价 */
|
||
if (in_array('store_vip_price', $check_list)) {
|
||
if ($msku['store_mem_price'] && $msku['store_mem_price'] != $sku['store_mem_price']) {
|
||
$up['store_mem_price'] = $msku['store_mem_price'];
|
||
}
|
||
}
|
||
/* 7-商城会员价 */
|
||
if (in_array('shop_vip_price', $check_list)) {
|
||
if ($msku['shop_mem_price'] && $msku['shop_mem_price'] != $sku['shop_mem_price']) {
|
||
$up['shop_mem_price'] = $msku['shop_mem_price'];
|
||
}
|
||
}
|
||
if (in_array('plus_price', $check_list)) {
|
||
if ($msku['plus_price'] && $msku['plus_price'] != $sku['plus_price']) {
|
||
$up['plus_price'] = round($msku['plus_price'], 2);
|
||
}
|
||
}
|
||
if ($content) {
|
||
D('SSaleMGoods')->updateData(array('goods_id' => $goods_id, 'sku_id' => $sku['id']), $content);
|
||
A('Api/Inventory')->SalesWarehouse($content, $this->store_id, $goods_id, $sku['id']);
|
||
}
|
||
if ($up) {
|
||
$save2 = M('retail_sku_goods')->where(array('id' => $sku['id']))->save($up);
|
||
if (!$save2) {
|
||
$res = array('status' => 0, 'msg' => '规格更新出现错误,中断规格更新');
|
||
return $res;
|
||
}
|
||
unset($up);
|
||
unset($save2);
|
||
}
|
||
unset($sku);
|
||
} else { // 门店暂无该规格 添加规格
|
||
$cr = $msku;
|
||
unset($cr['id']);
|
||
unset($cr['mgoods_id']);
|
||
unset($cr['merchantid']);
|
||
unset($cr['goods_num']);
|
||
unset($cr['pd_num']);
|
||
unset($cr['purch_price']);
|
||
$cr['store_id'] = $this->store_id;
|
||
$cr['goods_id'] = $goods_id;
|
||
$cr['sku_mgoods_id'] = $msku['id'];
|
||
$cr['add_time'] = time();
|
||
$add = M('retail_sku_goods')->add($cr);
|
||
if (!$add) {
|
||
$res = array('status' => 0, 'msg' => '规格更新出现错误,中断规格更新');
|
||
return $res;
|
||
}
|
||
$saleWarehouseId = D('SSaleWarehouse')->getFindField(array('merchant_id' => $this->merchant_id, 'store_id' => $this->store_id, 'status' => 1), "id");
|
||
if (!$saleWarehouseId) {
|
||
$res = array('status' => 0, 'msg' => '未找到供给仓库');
|
||
return $res;
|
||
}
|
||
$sku_name = M('retail_sku_list')->where(array('id' => array('in', $msku['sku_id_list'])))->getField('name', true);
|
||
$sku_name = implode(',', $sku_name);
|
||
$sale_add = array();
|
||
$sale_add['merchant_id'] = $this->merchant_id;
|
||
$sale_add['warehouse_id'] = $saleWarehouseId;
|
||
$sale_add['store_id'] = $this->store_id;
|
||
$sale_add['goods_class_id'] = $goods['goods_class_id'];
|
||
$sale_add['goods_id'] = $goods['id'];
|
||
$sale_add['goods_number'] = $goods['goods_number'];
|
||
$sale_add['sku_id'] = $add;
|
||
$sale_add['goods_name'] = $goods['goods_name'];
|
||
$sale_add['sku_name'] = $sku_name;
|
||
$sale_add['goods_number'] = $goods['goods_number'];
|
||
$sale_add['sku_goods_number'] = $msku['sku_goods_number'];
|
||
$sale_add['goods_code'] = $goods['goods_code'];
|
||
$sale_add['sku_code'] = $msku['sku_code'];
|
||
$sale_add['company'] = $goods['company'];
|
||
$sale_add['specifications'] = $goods['specifications'];
|
||
$sale_add['attribute_state'] = 2;
|
||
$sale_add['pricing_method'] = $goods['pricing_method'];
|
||
$sale_add['goods_brand_id'] = $goods['goods_brand_id'];
|
||
$sale_add['goods_yieldly_id'] = $goods['goods_yieldly_id'];
|
||
$sale_add['goods_num'] = 0;
|
||
$sale_add['sku_num'] = $msku['sku_num'];
|
||
$sale_add['sku_id_list'] = $msku['sku_id_list'];
|
||
$sale_add['more_num'] = $msku['more_num'];
|
||
$sale_add['less_num'] = $msku['less_num'];
|
||
$sale_add['status'] = $goods['status'];
|
||
$sale_add['add_time'] = time();
|
||
A('Api/Inventory')->addSaleGoods($sale_add, 1); //供给仓库添加
|
||
unset($cr);
|
||
unset($add);
|
||
}
|
||
unset($msku);
|
||
}
|
||
$res = array('status' => 1, 'msg' => '更新成功');
|
||
return $res;
|
||
}
|
||
|
||
public function updateGoodsPLU()
|
||
{
|
||
$id = I('get.id');
|
||
$map = array(
|
||
'id' => array('in', $id),
|
||
'status' => array('in', '0,1'),
|
||
'pricing_method' => 2,
|
||
'store_id' => $this->store_id
|
||
);
|
||
$goodsList = D('Goods')->getSelect($map, 'id,goods_name,goods_number,plu_code,goods_code', 'plu_code asc');
|
||
$this->assign('goodsList', json_encode($goodsList));
|
||
$this->display();
|
||
}
|
||
|
||
public function toUpdatePLU()
|
||
{
|
||
$goodsList = I('post.goodsList');
|
||
$errorArr = array();
|
||
$GoodsModel = new RetailGoodsModel();
|
||
foreach ($goodsList as $value) {
|
||
if ($value['plu_code'] != '' && !preg_match("/^[1-9]\d{0,3}$/", $value['plu_code'])) {
|
||
$errorArr[] = '货号为- ' . $value['goods_number'] . ' -的PLU序号有误';
|
||
} else {
|
||
if ($value['plu_code'] != '') {
|
||
$map = array(
|
||
'id' => array('neq', $value['id']),
|
||
'store_id' => $this->store_id,
|
||
'status' => array('in', '0,1'),
|
||
'plu_code' => $value['plu_code']
|
||
);
|
||
$old = $GoodsModel->getFind($map, 'id,plu_code');
|
||
} else {
|
||
$old = '';
|
||
}
|
||
if (!empty($old)) {
|
||
$errorArr[] = '货号为- ' . $value['goods_number'] . ' -的PLU序号已存在';
|
||
} else {
|
||
$up = $GoodsModel->updateOrder(array('id' => $value['id'], 'store_id' => $this->store_id), array('plu_code' => $value['plu_code']));
|
||
if (!$up) {
|
||
$errorArr[] = '货号为- ' . $value['goods_number'] . ' -的PLU序号更新失败';
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (empty($errorArr)) {
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = '商品档案-批量修改PLU码'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
|
||
$result = array(
|
||
'status' => 1,
|
||
'msg' => '更新成功'
|
||
);
|
||
} else {
|
||
$result = array(
|
||
'status' => 2,
|
||
'msg' => '更新失败'
|
||
);
|
||
if (count($errorArr) != count($goodsList)) {
|
||
array_push($errorArr, '其余的都已更新成功');
|
||
}
|
||
$result['errorData'] = $errorArr;
|
||
}
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
/**
|
||
* 获取下载标签的商品数据
|
||
*/
|
||
public function getDownLabelGoodsList()
|
||
{
|
||
$goods_number = I('post.goods_number');
|
||
$page = I('post.page');
|
||
$limit = I('post.limit');
|
||
//按照商品类别搜索
|
||
$person1 = I('post.person1');
|
||
$person2 = I('post.person2');
|
||
$person3 = I('post.person3');
|
||
|
||
if (!empty($goods_number)) {
|
||
$keyword = trim($goods_number);
|
||
$where['goods_number|goods_code|goods_name'] = array('like', '%' . $keyword . '%');
|
||
}
|
||
|
||
$flag = 0;
|
||
if (!empty($person3)) {
|
||
$where['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);
|
||
$where['goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1));
|
||
} else if ($flag == 1) {
|
||
$where['goods_class_id'] = $person2 ? $person2 : $person1;
|
||
}
|
||
$where['store_id'] = $this->store_id;
|
||
$where['status'] = array('in', array(0, 1));
|
||
//商品列表
|
||
$fields = array(
|
||
'id',
|
||
'goods_code',
|
||
'goods_number',
|
||
'retail_price',
|
||
'online_price',
|
||
'attribute_state',
|
||
'production_date',
|
||
'shelf_life',
|
||
'goods_name',
|
||
);
|
||
$goods = D('RetailGoods')->getSelect($where, $fields, "id desc", $page . ',' . $limit);
|
||
// echo M()->_sql();
|
||
$goods_count = M('retail_goods')->where($where)->count();
|
||
$time = date('Y-m-d H:i:s');
|
||
foreach ($goods as $key => &$value) {
|
||
$value['index'] = round($_GET['limit'] * ($_GET['page'] - 1) + $key + 1);
|
||
$value['goods_code'] = $value['goods_code'] ? $value['goods_code'] : '';
|
||
$value['goods_number'] = $value['goods_number'] ? $value['goods_number'] : '';
|
||
$value['subheading'] = $value['subheading'] ? $value['subheading'] : ''; //副标题
|
||
if (empty($value['shelf_life']) || empty($value['production_date'])) {
|
||
$value['shelf_life'] = '';
|
||
/*if(!empty($value['production_date'])){
|
||
$value['production_date'] = date('Y-m-d H:i:s', $value['production_date']);
|
||
}else{
|
||
$value['production_date'] = $time;
|
||
}*/
|
||
} else {
|
||
// 保质期 秒
|
||
$shelf_life = intval($value['shelf_life'] - $value['production_date']);
|
||
// 判断保质期
|
||
// $value['production_date'] = date('Y-m-d H:i:s', $value['production_date']);
|
||
if (is_int($shelf_life / 31536000) == true) {
|
||
$value['shelf_life'] = ($shelf_life / 31536000) . '年';
|
||
} else if (is_int($shelf_life / 2592000) == true) {
|
||
$value['shelf_life'] = ($shelf_life / 2592000) . '月';
|
||
} else if (is_int($shelf_life / 86400) == true) {
|
||
$value['shelf_life'] = ($shelf_life / 86400) . '天';
|
||
} else if (is_int($shelf_life / 3600) == true) {
|
||
$value['shelf_life'] = ($shelf_life / 3600) . '小时';
|
||
} else {
|
||
$value['shelf_life'] = '';
|
||
}
|
||
}
|
||
$value['production_date'] = $time;
|
||
}
|
||
$rt['code'] = 0;
|
||
$rt['msg'] = '';
|
||
$rt['count'] = $goods_count;
|
||
$rt['data'] = $goods;
|
||
$this->ajaxReturn($rt);
|
||
}
|
||
|
||
//获取商品规格信息
|
||
public function getDownLabelGoodsSku()
|
||
{
|
||
$id = I('post.id');
|
||
if (empty($id)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = "请求参数有误";
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$goods = M('retail_goods')->where(array('id' => $id, 'status' => array('in', '0,1')))->field('shelf_life,production_date')->find();
|
||
if (empty($goods)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = "商品不存在";
|
||
$this->ajaxReturn($res);
|
||
}
|
||
if (empty($goods['shelf_life']) || empty($goods['production_date'])) {
|
||
$goods['shelf_life'] = '';
|
||
/*if(!empty($goods['production_date'])){
|
||
$goods['production_date'] = date('Y-m-d H:i:s', $goods['production_date']);
|
||
}else{
|
||
$goods['production_date'] = date('Y-m-d H:i:s');
|
||
}*/
|
||
} else {
|
||
// 保质期 秒
|
||
$shelf_life = intval($goods['shelf_life'] - $goods['production_date']);
|
||
// 判断保质期
|
||
// $goods['production_date'] = date('Y-m-d H:i:s', $goods['production_date']);
|
||
if (is_int($shelf_life / 31536000) == true) {
|
||
$goods['shelf_life'] = ($shelf_life / 31536000) . '年';
|
||
} else if (is_int($shelf_life / 2592000) == true) {
|
||
$goods['shelf_life'] = ($shelf_life / 2592000) . '月';
|
||
} else if (is_int($shelf_life / 86400) == true) {
|
||
$goods['shelf_life'] = ($shelf_life / 86400) . '天';
|
||
} else if (is_int($shelf_life / 3600) == true) {
|
||
$value['shelf_life'] = ($shelf_life / 3600) . '小时';
|
||
} else {
|
||
$goods['shelf_life'] = '';
|
||
}
|
||
}
|
||
$goods['production_date'] = date('Y-m-d H:i:s');
|
||
$skuList = M('retail_sku_goods')->where(array('goods_id' => $id, 'state' => 0))->select();
|
||
$skuAttr = array();
|
||
if (!empty($skuList)) {
|
||
foreach ($skuList as &$value) {
|
||
$value['checked'] = false;
|
||
$id = explode(',', $value['sku_id_list']);
|
||
foreach ($id as &$v) {
|
||
$v = intval($v);
|
||
$value['name'][] = M('retail_sku_list')->where(array('id' => $v))->getField('name');
|
||
}
|
||
$value['shelf_life'] = $goods['shelf_life'];
|
||
$value['production_date'] = $goods['production_date'];
|
||
$value['online_price'] = floatval($value['online_price']) ? floatval($value['online_price']) : '';
|
||
$value['retail_price'] = floatval($value['retail_price']);
|
||
$value['id'] = $id;
|
||
$value['goods_img'] = $value['goods_img'] ? $value['goods_img'] : '/Public/Retail/goods/default.png';
|
||
if (!empty($value['goods_img_id'])) {
|
||
$value['goods_img'] = D('ImageGallery')->getOneField(array('id' => $value['goods_img_id']), 'path');
|
||
}
|
||
if ($value['goods_num'] == round($value['goods_num'])) {
|
||
$value['goods_num'] = round($value['goods_num']);
|
||
}
|
||
if ($value['sku_num'] == round($value['sku_num'])) {
|
||
$value['sku_num'] = round($value['sku_num']);
|
||
}
|
||
$value['sku_code'] = $value['sku_code'] ? $value['sku_code'] : '';
|
||
if (!empty($value['less_num'])) {
|
||
$value['less_num'] = round($value['less_num']);
|
||
}
|
||
}
|
||
//为了保证规格顺序
|
||
$skuAttr = array();
|
||
for ($i = 0; $i < count($skuList[0]['id']); $i++) {
|
||
$skuAttr[] = M('retail_sku_attr as s')
|
||
->join('ls_retail_sku_list as l on l.attr_id=s.id')
|
||
->where(array('s.state' => 0, 'l.id' => $skuList[0]['id'][$i]))
|
||
->group('l.attr_id')
|
||
->field('s.id,s.name')
|
||
->find();
|
||
}
|
||
}
|
||
$data['attr'] = $skuAttr;
|
||
$data['list'] = $skuList;
|
||
$this->ajaxReturn(array('data' => $data));
|
||
}
|
||
|
||
/**
|
||
* 门店供给仓商品上架,下架,删除
|
||
* $status 0上架 1下架 2删除
|
||
*/
|
||
public function updateSaleGoods($id, $sku_id, $status)
|
||
{
|
||
$data = array();
|
||
$data['goods_id'] = array('in', $id);
|
||
if (!empty($sku_id)) {
|
||
$data['sku_id'] = $sku_id;
|
||
}
|
||
$content['status'] = $status;
|
||
$res = D('SSaleMGoods')->updateData($data, $content);
|
||
if ($res['status'] == 0) {
|
||
$res['msg'] = '库存状况状态修改失败';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
public function changeGuideYoyalty()
|
||
{
|
||
$type = I('post.type');
|
||
if (empty($type)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '缺少参数';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$GoodsModel = D('RetailGoods');
|
||
$map = array(
|
||
$GoodsModel::STORE_ID => $this->store_id,
|
||
$GoodsModel::STATUS => array('in', '0,1'),
|
||
);
|
||
$save = array(
|
||
$GoodsModel::GUIDE_ROYALTY_STATE => $type == 1 ? 1 : 0,
|
||
);
|
||
$t_1 = mSecTime();
|
||
$update = $GoodsModel->updateOrder($map, $save);
|
||
$t_2 = mSecTime();
|
||
$res['sql_time'] = ($t_2 - $t_1) / 1000;
|
||
if ($update) {
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$user_type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
if ($type == 1) {
|
||
$desc = '商品档案-一键开启导购推广'; //操作行为描述
|
||
} else {
|
||
$desc = '商品档案-一键关闭导购推广'; //操作行为描述
|
||
}
|
||
action_log($source, $user_type, $request_data, $desc);
|
||
|
||
$res['status'] = 1;
|
||
$res['msg'] = '操作成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '操作失败';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 商品回收站
|
||
*/
|
||
public function recycle()
|
||
{
|
||
$class_name = M('retail_goods_class')->where(array('merchantid' => $this->merchant_id, 'status' => 0, 'type' => 1))->order('code asc')->select();
|
||
$this->assign('class_name', json_encode($class_name));
|
||
$this->display();
|
||
}
|
||
|
||
/**
|
||
* 拆分商品页面
|
||
*/
|
||
public function splitgoods()
|
||
{
|
||
$class_name = M('retail_goods_class')->where(array('merchantid' => $this->merchant_id, 'status' => 0, 'type' => 1))->order('code asc')->select();
|
||
$arr = array(
|
||
'splitgoodsset' => '/index.php/Retail/Goods/splitgoodsset',
|
||
'dosubmitsplit' => '/index.php/Retail/Goods/dosubmitsplit',
|
||
'record' => 'index.php/Retail/Goods/deleteRule',
|
||
'Delete' => '/index.php/Retail/Goods/recordList',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$this->assign('goodsClass1', json_encode($class_name));
|
||
$this->assign('supplier_type', session('ls_userinfo')['supplier_type']);
|
||
$this->display();
|
||
}
|
||
|
||
/**
|
||
* 获取商品的采购单
|
||
*/
|
||
public function getPurchaseList()
|
||
{
|
||
$sale_model = new SSaleMGoodsModel();
|
||
$goods_id = I("post.goods_id");
|
||
$sku_id = I("post.sku_id");
|
||
$parameter = array(
|
||
'store_id' => $this->store_id,
|
||
'goods_id' => $goods_id,
|
||
'sku_id' => $sku_id
|
||
);
|
||
$purchase_list = $sale_model->getPurchaseId($parameter);
|
||
$res = array(
|
||
'status' => 1,
|
||
'msg' => '查询成功',
|
||
'data' => array(
|
||
'purchase_list' => $purchase_list
|
||
)
|
||
);
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 拆分规则列表
|
||
*/
|
||
public function splitgoodslist()
|
||
{
|
||
$ruleListModel = D("StoreSplitRule");
|
||
$content = I("post.");
|
||
$page = $content['page'];
|
||
$limit = $content['limit'];
|
||
$name = $content['name'];
|
||
if (!empty($name)) {
|
||
$where['large_name | large_sku_name | small_name | small_sku_name | large_number | large_sku_number | large_code | large_sku_code | small_number | small_sku_number | small_code | small_sku_code'] = array('like', '%' . $name . '%');
|
||
}
|
||
$where['merchant_id'] = $this->merchant_id;
|
||
$where['store_id'] = $this->store_id;
|
||
$where['status'] = 1;
|
||
$ruleList = $ruleListModel->getSelect($where, $page, $limit);
|
||
if ($ruleList) {
|
||
$count = $ruleListModel->getCount($where);
|
||
$GoodsModel = new RetailGoodsModel();
|
||
$SkuAttributeClass = new SkuAttribute();
|
||
foreach ($ruleList as $key => &$val) {
|
||
$val['index'] = $key + 1;
|
||
$val['add_time'] = date("Y-m-d H:i:s", $val['add_time']);
|
||
$val['num'] = round($val['num'], 3);
|
||
switch ($val['large_attribute_state']) {
|
||
case 1:
|
||
//无规格
|
||
$val['large_name'] = $GoodsModel->getFindField(['id' => $val['large_goods_id']], 'goods_name');
|
||
break;
|
||
case 2:
|
||
//规格
|
||
$val['large_name'] = $val['large_name'] . ',' . $SkuAttributeClass->basisSkuIdGetSkuName(4, $val['large_sku_id']);
|
||
break;
|
||
}
|
||
switch ($val['small_attribute_state']) {
|
||
case 1:
|
||
//无规格
|
||
$val['small_name'] = $GoodsModel->getFindField(['id' => $val['small_goods_id']], 'goods_name');
|
||
break;
|
||
case 2:
|
||
//规格
|
||
$val['small_name'] = $val['small_name'] . ',' . $SkuAttributeClass->basisSkuIdGetSkuName(4, $val['small_sku_id']);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
$res['status'] = 1;
|
||
$res['msg'] = '查询成功';
|
||
$res['data'] = $ruleList;
|
||
$res['count'] = $count ? $count : 0;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 拆分规则选择的商品
|
||
*/
|
||
public function SSaleList()
|
||
{
|
||
$content = I("post.");
|
||
$page = $content['page'];
|
||
$limit = $content['limit'];
|
||
$searchText = $content['searchText'];
|
||
$notInIds = $content['notInIds'];
|
||
$person1 = $content['person1'];
|
||
$person2 = $content['person2'];
|
||
$person3 = $content['person3'];
|
||
if (!empty($searchText)) {
|
||
$where['goods_name | sku_name | goods_number | sku_goods_number | goods_code | sku_code'] = array('like', "%" . $searchText . "%");
|
||
}
|
||
if (!empty($notInIds)) {
|
||
$where['id'] = array('neq', $notInIds);
|
||
}
|
||
$flag = 0;
|
||
if (!empty($person3)) {
|
||
$where['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);
|
||
$where['goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1));
|
||
} else if ($flag == 1) {
|
||
$where['goods_class_id'] = $person2 ? $person2 : $person1;
|
||
}
|
||
$where['status'] = array('in', '0,1');
|
||
$where['merchant_id'] = $this->merchant_id;
|
||
$where['store_id'] = $this->store_id;
|
||
$where['serial_number_state'] = ['neq', 1];
|
||
$fields = "id,goods_id,sku_id,goods_name,sku_name,goods_number,sku_goods_number,company,attribute_state,pricing_method,goods_code,sku_code";
|
||
$SSaleMGoodsModel = new SSaleMGoodsModel();
|
||
$goodsList = $SSaleMGoodsModel->getSelect($where, $page, $limit, $fields);
|
||
if ($goodsList) {
|
||
$count = $SSaleMGoodsModel->getCount($where);
|
||
}
|
||
$res['status'] = 1;
|
||
$res['msg'] = '';
|
||
$res['count'] = $count ? $count : 0;
|
||
$res['data'] = $goodsList;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 添加规则
|
||
*/
|
||
public function splitgoodsset()
|
||
{
|
||
$StoreSplitRuleModel = D("StoreSplitRule");
|
||
$content = I("post.");
|
||
$LargeGoods = $content['LargeGoods'];
|
||
$SmallGoods = $content['SmallGoods'];
|
||
$num = $content['num'];
|
||
if (!$LargeGoods || !$SmallGoods || !$num) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数缺失';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$map = array(
|
||
'large_goods_id' => $LargeGoods['large_goods_id'],
|
||
'large_sku_id' => $LargeGoods['large_sku_id'],
|
||
'small_goods_id' => $SmallGoods['small_goods_id'],
|
||
'small_sku_id' => $SmallGoods['small_sku_id'],
|
||
'status' => 1
|
||
);
|
||
$id = $StoreSplitRuleModel->getFindField($map, "id");
|
||
if ($id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '该规则已存在';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$time = time();
|
||
$data = array(
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'large_goods_id' => $LargeGoods['large_goods_id'],
|
||
'large_sku_id' => $LargeGoods['large_sku_id'],
|
||
'large_attribute_state' => $LargeGoods['large_attribute_state'],
|
||
'large_pricing_method' => $LargeGoods['large_pricing_method'],
|
||
'large_name' => $LargeGoods['large_name'],
|
||
'large_sku_name' => $LargeGoods['large_sku_name'],
|
||
'large_number' => $LargeGoods['large_number'],
|
||
'large_sku_number' => $LargeGoods['large_sku_number'],
|
||
'large_code' => $LargeGoods['large_code'],
|
||
'large_sku_code' => $LargeGoods['large_sku_code'],
|
||
'small_goods_id' => $SmallGoods['small_goods_id'],
|
||
'small_sku_id' => $SmallGoods['small_sku_id'],
|
||
'small_attribute_state' => $SmallGoods['small_attribute_state'],
|
||
'small_pricing_method' => $SmallGoods['small_pricing_method'],
|
||
'small_name' => $SmallGoods['small_name'],
|
||
'small_sku_name' => $SmallGoods['small_sku_name'],
|
||
'small_number' => $SmallGoods['small_number'],
|
||
'small_sku_number' => $SmallGoods['small_sku_number'],
|
||
'small_code' => $SmallGoods['small_code'],
|
||
'small_sku_code' => $SmallGoods['small_sku_code'],
|
||
'large_company' => $LargeGoods['large_company'],
|
||
'small_company' => $SmallGoods['small_company'],
|
||
'num' => round($num, 3),
|
||
'add_time' => $time,
|
||
'status' => 1,
|
||
);
|
||
$res = $StoreSplitRuleModel->addData($data);
|
||
if ($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);
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 删除规则
|
||
*/
|
||
public function deleteRule()
|
||
{
|
||
$StoreSplitRuleModel = D("StoreSplitRule");
|
||
$id = I("post.id");
|
||
$res = $StoreSplitRuleModel->updateData(array('id' => $id), array('status' => 2));
|
||
if ($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);
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 拆分组合操作
|
||
*/
|
||
public function dosubmitsplit()
|
||
{
|
||
$operator_id = session("jurisdiction_user")['id'];
|
||
$supplier_type = session("ls_userinfo")['supplier_type'];
|
||
$data = I("post.");
|
||
if (!$data['id'] || !$data['operation_type'] || !$data['operation_num']) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数缺失';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$parameter = array(
|
||
'store_id' => $this->store_id,
|
||
'merchant_id' => $this->merchant_id,
|
||
'operator_id' => $operator_id,
|
||
'operation_type' => $data['operation_type'], //1拆分 2组合
|
||
'id' => $data['id'], //规则id
|
||
'operation_num' => $data['operation_num'], //操作数量
|
||
'supplier_type' => $supplier_type, //1供货商类型
|
||
'purchase_order_id' => $data['purchase_order_id'], //采购id
|
||
'split_type' => 1, //1手动 2自动
|
||
'operator_type' => 1 //后台端
|
||
);
|
||
$goodsSplit = new GoodsSplit();
|
||
$result = $goodsSplit->goodsSplitMakeUp($parameter); //拆分与组合
|
||
if ($result['status'] == 1) {
|
||
//操作日志记录
|
||
switch ($data['operation_type']) {
|
||
case 1:
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = '拆分组合-拆分'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
break;
|
||
case 2:
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = '拆分组合-组合'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
break;
|
||
}
|
||
}
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
/**
|
||
* 拆分组合记录
|
||
*/
|
||
public function recordList()
|
||
{
|
||
$data = I("post.");
|
||
$rule_id = $data['rule_id'];
|
||
$page = $data['page'];
|
||
$limit = $data['limit'];
|
||
$where['rule_id'] = $rule_id;
|
||
$list = D("StoreSplitRecord")->getSelect($where, $page, $limit);
|
||
if ($list) {
|
||
$ruleInfo = D("StoreSplitRule")->getFind(array('id' => $rule_id));
|
||
$count = D("StoreSplitRecord")->getCount($where);
|
||
foreach ($list as $key => &$val) {
|
||
$val['index'] = $key + 1;
|
||
$val['large_name'] = $ruleInfo['large_name'];
|
||
$val['small_name'] = $ruleInfo['small_name'];
|
||
$val['num'] = round($ruleInfo['num']);
|
||
$val['large_num'] = round($val['large_num'], 3);
|
||
$val['small_num'] = round($val['small_num'], 3);
|
||
$val['add_time'] = date("Y-m-d H:i:s", $val['add_time']);
|
||
if ($val['type'] == 1) {
|
||
$val['type_name'] = "拆分";
|
||
} else if ($val['type'] == 2) {
|
||
$val['type_name'] = "组合";
|
||
}
|
||
}
|
||
}
|
||
$res['status'] = 1;
|
||
$res['count'] = $count ? $count : 0;
|
||
$res['msg'] = "";
|
||
$res['data'] = $list;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 商品导入
|
||
*/
|
||
public function goods_import()
|
||
{
|
||
$this->display();
|
||
}
|
||
|
||
/**
|
||
* 获取导入商品列表
|
||
*/
|
||
public function getGoodsList()
|
||
{
|
||
$data = I('post.');
|
||
$goods = new Goods();
|
||
$result = $goods->getImportGoodsList([
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'user_type' => 2,
|
||
'status' => $data['type'],
|
||
'searchText' => $data['searchText'],
|
||
'page' => $data['page'],
|
||
'limit' => $data['limit']
|
||
]);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
/**
|
||
* 导入商品表数据同步到商品档案
|
||
*/
|
||
public function submitToMGoods()
|
||
{
|
||
$platform_type = $this->role_info['platform_type'] ? $this->role_info['platform_type'] : 1;
|
||
$checkGoodsArr = I('post.checkgoodsarr');
|
||
$goodsClass = new GoodsClass();
|
||
$result = $goodsClass->storeGoodsImportBatch([
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => session('storeid'),
|
||
'checkGoodsArr' => $checkGoodsArr,
|
||
'platform_type' => $platform_type
|
||
]);
|
||
if ($result['status'] == 1) {
|
||
$remark = $result['remark'];
|
||
if ($remark == '') {
|
||
//操作日志记录
|
||
$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'] = '部分商品同步失败';
|
||
$res['remark'] = explode(',', trim($remark, ','));
|
||
}
|
||
} else {
|
||
$res = ['status' => 0, 'remark' => explode(',', trim($result['remark'], ','))];
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
|
||
/**
|
||
* 商品导入文件上传以及存导入表
|
||
* user_type 1商户后台 2门店后台
|
||
* @throws \PHPExcel_Exception
|
||
* @throws \PHPExcel_Reader_Exception
|
||
*/
|
||
public function uploadFile()
|
||
{
|
||
ini_set('memory_limit', -1);
|
||
ini_set('max_execution_time', '60');
|
||
$platform_type = $this->role_info['platform_type'] ? $this->role_info['platform_type'] : 1;
|
||
$goods = new Goods();
|
||
$result = $goods->goodsImportOperation([
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'user_type' => 4,
|
||
'operator_type' => 1,
|
||
'attribute_state' => I('post.attribute_state'),
|
||
'platform_type' => $platform_type
|
||
]);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
/**
|
||
* 商品导入的表批量删除
|
||
* user_type 1商户后台 2门店后台
|
||
* idArr 删除的id集合
|
||
*/
|
||
public function importGoodsOut()
|
||
{
|
||
$checkgoodsarr = I('post.checkgoodsarr');
|
||
$goodsClass = new Goods();
|
||
$result = $goodsClass->importGoodsOut([
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => session("storeid"),
|
||
'user_type' => 2,
|
||
'idArr' => $checkgoodsarr
|
||
]); //删除数据
|
||
if ($result) {
|
||
//操作日志记录
|
||
$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,
|
||
'msg' => '删除成功',
|
||
'data' => $checkgoodsarr
|
||
];
|
||
} else {
|
||
$res = [
|
||
'status' => 0,
|
||
'msg' => '删除失败'
|
||
];
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
|
||
/**
|
||
* 下载商品导入失败的表格
|
||
* user_type 1商户后台 2门店后台
|
||
*/
|
||
public function downFailFile()
|
||
{
|
||
ini_set('memory_limit', -1);
|
||
ini_set('max_execution_time', '60');
|
||
$platform_type = $this->role_info['platform_type'] ? $this->role_info['platform_type'] : 1;
|
||
$DownFileClass = new DownFile();
|
||
$DownFileClass->GoodsImportFail([
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'user_type' => 4,
|
||
'attribute_state' => I('get.attribute_state'),
|
||
'platform_type' => $platform_type
|
||
]);
|
||
}
|
||
|
||
|
||
/**
|
||
* 导入商品模板下载
|
||
*/
|
||
public function downModelFile()
|
||
{
|
||
$platform_type = $this->role_info['platform_type'] ? $this->role_info['platform_type'] : 1;
|
||
$downFile = new DownFile();
|
||
$downFile->GoodsTemplate($platform_type);
|
||
}
|
||
|
||
/**
|
||
* 获取商品产地供选择
|
||
*/
|
||
public function getGoodsYieldlyList()
|
||
{
|
||
$YieldlyApi = new Yieldly();
|
||
$data = $YieldlyApi->getUsedGoodsYieldlyList($this->merchant_id);
|
||
$this->ajaxReturn(array(
|
||
'status' => 1,
|
||
'msg' => $data ? '获取成功' : '暂无标签',
|
||
'data' => $data ? $data : array(),
|
||
));
|
||
}
|
||
|
||
/**
|
||
* 添加商品产地
|
||
*/
|
||
public function addGoodsYieldly()
|
||
{
|
||
$YieldlyApi = new Yieldly();
|
||
$param = array(
|
||
'name' => I('post.name'), //品牌名
|
||
'store_id' => $this->store_id,
|
||
'merchant_id' => $this->merchant_id,
|
||
);
|
||
$data = $YieldlyApi->addGoodsYieldly($param);
|
||
$this->ajaxReturn(array(
|
||
'status' => $data['status'],
|
||
'msg' => $data['message'],
|
||
'data' => $data['data'] ? $data['data'] : array(),
|
||
));
|
||
}
|
||
|
||
//简拼商品
|
||
public function simple()
|
||
{
|
||
$GoodsClassify = new GoodsClassify();
|
||
$result = $GoodsClassify->getGoodsClassTopLevel($this->merchant_id);
|
||
$class_name = $result['data']['list'];
|
||
$this->assign('goodsClass1', json_encode($class_name));
|
||
$arr = [
|
||
'updateGoods' => '/index.php/Retail/Goods/batchPinYin',
|
||
'generate' => '/index.php/Retail/Goods/generatePinYin',
|
||
];
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$this->display();
|
||
}
|
||
|
||
/**
|
||
* 简拼商品列表
|
||
*/
|
||
public function getSimpleGoods()
|
||
{
|
||
$data = I('post.');
|
||
$data['store_id'] = $this->store_id;
|
||
$GoodsClass = new Goods();
|
||
$result = $GoodsClass->getStoreGoodsList($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
//一键生成简拼
|
||
public function generatePinYin()
|
||
{
|
||
ini_set('memory_limit', -1);
|
||
$data = I('post.');
|
||
$data['type'] = 2;
|
||
$data['store_id'] = $this->store_id;
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$GoodsClass = new Goods();
|
||
$result = $GoodsClass->generateSimpleSpelling($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
//批量修改简拼
|
||
public function batchPinYin()
|
||
{
|
||
$data = I('post.');
|
||
$data['type'] = 2;
|
||
$data['store_id'] = $this->store_id;
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$GoodsClass = new Goods();
|
||
$result = $GoodsClass->batchSimpleSpelling($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
/**
|
||
* 批量修改商品的某个字段值(配送方式例外)
|
||
*/
|
||
public function batchOperateGoods()
|
||
{
|
||
if (IS_POST) {
|
||
$user = session('jurisdiction_user');
|
||
$OperateGoods = new OperateGoods();
|
||
$result = $OperateGoods->batchOperateGoods([
|
||
'store_id' => $this->store_id,
|
||
'user_type' => $user['login_type'],
|
||
'operate_id' => $user['id'],
|
||
'key' => I('post.key'),
|
||
'value' => I('post.value'),
|
||
'delivery_template_id' => I('post.delivery_template_id'),
|
||
'goodsIds' => I('post.goodsIds'),
|
||
]);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
}
|
||
|
||
|
||
//导出
|
||
public function exportGoods()
|
||
{
|
||
ini_set('memory_limit', -1);
|
||
ini_set('max_execution_time', '60');
|
||
$data = I('post.');
|
||
$searchForm = $data['searchForm'];
|
||
unset($data['searchForm']);
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$data['store_id'] = $this->store_id;
|
||
$data['platform_type'] = $this->role_info['platform_type'] ? $this->role_info['platform_type'] : 1;
|
||
$data['user_type'] = 4;
|
||
$data['operator_type'] = 1;
|
||
$data['searchText'] = $searchForm['keyword'];
|
||
$data['keyword_type'] = $searchForm['keyword_type'];
|
||
$data['pricing_method'] = $searchForm['pricing_method'];
|
||
$data['condition_name'] = $searchForm['condition_name'];
|
||
$data['advance_sale_status'] = $searchForm['advance_sale_status'];
|
||
$data['person1'] = $searchForm['person1'];
|
||
$data['person2'] = $searchForm['person2'];
|
||
$data['person3'] = $searchForm['person3'];
|
||
$data['status'] = $searchForm['status'];
|
||
$GoodsClass = new Goods();
|
||
$result = $GoodsClass->exportGoods($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
//下载文件
|
||
public function exportFile()
|
||
{
|
||
ini_set('memory_limit', -1);
|
||
$attribute_state = I('get.attribute_state');
|
||
if ($attribute_state == 2) {
|
||
$file_name = '规格商品导出';
|
||
} else {
|
||
$file_name = '非规格商品导出';
|
||
}
|
||
$DownFileClass = new DownFile();
|
||
$DownFileClass->downFile([
|
||
'file_path' => I('get.file_path'),
|
||
'file_name' => $file_name,
|
||
'file_type' => '.xls'
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* 2021.5.10,11:51
|
||
* plu码
|
||
*/
|
||
//自动生成PLU码
|
||
public function generateStorePlu()
|
||
{
|
||
$storeId = $this->store_id;//门店id
|
||
|
||
$where = [
|
||
'store_id' => $storeId,
|
||
'status' => ['in', ['0', '1']],//状态:0,正常,1,下架,2,删除
|
||
];
|
||
$field = [
|
||
'plu_code',//plu码
|
||
];
|
||
$order = 'plu_code desc';
|
||
|
||
$retailGoodsModel = new RetailGoodsModel();
|
||
$retailGoods = $retailGoodsModel->getOrderFind($where, $field, $order);//商品最大PLU码
|
||
|
||
$whereSku = [
|
||
'store_id' => $storeId,
|
||
'state' => 0,//0正常 1删除
|
||
];
|
||
$retailSkuGoodsModel = new RetailSkuGoodsModel();
|
||
$skuGoods = $retailSkuGoodsModel->getOrderFind($whereSku, $field, $order);//规格最大PLU码
|
||
|
||
if ($retailGoods === false || $skuGoods === false) {
|
||
$res = callBack(statusCode()['error'], '失败');
|
||
} else {
|
||
//判断是否为null处理
|
||
if ($retailGoods == null || $retailGoods['plu_code'] == null) {
|
||
$goodPluCode = 0;
|
||
} else {
|
||
$goodPluCode = $retailGoods['plu_code'];
|
||
}
|
||
//判断是否为null处理
|
||
if ($skuGoods == null || $skuGoods['plu_code'] == null) {
|
||
$skuPluCode = 0;
|
||
} else {
|
||
$skuPluCode = $skuGoods['plu_code'];
|
||
}
|
||
//选择最大值
|
||
if ($goodPluCode >= $skuPluCode) {
|
||
$data = $goodPluCode;
|
||
} else {
|
||
$data = $skuPluCode;
|
||
}
|
||
|
||
$res = callBack(statusCode()['success'], '成功', $data);
|
||
}
|
||
$this->ajaxReturn($res);
|
||
|
||
}
|
||
|
||
//重置PLU码
|
||
public function resetStorePlu()
|
||
{
|
||
$storeId = $this->store_id;//门店id
|
||
$post = I('post.');
|
||
//条件: 1:不称重 2:称重 ,3全部
|
||
if (isset($post['pricing_method']) && $post['pricing_method'] !== '') {
|
||
if ($post['pricing_method'] == 1 || $post['pricing_method'] == 2) {
|
||
$wherePricingMethod = [
|
||
'pricing_method' => $post['pricing_method'],
|
||
];
|
||
} else {
|
||
$wherePricingMethod = [];
|
||
}
|
||
} else {
|
||
$wherePricingMethod = [];
|
||
}
|
||
//获取最大PLU码
|
||
if (isset($post['plu_code']) && $post['plu_code'] !== '' && $post['plu_code'] > 0) {
|
||
$pluCode = $post['plu_code'];
|
||
} else {
|
||
$pluCode = 0;
|
||
}
|
||
//商品id,获取修改阶段
|
||
if (isset($post['goodId']) && $post['goodId'] !== '') {
|
||
$whereId = [
|
||
'id' => ['gt', $post['goodId']],
|
||
];
|
||
} else {
|
||
$whereId = [];
|
||
}
|
||
|
||
$where = [
|
||
'store_id' => $storeId,
|
||
'status' => ['in', ['0', '1']],//状态:0,正常,1,下架,2,删除
|
||
];
|
||
$field = [
|
||
'id',
|
||
'plu_code',//plu码
|
||
];
|
||
|
||
// 启动事务(tp3.2)
|
||
M()->startTrans();
|
||
try {
|
||
$retailGoodsModel = new RetailGoodsModel();
|
||
$retailSkuGoodsModel = new RetailSkuGoodsModel();
|
||
//清空原有的PLU码
|
||
if ($pluCode == 0) {
|
||
$saveNull = [
|
||
'plu_code' => null,
|
||
];
|
||
$retailGoodsModel->updateOrder($where, $saveNull);
|
||
|
||
$whereSkuNull = [
|
||
'store_id' => $storeId,
|
||
'state' => 0,//0正常 1删除
|
||
];
|
||
$retailSkuGoodsModel->updateOrder($whereSkuNull, $saveNull);
|
||
}
|
||
|
||
$retailGoods = $retailGoodsModel->where($where)->where($whereId)->where($wherePricingMethod)->limit(50)->field($field)->select();//获取重置商品
|
||
if ($retailGoods == null) {
|
||
//为null,说明商品PLU码,已经重置完毕
|
||
$res = callBack(statusCode()['success'], '成功', null);
|
||
$this->ajaxReturn($res);
|
||
}
|
||
//获取商品的,ids
|
||
$skuGoodIds = [];
|
||
foreach ($retailGoods as $k => $v) {
|
||
$skuGoodIds[$k] = $v['id'];
|
||
//生成符合条件的商品数组
|
||
$v['plu_code'] = $pluCode + $k + 1;
|
||
$retailGoods[$k] = $v;
|
||
}
|
||
//商品PLU码值判断
|
||
if ($retailGoods && $retailGoods[count($retailGoods) - 1]['plu_code'] > 9999) {
|
||
$res = callBack(statusCode()['error'], 'PLU码已达上限!');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
//修改商品PLU码
|
||
foreach ($retailGoods as $k => $v) {
|
||
$whereGoodSave = [
|
||
'id' => $v['id']
|
||
];
|
||
$goodSave = [
|
||
'plu_code' => $v['plu_code']
|
||
];
|
||
$retailGoodsModel->updateOrder($whereGoodSave, $goodSave);
|
||
}
|
||
|
||
//获取商品规格
|
||
$skuGoodsWhere = [
|
||
'store_id' => $storeId,
|
||
'goods_id' => ['in', $skuGoodIds],
|
||
'state' => 0,//0正常 1删除
|
||
];
|
||
$skuGoods = $retailSkuGoodsModel->where($skuGoodsWhere)->field($field)->select();//获取商品规格
|
||
//生成符合条件的规格数组
|
||
foreach ($skuGoods as $k => $v) {
|
||
$v['plu_code'] = $retailGoods[count($retailGoods) - 1]['plu_code'] + $k + 1;
|
||
$skuGoods[$k] = $v;
|
||
}
|
||
//规格PLU码值判断
|
||
if ($skuGoods && $skuGoods[count($skuGoods) - 1]['plu_code'] > 9999) {
|
||
$res = callBack(statusCode()['error'], 'PLU码已达上限!');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
//修改商品规格PLU码
|
||
foreach ($skuGoods as $k => $v) {
|
||
$whereSkuGoodSave = [
|
||
'id' => $v['id']
|
||
];
|
||
$skuGoodSave = [
|
||
'plu_code' => $v['plu_code']
|
||
];
|
||
$retailSkuGoodsModel->updateOrder($whereSkuGoodSave, $skuGoodSave);
|
||
}
|
||
//商品数组,最后的值
|
||
$data['goodId'] = $retailGoods[count($retailGoods) - 1]['id'];
|
||
//最大PLU码
|
||
if ($retailGoods[count($retailGoods) - 1]['plu_code'] > $skuGoods[count($skuGoods) - 1]['plu_code']) {
|
||
$data['pluCode'] = $retailGoods[count($retailGoods) - 1]['plu_code'];
|
||
} else {
|
||
$data['pluCode'] = $skuGoods[count($skuGoods) - 1]['plu_code'];
|
||
}
|
||
|
||
M()->commit();// 提交事务
|
||
$res = callBack(statusCode()['success'], '成功', $data);
|
||
} catch (\Exception $e) {
|
||
// 回滚事务
|
||
M()->rollback();
|
||
$res = callBack(statusCode()['error'], '失败');
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|