12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2018/1/5
- * Time: 下午8:00
- */
- class room_bargainModel extends Model
- {
- public function __construct() {
- parent::__construct('room_bargain');
- }
- public function create($roomid,$userid,$goods_id,$goods_price,$lowest_price,$days,$type,$total_num)
- {
- $params = ['room_id' => $roomid,'user_id' => $userid,'goods_id' => $goods_id,'type' => $type,'total_num' => $total_num,
- 'goods_price' => $goods_price,'lowest_price' => $lowest_price,
- 'add_time' => time(),'over_time' => time() + 86400 * $days,'closed' => 0];
- return $this->insert($params);
- }
- public function getBargainById($bargain_id,$lock=false) {
- return $this->where(['bargain_id' => $bargain_id])->lock($lock)->find();
- }
- public function getBargainByRoom($room_id,$lock=false) {
- return $this->where(['room_id' => $room_id])->lock($lock)->find();
- }
- public function getBargainByUserGoods($user_id,$goods_id,$lock=false) {
- return $this->where(['user_id' => $user_id,'goods_id' => $goods_id])->lock($lock)->find();
- }
- public function getBargainByUserGoodIDs($user_id,$goods_ids,$lock=false) {
- return $this->where(['user_id' => $user_id,'goods_id' => ['in',$goods_ids]])->lock($lock)->select();
- }
- public function getBargainList($condition, $field = '*', $page = 0 , $order = 'bargain_id desc', $limit = 0) {
- return $this->where($condition)->field($field)->order($order)->page($page)->limit($limit)->select();
- }
- public function editBargain($bargain_id,$datas)
- {
- return $this->where(['bargain_id' => $bargain_id])->update($datas);
- }
- public function getBargainNumByUser($user_id)
- {
- return $this->where(['user_id' => $user_id,'closed' => 0])->count();
- }
- }
|