196 lines
6.0 KiB
PHP
196 lines
6.0 KiB
PHP
<?php
|
|
|
|
namespace addon\futures\model;
|
|
use app\model\system\Config as ConfigModel;
|
|
use app\model\BaseModel;
|
|
use think\facade\Cache;
|
|
use think\facade\Db;
|
|
|
|
class Futures extends BaseModel{
|
|
|
|
/**
|
|
* 获取列表
|
|
* @param array $condition
|
|
* @param int $page
|
|
* @param int $page_size
|
|
* @param string $order
|
|
* @param string $field
|
|
* @param string $alias
|
|
* @param array $join
|
|
* @return array
|
|
*/
|
|
public function getPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = 'a.*', $alias = 'a', $join = [])
|
|
{
|
|
$list = model('futures')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
|
return $this->success($list);
|
|
}
|
|
/**
|
|
* 详情
|
|
* @param $id
|
|
* @param $site_id
|
|
* @return array
|
|
*/
|
|
public function detail($id, $site_id){
|
|
$condition = [
|
|
['a.id', '=', $id],
|
|
['a.site_id','=',$site_id]
|
|
];
|
|
|
|
// 获取内容
|
|
$field = [
|
|
'seller.username as seller_username',
|
|
'seller.nickname as seller_nickname',
|
|
'seller.headimg as seller_headimg',
|
|
'g.goods_name',
|
|
'g.goods_image',
|
|
'g.goods_content',
|
|
'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'],// 获取商品信息
|
|
];
|
|
|
|
$detail = model('futures')->getInfo($condition, $field, 'a', $join);
|
|
return $this->success($detail);
|
|
}
|
|
|
|
/**
|
|
* 发布
|
|
* @return array
|
|
*/
|
|
public function release($id, $price){
|
|
$date = model('futures')->getInfo([['id', '=', $id]]);
|
|
if(empty($date) || $date['status'] !== 1){
|
|
return $this->error('','发布失败');
|
|
}
|
|
model('futures')->update([
|
|
'status' => 2,
|
|
'release_time' => time(),
|
|
'price' => $price
|
|
], [['id', '=', $id]]);
|
|
Cache::store('redis_concurrent')->set('addon_futures_'.$id,'1');
|
|
return $this->success();
|
|
}
|
|
|
|
/**
|
|
* 下架到库存
|
|
* @return array
|
|
*/
|
|
public function stock($id){
|
|
$date = model('futures')->getInfo([['id', '=', $id]]);
|
|
if(empty($date) || $date['status'] !== 2){
|
|
return $this->error('','下架失败');
|
|
}
|
|
if(!Cache::store('redis_concurrent')->delete('addon_futures_'.$id)){
|
|
return $this->error('','下架失败');
|
|
}
|
|
model('futures')->update([
|
|
'status' => 1,
|
|
], [['id', '=', $id]]);
|
|
return $this->success();
|
|
}
|
|
|
|
/**
|
|
* 订单创建
|
|
* @return array
|
|
*/
|
|
public function orderCreate($id, $order_id, $member_id){
|
|
$date = model('futures')->getInfo([['id', '=', $id]]);
|
|
if(empty($date) || ($date['status'] !== 2 && $date['status'] !== 7)){
|
|
return $this->error($date,'下单失败');
|
|
}
|
|
if(!Cache::store('redis_concurrent')->delete('addon_futures_'.$id)){
|
|
return $this->error('','下单失败');
|
|
}
|
|
model('futures')->update([
|
|
'status' => 6,
|
|
'created_time' => time(),
|
|
'order_id' => $order_id,
|
|
'member_id' => $member_id
|
|
], [['id', '=', $id]]);
|
|
Cache::store('redis_concurrent')->set('addon_futures_pay_'.$id,'1');
|
|
return $this->success();
|
|
}
|
|
|
|
/**
|
|
* 订单完成
|
|
* @return array
|
|
*/
|
|
public function orderComplete($id){
|
|
$date = model('futures')->getInfo([['id', '=', $id]]);
|
|
if(empty($date) || $date['status'] !== 6){
|
|
return $this->error($date,'完成失败');
|
|
}
|
|
if(!Cache::store('redis_concurrent')->delete('addon_futures_pay_'.$id)){
|
|
return $this->error('','完成失败');
|
|
}
|
|
$date = model('futures')->getInfo([['id', '=', $id]]);
|
|
model('futures')->update([
|
|
'status' => 3,
|
|
'sell_time' => time()
|
|
], [['id', '=', $id]]);
|
|
model('futures')->add([
|
|
'site_id' => $date['site_id'],
|
|
'seller_uid' => $date['member_id'],
|
|
'old_futures_id' => $id,
|
|
'goods_id' => (int)$date['goods_id'],
|
|
'total' => (int)$date['total'],
|
|
'unit_price' => $date['price'],
|
|
'status' => 1,
|
|
'created_time' => time()]);
|
|
return $this->success();
|
|
}
|
|
|
|
/**
|
|
* 订单取消
|
|
* @return array
|
|
*/
|
|
public function orderClose($id){
|
|
$date = model('futures')->getInfo([['id', '=', $id]]);
|
|
if(empty($date) || $date['status'] !== 6){
|
|
return $this->error($date,'取消失败');
|
|
}
|
|
if(!Cache::store('redis_concurrent')->delete('addon_futures_pay_'.$id)){
|
|
return $this->error('','取消失败');
|
|
}
|
|
model('futures')->update([
|
|
'status' => 7,
|
|
], [['id', '=', $id]]);
|
|
Cache::store('redis_concurrent')->set('addon_futures_'.$id,'1');
|
|
return $this->success();
|
|
}
|
|
|
|
/**
|
|
* 写入基本设置
|
|
* @param $data
|
|
* @param $is_use
|
|
* @param $site_id
|
|
* @return array
|
|
*/
|
|
public function setBasicsConfig($data, $is_use, $site_id)
|
|
{
|
|
$config = new ConfigModel();
|
|
return $config->setConfig($data, '秒杀基本配置', $is_use, [['site_id', '=', $site_id], ['app_module', '=', 'shop'], ['config_key', '=', 'MIAOSHA_BASICS_CONFIG']]);
|
|
}
|
|
|
|
/**
|
|
* 读取基本设置
|
|
* @param $site_id
|
|
* @return array
|
|
*/
|
|
public function getBasicsConfig($site_id)
|
|
{
|
|
$config = new ConfigModel();
|
|
return $config->getConfig([['site_id', '=', $site_id], ['app_module', '=', 'shop'], ['config_key', '=', 'MIAOSHA_BASICS_CONFIG']]);
|
|
}
|
|
} |