AuctionProduct.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/02
  6. */
  7. namespace app\models\auction;
  8. use crmeb\traits\ModelTrait;
  9. use crmeb\basic\BaseModel;
  10. /**
  11. * 竞拍上坪 Model
  12. * Class WechatNews
  13. * @package app\admin\model\wechat
  14. */
  15. class AuctionProduct extends BaseModel
  16. {
  17. use ModelTrait;
  18. protected $pk = 'id';
  19. protected $name = 'auction_product';
  20. protected $autoWriteTimestamp = true;
  21. /**
  22. * 竞拍商品列表
  23. * @param $data
  24. * @param $uid
  25. * @return array
  26. * @throws \think\db\exception\DataNotFoundException
  27. * @throws \think\db\exception\DbException
  28. * @throws \think\db\exception\ModelNotFoundException
  29. */
  30. public static function list($data, $uid){
  31. $model = self::where('is_show', 1)->where('auction_id', $data['id'])->order('sort DESC,id DESC');
  32. $model->page($data['page'], $data['limit']);
  33. if ($data['name']) $model->where('name', 'like', '%'.$data['name'].'%');
  34. $list = $model->select();
  35. $list = empty($list)? [] : $list->toArray();
  36. if ($list){
  37. foreach ($list as $k => $v) {
  38. $order = AuctionOrder::where('product_id', $v['id'])->where('status', '>', 0)->whereBetweenTime('create_time', date('Y-m-d H:i:s', strtotime(date('Y-m-d'))), date('Y-m-d H:i:s', strtotime('+1 day')))->find();
  39. if ($order){
  40. $list[$k]['status'] = 2;// 已被购买
  41. $list[$k]['str'] = '已卖完';
  42. }else{
  43. $list[$k]['status'] = 1;// 能购买
  44. $list[$k]['str'] = '购买';
  45. }
  46. }
  47. }
  48. return $list;
  49. }
  50. /**
  51. * 用户商品
  52. * @param $data
  53. * @param $uid
  54. * @return array
  55. * @throws \think\db\exception\DataNotFoundException
  56. * @throws \think\db\exception\DbException
  57. * @throws \think\db\exception\ModelNotFoundException
  58. */
  59. public static function user_product($data, $uid){
  60. $model = self::where('is_show', 1)->where('uid', $uid)->order('sort DESC,id DESC');
  61. $model->page($data['page'], $data['limit']);
  62. $list = $model->select()->toArray();
  63. return $list;
  64. }
  65. }