/**
* @title 装修店铺
* @param plate_id 是 int 店铺装修样式ID
* @param type 是 int 模板样式子板块类型(4-海景、6-二宫格、8-三宫格、9-四宫格)
* @param sort 是 int 模块排序位置
* @param sku_id 是 string 商品sku_id
* @param index 是 int 商品sku排序位置
* @param operate_type 是 int 1-替换商品、2-删除商品
* @param type_id 否 int 装修商品的类型(1-平台商品、2-特色商品)
* @example FlagShipShopDecorate.decorateShop? 调试参数:{"operate_type":"1","username":"17721355485","check_code":"123456","method":"FlagShipShopDecorate.decorateShop","plate_id":1,"type":8,"sort":"3","sku_id": "8032717999","index":"1","type_id":"1"}
* @return {"status":"0","errorCode":"0","msg":"成功","result":true}
* @method POST
* @author 邹柯
*/
public function decorateShop($res){
$user_id=session("user.user_id");
$plate_id=$res['plate_id'];
if(empty($plate_id)){
E('');
}
$type=$res['type'];
if($type != && $type != && $type != && $type !=){
E('');
}
$type_id=$res['type_id'];
if($type_id != && $type_id !=){
E('');
}
$sort=$res['sort'];
if(!is_numeric($sort) || $sort <= ){
E('');
}
$sku_id=$res['sku_id'];
if(empty($sku_id)){
E('');
}
$index=$res['index'];
if(!is_numeric($index) || $index <= ){
E('');
}
$operate_type=$res['operate_type'];
if($operate_type != && $operate_type !=){
E('');
}
$user_shop_decorate=M('user_shop_decorate');
$where['flagship_shop']=;
$where['create_id']=$user_id;
$usd_info=$user_shop_decorate->field('id,plate_id,plate_content_draft,plate_content_draft_features,select_status')->where($where)->order('create_time desc')->find();
if($type_id==){
if(empty($usd_info['plate_content_draft'])){
$plate_content_draft=$this->getDefaultStyleByPlateId($plate_id,$type_id);
}else{
$plate_content_draft=json_decode($usd_info['plate_content_draft'],true);
}
}else{
if(empty($usd_info['plate_content_draft_features'])){
$plate_content_draft=$this->getDefaultStyleByPlateId($plate_id,$type_id);
}else{
$plate_content_draft=json_decode($usd_info['plate_content_draft_features'],true);
}
} foreach($plate_content_draft as $k=>$v){
if($v['type']==$type && $v['sort']==$sort){
foreach($v['goods'] as $k2=>$v2){
if($v2['index']==$index){
$plate_content_draft[$k]['goods'][$k2]['sku_id']=$sku_id;
$plate_content_draft[$k]['goods'][$k2]['operate_type']=$operate_type;
}
}
}
}
$plate_content_draft_arr=json_encode($plate_content_draft);
$time=date("Y-m-d H:i:s",time());
if(!empty($usd_info)){ //修改
$u_where['id']=$usd_info['id'];
if($type_id==){
$data=array(
'plate_id' => $plate_id,
'plate_content_draft'=>$plate_content_draft_arr,
'status'=>,
'update_time'=>$time,
'update_id'=>$user_id,
'select_status'=>,
);
}else{
$data=array(
'plate_id_features' => $plate_id,
'plate_content_draft_features'=>$plate_content_draft_arr,
'status'=>,
'update_time'=>$time,
'update_id'=>$user_id,
'select_status'=>,
);
}
$res=$user_shop_decorate->data($data)->where($u_where)->save();
if(!$res && $res !=){
E('');
}
}else{ //添加
if($type_id==) {
$data = array(
'plate_id' => $plate_id,
'plate_content_draft' => $plate_content_draft_arr,
'status' => ,
'create_time' => $time,
'create_id' => $user_id,
'update_time' => $time,
'update_id' => $user_id,
'use_status' => ,
'select_status' =>
);
}else{
$data = array(
'plate_id_features' => $plate_id,
'plate_content_draft_features' => $plate_content_draft_arr,
'status' => ,
'create_time' => $time,
'create_id' => $user_id,
'update_time' => $time,
'update_id' => $user_id,
'use_status' => ,
'select_status' =>
);
}
$res=$user_shop_decorate->data($data)->add();
if(!$res){
E('');
}
}
$usd_where['plate_id']=array("neq",$plate_id);
$usd_where['create_id']=$user_id;
$res_info=$user_shop_decorate->data(['select_status'=>])->where($usd_where)->save();
if(!$res_info && $res_info !=){
E('');
}
return true;
}
    //根据指定样式id获取样式下的默认商品信息
public function getDefaultStyleByPlateId($plate_id,$type_id){
$shop_decorate_template=M('shop_decorate_template');
$sd_where['id']=$plate_id;
$sd_where['is_deleted']=;
$sdt_info=$shop_decorate_template->field('id,plate_content,goods_nums')->where($sd_where)->find();
$plate_content=json_decode($sdt_info['plate_content'],true);
if($type_id==){
$goods_info=$this->getDefaultGoodsInfo($sdt_info['goods_nums'],"sell_nums desc",null,null,null,null,null,null,null,true,$plate_id);
foreach($goods_info as $k=>$v){
unset($goods_info[$k]['activity_info']);
unset($goods_info[$k]['store_id']);
unset($goods_info[$k]['sell_nums']);
unset($goods_info[$k]['sell_price']);
unset($goods_info[$k]['img']);
unset($goods_info[$k]['title']);
unset($goods_info[$k]['sku_no']);
unset($goods_info[$k]['short_name']);
unset($goods_info[$k]['search_name']);
unset($goods_info[$k]['product_id']);
unset($goods_info[$k]['imgs']);
unset($goods_info[$k]['seascapes']);
$goods_info[$k]['index']=$k+;
}
$total_nums=;
foreach($plate_content as $k=>$v){
$at=array_slice($goods_info,$total_nums,$v['goods_nums']);
$plate_content[$k]['goods']=$at;
$total_nums +=$v['goods_nums'];
unset($plate_content[$k]['goods_nums']);
}
}else{
$goods_info=$this->getDefaultGoodsNull($sdt_info['goods_nums'],$type_id);
$total_nums=;
foreach($plate_content as $k=>$v){
$at=array_slice($goods_info,$total_nums,$v['goods_nums']);
$plate_content[$k]['goods']=$at;
$total_nums +=$v['goods_nums'];
}
} return $plate_content;
} //获取默认空商品
public function getDefaultGoodsNull($goods_nums,$type_id){
$user_id=session("user.user_id");
$store=M('store');
$s_where['user_id']=$user_id;
$store_id=$store->where($s_where)->getField('id');
$store_goods=M('store_goods');
$gs_where['is_deleted']=;
$gs_where['is_open']=;
if($type_id==){
$gs_where['pt_cats']="0/1";
}else{
$gs_where['store_id']=$store_id;
}
$gs_info=$store_goods->where($gs_where)->field('sku_id')->find();
for($i=;$i<$goods_nums;$i++){
$goods[]=[
'sku_id'=>$gs_info['sku_id'],
'operate_type'=>,
'index'=>$i+
];
}
return $goods;
}

php 实现店铺装修3的更多相关文章

  1. 关于淘宝店铺装修弹出层popup的记录

    小龙最近做了一下下淘宝的店铺装修,里面封装的widget深不见底,刚刚整明白popup,也就是弹出层的使用方法,大神勿喷: <div class="area001">触 ...

  2. Adobe Photoshop CC2018最新教程+某宝店铺装修教程

    PS免费教程,ps淘宝店铺装修教程.该资源为本人从某商网站重金买来,现免费分享给大家,下载地址:百度网盘,https://pan.baidu.com/s/127PjFbGwVVUVce1litHFsw

  3. php 实现店铺装修5

    /** * @title 选中蜂店装修模板样式 * @param plate_id 是 int 商品(平台或特色)装修样式ID * @param type_id 是 int 要装修商品的类型(1-平台 ...

  4. php 实现店铺装修6

    /** * @title 获取预览或发布的蜂店模板样式 * @param store_id 是 string 店铺id * @param type 是 int 装修模板的状态:1-预览蜂店装修模板样式 ...

  5. php 实现店铺装修7

    type_id=0的情况 type_id=1的情况                         type_id=2的情况 /** * @title 店铺装修--商品分类 * @param type ...

  6. php 实现店铺装修8

    /** * @title 店铺装修--根据分类获取商品列表 * @param source 是 int 来源(1--h5.2--app) * @param type 是 string 店铺类型--首页 ...

  7. php 实现店铺装修2

    <?php namespace Webapp\Model; use Common\Model\DataModel\FlagShopCategoryModel; use Common\Model\ ...

  8. php 实现店铺装修1

    一.原型分析 1.店铺未装修的情况下,使用默认样式,哪个是默认样式由后台告知: 2.所有的样式由后台进行维护(但后台始终有一个默认样式,不可删除不可编辑),所有样式,只要用户未编辑过,则默认按照商品的 ...

  9. php 实现店铺装修4

    /** * @title 发布装修的店铺 * @example FlagShipShopDecorate.fabu? 调试参数:{"username":"17721355 ...

随机推荐

  1. 【代码学习】PYTHON 抛出异常

    class ShortInputException(Exception): '''你定义的异常类.''' def __init__(self, length, atleast): Exception. ...

  2. python splash scrapy

    python splash scrapy 1.      前言 slpash是一个渲染引擎,它有自己的api,可以直接访问splash服务的http接口,但也有对应的包python-splash方便调 ...

  3. 26 JavaScript HTML DOM简介&方法&文档

    HTML DOM: Document  Object  Model 文档对象模型.是HTML的标准对象模型和编程接口.(JavaScript只是可以操作HTML DOM的语言之一) 定义了HTML元素 ...

  4. Nexus-vPC相关特性

    vPC Peer-switch: 不开启这功能,只有Primary设备发送BPDU,开启之后,将会把这一对设备呈现为一个STP Root,使用一个MAC地址,那么都可以发送BPDU了.STP BPDU ...

  5. POJ1797 Heavy Transportation (堆优化的Dijkstra变形)

    Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand bus ...

  6. 【PAT甲级】1066 Root of AVL Tree (25 分)(AVL树建树模板)

    题意: 输入一个正整数N(<=20),接着输入N个结点的值,依次插入一颗AVL树,输出最终根结点的值. AAAAAccepted code: #define HAVE_STRUCT_TIMESP ...

  7. dense向量和稀疏向量sparse

    import org.apache.spark.mllib.linalg.Vectors object Test { def main(args: Array[String]) { val vd = ...

  8. 定时任务--mysql数据库备份

    vim /home/back.sh #!/bin/bash USER="******" PASSWORD="******" DATABASE="*** ...

  9. Pytorch-Faster-RCNN 中的 MAP 实现 (解析imdb.py 和 pascal_voc.py)

    ---恢复内容开始--- MAP是衡量object dectection算法的重要criteria,然而一直没有仔细阅读相关代码,今天就好好看一下: 1. 测试test过程是由FRCN/tools/t ...

  10. 条件语句(if语句)的用法

    if语句是实现分支结构的常用分支语句之一,另外还有条件运算符.switch语句等. if语句的功能是:根据给定条件,选择程序执行方向. if语句的基本格式 “if语句”又称条件语句,其基本格式为:  ...