Files
liche/market/controllers/api/sylive/Goods.php
T
2022-10-25 14:31:02 +08:00

131 lines
3.6 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . 'controllers/api/BaseController.php';
/**
* Notes:私域直播_商品管理
* Created on: 2022/10/21 17:15
* Created by: dengbw
*/
class Goods extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('market/Market_sylive_items_model', 'mdSyliveItems');
}
/**
* Notes:商品管理列表
* Created on: 2022/9/20 14:48
* Created by: dengbw
*/
public function page_get()
{
$activityId = intval($this->input_param('activityId'));
$page = $this->input_param('page');
$limit = $this->input_param('limit');
$title = $this->input_param('title');
$sort = $this->input_param('sort');
$order = $this->input_param('order');
!$page && $page = 1;
!$limit && $limit = 10;
$sort_order = 'id desc';
if ($sort && $order) {
$sort_order = $sort . ' ' . $order;
}
$where['status>'] = 0;
$activityId && $where['a_id'] = $activityId;
$title && $where['title'] = $title;
$count = $this->mdSyliveItems->count($where);
$list = [];
if ($count) {
$res = $this->mdSyliveItems->select($where, $sort_order, $page, $limit);
foreach ($res as $v) {
$list[] = $v;
}
}
$date = ['list' => $list, 'count' => $count];
$this->return_response_list($date);
}
/**
* Notes:添加商品
* Created on: 2022/10/21 16:46
* Created by: dengbw
*/
public function index_post()
{
$a_id = intval($this->input_param('a_id'));
$title = $this->input_param('title');
$imgs = $this->input_param('imgs');
$descrip = $this->input_param('descrip');
$price = $this->input_param('price');
$stock = $this->input_param('stock');
$sort = $this->input_param('sort');
if (!$a_id) {
$this->return_json('参数错误');
}
if (!$title) {
$this->return_json('请输入商品标题');
}
$addDate = ['a_id' => $a_id, 'title' => $title, 'price' => $price, 'stock' => $stock, 'sort' => $sort
, 'descrip' => $descrip, 'c_time' => time()];
if ($imgs) {
$setImgs = [];
foreach ($imgs as $v) {
$setImgs[] = $v['fileUrl'];
}
$addDate['imgs'] = $setImgs;
}
$id = $this->mdSyliveItems->add($addDate);
if (!$id) {
$this->return_json('添加商品失败');
}
$this->return_response();
}
/**
* Notes:修改商品
* Created on: 2022/10/21 14:48
* Created by: dengbw
*/
public function index_put()
{
}
/**
* Notes:删除商品
* Created on: 2022/10/21 16:10
* Created by: dengbw
* @param null $id
*/
public function index_delete($id = null)
{
if (!$id) {
$this->return_json('参数错误');
}
$this->mdSyliveItems->update(['status' => -1], ['id' => $id]);
$this->return_response();
}
/**
* Notes:批量删除商品
* Created on: 2022/10/21 17:11
* Created by: dengbw
*/
public function batch_delete()
{
$ids = $this->inputs;
if (!$ids) {
$this->return_json('参数错误');
}
$str_ids = implode(',', $ids);
if ($str_ids) {
$this->mdSyliveItems->update(['status' => -1], ["id in($str_ids)" => null]);
}
$this->return_response();
}
}