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