107 lines
3.0 KiB
PHP
107 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace addon\futures\model;
|
|
use app\model\BaseModel;
|
|
use think\facade\Cache;
|
|
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* 发布
|
|
* @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('','下单失败');
|
|
}
|
|
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]]);
|
|
return $this->success();
|
|
}
|
|
|
|
/**
|
|
* 订单完成
|
|
* @return array
|
|
*/
|
|
public function orderComplete($id){
|
|
model('futures')->update([
|
|
'status' => 3,
|
|
], [['id', '=', $id]]);
|
|
return $this->success();
|
|
}
|
|
|
|
/**
|
|
* 订单取消
|
|
* @return array
|
|
*/
|
|
public function orderClose($id){
|
|
model('futures')->update([
|
|
'status' => 7,
|
|
'member_id' => 0,
|
|
'order_id' => 0
|
|
], [['id', '=', $id]]);
|
|
Cache::store('redis_concurrent')->set('addon_futures_'.$id,'1');
|
|
return $this->success();
|
|
}
|
|
} |