room_bargain.model.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2018/1/5
  6. * Time: 下午8:00
  7. */
  8. class room_bargainModel extends Model
  9. {
  10. public function __construct() {
  11. parent::__construct('room_bargain');
  12. }
  13. public function create($roomid,$userid,$goods_id,$goods_price,$lowest_price,$days,$type,$total_num)
  14. {
  15. $params = ['room_id' => $roomid,'user_id' => $userid,'goods_id' => $goods_id,'type' => $type,'total_num' => $total_num,
  16. 'goods_price' => $goods_price,'lowest_price' => $lowest_price,
  17. 'add_time' => time(),'over_time' => time() + 86400 * $days,'closed' => 0];
  18. return $this->insert($params);
  19. }
  20. public function getBargainById($bargain_id,$lock=false) {
  21. return $this->where(['bargain_id' => $bargain_id])->lock($lock)->find();
  22. }
  23. public function getBargainByRoom($room_id,$lock=false) {
  24. return $this->where(['room_id' => $room_id])->lock($lock)->find();
  25. }
  26. public function getBargainByUserGoods($user_id,$goods_id,$lock=false) {
  27. return $this->where(['user_id' => $user_id,'goods_id' => $goods_id])->lock($lock)->find();
  28. }
  29. public function getBargainByUserGoodIDs($user_id,$goods_ids,$lock=false) {
  30. return $this->where(['user_id' => $user_id,'goods_id' => ['in',$goods_ids]])->lock($lock)->select();
  31. }
  32. public function getBargainList($condition, $field = '*', $page = 0 , $order = 'bargain_id desc', $limit = 0) {
  33. return $this->where($condition)->field($field)->order($order)->page($page)->limit($limit)->select();
  34. }
  35. public function editBargain($bargain_id,$datas)
  36. {
  37. return $this->where(['bargain_id' => $bargain_id])->update($datas);
  38. }
  39. public function getBargainNumByUser($user_id)
  40. {
  41. return $this->where(['user_id' => $user_id,'closed' => 0])->count();
  42. }
  43. }