PHPを上に移動、下に移動、上に置く操作
15547 ワード
/**
* ,
*
*/
public function goodsResort(){
$this->load->model('CmsFilmGoods');
//
$params = $this->input->post(NULL, true);
// SKU
$goods_sku = $params['sku'];
// ID
$film_id = $params['film_id'];
//
$sort_type = $params['type'];
if(!$film_id || !$goods_sku || !$sort_type){
$this->response('300000201', " ");
}
//
$goods_info = $this->CmsFilmGoods->getRow(['film_id' => $film_id, 'goods_sku' => $goods_sku, 'status' => 0], 'id, sort');
if(!isset($goods_info['id'])){
$this->response('300000202', " ");
}
//
switch ($sort_type)
{
case 1:
//
$goods_before = $this->CmsFilmGoods->getOne('film_id = '.$film_id.' and goods_sku > 0 and status=0 and sort < '.$goods_info['sort'], 'id, sort', " sort desc");
var_dump($goods_before);
if($goods_info['sort'] == 1 || !isset($goods_before['id'])){
//
$this->response('300000203', " ");
}
$sql = 'UPDATE cms_film_goods SET sort = CASE id WHEN '.$goods_info['id'].' THEN '.$goods_before['sort'].' WHEN '.$goods_before['id'].' THEN '.$goods_info['sort'].' END WHERE id IN ('.$goods_info['id'].', '.$goods_before['id'].')';
$res = $this->CmsFilmGoods->query($sql);
$this->db->last_query();die;
if(!$res){
$this->response('300000204', " ");
}
break;
case 2:
//
$goods_after = $this->CmsFilmGoods->getOne('film_id = '.$film_id.' and goods_sku > 0 and status=0 and sort > '.$goods_info['sort'], 'id, sort', " sort asc");
if(!isset($goods_after['id'])){
//
$this->response('300000203', " ");
}
$sql = 'UPDATE cms_film_goods SET sort = CASE id WHEN '.$goods_info['id'].' THEN '.$goods_after['sort'].' WHEN '.$goods_after['id'].' THEN '.$goods_info['sort'].' END WHERE id IN ('.$goods_info['id'].', '.$goods_after['id'].')';
$res = $this->CmsFilmGoods->query($sql);
if(!$res){
$this->response('300000204', " ");
}
break;
case 3:
//
if($goods_info['sort'] == 1){
$this->response('0', " ");
}
$goods_first = $this->CmsFilmGoods->getOne('film_id = '.$film_id.' and goods_sku > 0 and status=0', 'id, sort', " sort asc");
if($goods_first && $goods_first['sort'] > 1){
// 1
$ret = $this->CmsFilmGoods->update(['id'=>$goods_info['id']], ['sort'=>1]);
if(!$ret){
$this->response('300000204', " ");
}
}else{
// +1, 1
$this->CmsFilmGoods->startTrans();
$down = $this->CmsFilmGoods->format('sort < '.$goods_info['sort'], array('sort'=>'sort+1'));
if(!$down){
$this->response('300000204', " ");
}
$set = $this->CmsFilmGoods->update('id = '.$goods_info['id'], array('sort'=>'1'));
if(!$set){
$this->CmsFilmGoods->rollback();
$this->response('300000204', " ");
}
$this->CmsFilmGoods->commit();
}
break;
case 4:
//
$goods_last = $this->CmsFilmGoods->getOne('film_id = '.$film_id.' and goods_sku > 0 and status=0', 'id, sort', " sort desc");
if($goods_last && $goods_last['id'] == $goods_info['id']){
$this->response('0', " ");
}
$this->CmsFilmGoods->startTrans();
$up = $this->CmsFilmGoods->format('sort > '.$goods_info['sort'], array('sort'=>'sort-1'));
if(!$up){
$this->response('300000204', " ");
}
$set_down = $this->CmsFilmGoods->update('id = '.$goods_info['id'], array('sort'=>$goods_last['sort']));
if(!$set_down){
$this->CmsFilmGoods->rollback();
$this->response('300000204', " ");
}
$this->CmsFilmGoods->commit();
break;
default:
$this->response('300000201', " ");
}
$this->response('0', " ");
}