317 lines
11 KiB
PHP
317 lines
11 KiB
PHP
<?php
|
|
|
|
namespace addon\futures\api\controller;
|
|
use app\api\controller\BaseApi;
|
|
use addon\futures\model\Futures as FuturesModel;
|
|
use app\model\system\Document;
|
|
|
|
class Futures extends BaseApi{
|
|
/**
|
|
* 售卖列表
|
|
* @return false|string
|
|
*/
|
|
public function list()
|
|
{
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
|
|
$status = input('status', 'miaosha');
|
|
|
|
$condition = [
|
|
['a.site_id','=',$this->site_id],
|
|
['release_time', '<', time() ],
|
|
];
|
|
|
|
$futuresModel = new FuturesModel;
|
|
switch($status){
|
|
case 'miaosha':
|
|
$condition[] = ['a.status', '=', '2'];
|
|
$times = $futuresModel->checkTimes($this->site_id, $this->member_id, 2);
|
|
if($times['code'] != 0){
|
|
return $this->response($times);
|
|
}
|
|
break;
|
|
case 'jianlou':
|
|
$condition[] = ['a.status', '=', '7'];
|
|
$times = $futuresModel->checkTimes($this->site_id, $this->member_id, 7);
|
|
if($times['code'] != 0){
|
|
$times['message'] = '未到捡漏时间';
|
|
return $this->response($times);
|
|
}
|
|
break;
|
|
default:
|
|
return $this->response($this->error('','参数不合法'));
|
|
break;
|
|
}
|
|
|
|
|
|
|
|
// 获取内容
|
|
$field = [
|
|
'seller.username as seller_username',
|
|
'seller.nickname as seller_nickname',
|
|
'seller.headimg as seller_headimg',
|
|
'g.goods_name',
|
|
'g.goods_image',
|
|
'g.market_price',
|
|
'g.unit',
|
|
'a.id',
|
|
'a.total',
|
|
'a.unit_price',
|
|
'a.price',
|
|
'a.status',
|
|
'a.release_time',
|
|
'a.sell_time',
|
|
'a.created_time',
|
|
'a.take_time',
|
|
];
|
|
// 表关联
|
|
$join = [
|
|
['member seller', 'seller.member_id = a.seller_uid', 'left'],// 获取卖家信息
|
|
['goods g', 'g.goods_id = a.goods_id', 'left'],// 获取商品信息
|
|
];
|
|
|
|
|
|
$page = input('page', 1);
|
|
$page_size = input('page_size', PAGE_LIST_ROWS);
|
|
$list = $futuresModel->getPageList($condition, $page, $page_size, 'a.created_time desc,a.id desc', $field, 'a', $join);
|
|
$list['data']['times'] = $times['data'];
|
|
$list['data']['start_time'] = strtotime(date("Y-m-d", time())) + $times['data']['start_time'];
|
|
$list['data']['end_time'] = strtotime(date("Y-m-d", time())) + $times['data']['end_time'];
|
|
return $this->response($list);
|
|
}
|
|
|
|
/**
|
|
* 个人中心列表
|
|
* @return false|string
|
|
*/
|
|
public function myList()
|
|
{
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
|
|
$status = input('status', 'all');
|
|
$search_text = input('search_text', '');
|
|
|
|
$condition = [
|
|
['a.site_id','=',$this->site_id]
|
|
];
|
|
if($search_text != ''){
|
|
$condition[] = ['o.order_no','like','%'.$search_text.'%'];
|
|
}
|
|
|
|
switch($status){
|
|
case '待付款订单':
|
|
$condition[] = ['a.seller_uid', '=', $this->member_id];
|
|
$condition[] = ['a.status', 'in', [2, 6, 7]];
|
|
$condition[] = ['a.release_time', '<=', time()];
|
|
break;
|
|
case '商城已完成':
|
|
$condition[] = ['a.seller_uid', '=', $this->member_id];
|
|
$condition[] = ['a.status', '=', '3'];
|
|
break;
|
|
case '采购未付款':
|
|
$condition[] = ['a.member_id', '=', $this->member_id];
|
|
$condition[] = ['a.status', '=', '6'];
|
|
break;
|
|
case '成功完成订单':
|
|
$condition[] = ['a.member_id', '=', $this->member_id];
|
|
$condition[] = ['a.status', '=', '3'];
|
|
break;
|
|
case '库存订单':
|
|
$condition[] = ['a.seller_uid', '=', $this->member_id];
|
|
$condition[] = ['a.status', '=', '1'];
|
|
break;
|
|
case '提货订单':
|
|
$condition[] = ['a.seller_uid', '=', $this->member_id];
|
|
$condition[] = ['a.status', 'in', ['4','5']];
|
|
break;
|
|
case '审核出售':
|
|
$condition[] = ['a.seller_uid', '=', $this->member_id];
|
|
$condition[] = ['a.status', 'in', [2, 6]];
|
|
$condition[] = ['a.release_time', '>', time()];
|
|
break;
|
|
case 'stock':
|
|
$condition[] = ['a.seller_uid', '=', $this->member_id];
|
|
$condition[] = ['a.status', '=', '1'];
|
|
break;
|
|
case 'release':
|
|
$condition[] = ['a.seller_uid', '=', $this->member_id];
|
|
$condition[] = ['a.status', 'in', [2, 6, 7]];
|
|
break;
|
|
case 'sold':
|
|
$condition[] = ['a.seller_uid', '=', $this->member_id];
|
|
$condition[] = ['a.status', '=', '3'];
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
// 获取内容
|
|
$field = [
|
|
'seller.username as seller_username',
|
|
'seller.nickname as seller_nickname',
|
|
'seller.headimg as seller_headimg',
|
|
'g.goods_name',
|
|
'g.goods_image',
|
|
'g.market_price',
|
|
'g.unit',
|
|
'a.id',
|
|
'a.total',
|
|
'a.unit_price',
|
|
'a.price',
|
|
'a.status',
|
|
'a.release_time',
|
|
'a.sell_time',
|
|
'a.created_time',
|
|
'a.take_time',
|
|
'o.order_no'
|
|
];
|
|
// 表关联
|
|
$join = [
|
|
['member seller', 'seller.member_id = a.seller_uid', 'left'],// 获取卖家信息
|
|
['goods g', 'g.goods_id = a.goods_id', 'left'],// 获取商品信息
|
|
['order o', 'o.order_id = a.order_id', 'left'],// 获取商品信息
|
|
];
|
|
|
|
$futuresModel = new FuturesModel;
|
|
$page = input('page', 1);
|
|
$page_size = input('page_size', PAGE_LIST_ROWS);
|
|
$list = $futuresModel->getPageList($condition, $page, $page_size, 'a.created_time desc,a.id desc', $field, 'a', $join);
|
|
return $this->response($list);
|
|
}
|
|
|
|
/**
|
|
* 发布
|
|
* @return false|string
|
|
*/
|
|
public function release()
|
|
{
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
|
|
$id = input('id', 0);
|
|
$price = input('price', 0);
|
|
$agree_split_order = input('agree_split_order', 0);
|
|
|
|
$date = model('futures')->getInfo([['id', '=', $id],['seller_uid', '=', $this->member_id]]);
|
|
if(empty($date)){
|
|
return $this->response($this->error('','发布失败'));
|
|
}
|
|
|
|
$futuresModel = new FuturesModel;
|
|
$basicsConfig = $futuresModel->getBasicsConfig($this->site_id)['data']['value'];
|
|
if(!($price > sprintf('%.2f',$date['unit_price'] * (1 + $basicsConfig['price_range']['min'] / 100)) && $price <= sprintf('%.2f',$date['unit_price'] * (1 + $basicsConfig['price_range']['max'] / 100)))){// 后台配置范围
|
|
return $this->response($this->error('','发布失败,价格不在允许范围内'.sprintf('%.2f',$date['unit_price'] * (1 + $basicsConfig['price_range']['min'] / 100)).'-'.sprintf('%.2f',$date['unit_price'] * (1 + $basicsConfig['price_range']['max'] / 100))));
|
|
}
|
|
|
|
// 限制发布时间
|
|
|
|
return $this->response($futuresModel->release($id, $price, $agree_split_order));
|
|
}
|
|
|
|
/**
|
|
* 下架到库存
|
|
* @return false|string
|
|
*/
|
|
public function stock(){
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
|
|
$id = input('id', 0);
|
|
|
|
$date = model('futures')->getInfo([['id', '=', $id],['seller_uid', '=', $this->member_id]]);
|
|
if(empty($date)){
|
|
return $this->response($this->error('','下架失败'));
|
|
}
|
|
|
|
$futuresModel = new FuturesModel;
|
|
return $this->response($futuresModel->stock($id));
|
|
}
|
|
/**
|
|
* 提货
|
|
* @return false|string
|
|
* @throws \Psr\SimpleCache\InvalidArgumentException
|
|
*/
|
|
public function pickUp(){
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
|
|
$id = input('id', 0);
|
|
|
|
$date = model('futures')->getInfo([['id', '=', $id],['seller_uid', '=', $this->member_id]]);
|
|
if(empty($date)){
|
|
return $this->response($this->error('','提货失败'));
|
|
}
|
|
|
|
$futuresModel = new FuturesModel;
|
|
return $this->response($futuresModel->pickUp($id));
|
|
}
|
|
/**
|
|
* 详情
|
|
* @return false|string
|
|
*/
|
|
public function detail(){
|
|
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
|
|
$id = input('id', 0);
|
|
|
|
$futuresModel = new FuturesModel;
|
|
$detail = $futuresModel->detail($id, $this->site_id);
|
|
$times = $futuresModel->checkTimes($this->site_id, $this->member_id, $detail['data']['status']);
|
|
if($times['code'] != 0){
|
|
return $this->response($times);
|
|
}
|
|
$detail['data']['times'] = $times['data'];
|
|
$detail['data']['start_time'] = strtotime(date("Y-m-d", time())) + $times['data']['start_time'];
|
|
$detail['data']['end_time'] = strtotime(date("Y-m-d", time())) + $times['data']['end_time'];
|
|
return $this->response($detail);
|
|
}
|
|
/**
|
|
* 获取设置
|
|
* @return false|string
|
|
*/
|
|
public function getBasicsConfig(){
|
|
$futuresModel = new FuturesModel;
|
|
$basicsConfig = $futuresModel->getBasicsConfig($this->site_id)['data']['value'];
|
|
$res = [
|
|
'price_range' => $basicsConfig['price_range'],
|
|
'service_price' => $basicsConfig['service_price'],
|
|
];
|
|
return $this->response($this->success($res));
|
|
}
|
|
/**
|
|
* 详情
|
|
* @return false|string
|
|
*/
|
|
public function myDetail(){
|
|
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
|
|
$id = input('id', 0);
|
|
|
|
$futuresModel = new FuturesModel;
|
|
$detail = $futuresModel->detail($id, $this->site_id);
|
|
if($detail['code'] < 0 || empty($detail['data']) || !($detail['data']['seller_uid'] == $this->member_id || $detail['data']['member_id'] == $this->member_id)){
|
|
return $this->response($this->error('','订单不存在'));
|
|
}
|
|
return $this->response($detail);
|
|
}
|
|
|
|
/**
|
|
* 协议
|
|
*/
|
|
public function aggrement()
|
|
{
|
|
$document = new Document();
|
|
$info = $document->getDocument([['site_id', '=', $this->site_id], ['app_module', '=', 'shop'], ['document_key', '=', 'FUTURES_AGREEMENT']]);
|
|
return $this->response($info);
|
|
}
|
|
|
|
// public function testBuyBack(){
|
|
// return $this->response(event('BuyBack'));
|
|
// }
|
|
} |