295 lines
11 KiB
PHP
295 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('','参数不合法'));
|
||
}
|
||
// 获取内容
|
||
$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.'%'];
|
||
}
|
||
// $this->member_id=108;
|
||
//(1=库存,2=已上架,3=已售出,4=提货中,5=提货完成,6=待支付,7=捡漏,8=拆单)
|
||
switch($status){
|
||
case 6: //买家未付款
|
||
$condition[] = ['a.seller_uid', '=', $this->member_id];
|
||
$condition[] = ['a.status', '=', 6];
|
||
break;
|
||
case 3: //买家已付款(订单完成)
|
||
$condition[] = ['a.seller_uid', '=', $this->member_id];
|
||
$condition[] = ['a.status', '=', 3];
|
||
break;
|
||
case 'myorderpay': //我购买未付款
|
||
$condition[] = ['a.member_id', '=', $this->member_id];
|
||
$condition[] = ['a.status', '=', 6];
|
||
break;
|
||
case 'myorderend'://我购买已付款
|
||
$condition[] = ['a.seller_uid', '=', $this->member_id];
|
||
$condition[] = ['a.status', '=', 1];
|
||
break;
|
||
case 'stock': //库存商品
|
||
$condition[] = ['a.seller_uid', '=', $this->member_id];
|
||
$condition[] = ['a.status', 'in', [1,2]];
|
||
$condition[] = ['a.release_time', '<=', time()];
|
||
break;
|
||
case 'time': //待上架未审核商品
|
||
$condition[] = ['a.seller_uid', '=', $this->member_id];
|
||
$condition[] = ['a.status', '=', 2];
|
||
$condition[] = ['a.release_time', '>', time()];
|
||
break;
|
||
case 'pickup':
|
||
$condition[] = ['a.seller_uid', '=', $this->member_id];
|
||
$condition[] = ['a.status', 'in', ['4','5']];
|
||
break;
|
||
default:
|
||
$condition[] = ['a.seller_uid', '=', $this->member_id];
|
||
$condition[] = ['a.status', '=', $status];
|
||
break;
|
||
}
|
||
// 获取内容
|
||
$field = [
|
||
'old_seller.username as seller_username',
|
||
'old_seller.nickname as seller_nickname',
|
||
'old_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',
|
||
'o.adjust_money',
|
||
'o.pay_money',
|
||
'o.order_id',
|
||
'seller.nickname as buyer_name',
|
||
'f.seller_uid as fseller_uid',
|
||
];
|
||
// 表关联
|
||
$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'],// 获取商品信息
|
||
['futures f', 'f.id = a.old_futures_id', 'left'],// 获取旧订单信息
|
||
['member old_seller', 'old_seller.member_id = f.seller_uid', '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))));
|
||
// }
|
||
|
||
if(!($price <= sprintf('%.2f',$date['unit_price'] * (1 + $basicsConfig['price_range']['max'] / 100)))){// 后台配置范围
|
||
return $this->response($this->error('','发布失败,价格不得高于市场价格'));
|
||
}
|
||
// 限制发布时间
|
||
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'],
|
||
'proposed_range' => $basicsConfig['proposed_range'],
|
||
'technical_range' => $basicsConfig['technical_range'],
|
||
];
|
||
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);
|
||
}
|
||
|
||
} |