AuctionProduct.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. $auction = Auction::where('id', $v['auction_id'])->find();
  39. $order = AuctionOrder::where('product_id', $v['id'])->where('status', '>', 0)->where('frequency', $auction['frequency'])->find();
  40. if ($order){
  41. $list[$k]['status'] = 2;// 已被购买
  42. $list[$k]['str'] = '已卖完';
  43. }else{
  44. $list[$k]['status'] = 1;// 能购买
  45. $list[$k]['str'] = '购买';
  46. }
  47. }
  48. }
  49. return $list;
  50. }
  51. /**
  52. * 用户商品
  53. * @param $data
  54. * @param $uid
  55. * @return array
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\DbException
  58. * @throws \think\db\exception\ModelNotFoundException
  59. */
  60. public static function user_product($data, $uid){
  61. $model = self::where('is_show', 1)->where('uid', $uid)->order('sort DESC,id DESC');
  62. $model->page($data['page'], $data['limit']);
  63. $list = $model->select();
  64. $list = empty($list)? [] : $list->toArray();
  65. foreach ($list as $k => $v)
  66. {
  67. $auction = Auction::where('id', $v['auction_id'])->find();
  68. if (strtotime(date('Y-m-d',strtotime($v['update_time']))) < strtotime(date('Y-m-d'))){
  69. $list[$k]['g_time'] = date('Y-m-d H:i:s', strtotime($auction['radd_time']));
  70. }else{
  71. $list[$k]['g_time'] = date('Y-m-d', strtotime('+1 day')).' '.$auction['radd_time'];
  72. }
  73. }
  74. return $list;
  75. }
  76. }