AuctionProduct.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/02
  6. */
  7. namespace app\admin\model\auction;
  8. use app\models\auction\AuctionTime;
  9. use crmeb\traits\ModelTrait;
  10. use crmeb\basic\BaseModel;
  11. use think\model\concern\SoftDelete;
  12. /**
  13. * 竞拍上坪 Model
  14. * Class WechatNews
  15. * @package app\admin\model\wechat
  16. */
  17. class AuctionProduct extends BaseModel
  18. {
  19. use ModelTrait;
  20. use SoftDelete;
  21. protected $pk = 'id';
  22. protected $name = 'auction_product';
  23. protected $autoWriteTimestamp = true;
  24. protected $deleteTime = 'delete_time';
  25. public static function list($where, $id = 0)
  26. {
  27. $model = self::alias('a')
  28. ->field('a.*,u.nickname, au.nickname as au_name')
  29. ->order('a.id DESC')
  30. ->leftJoin('auction au', 'a.auction_id = au.id')
  31. ->leftJoin('user u', 'a.uid = u.uid');
  32. if (!empty($id)) {
  33. $model->where('a.auction_id', '=',$id);
  34. }
  35. if (trim($where['auction_id']) != '') {
  36. $model->where('a.auction_id', '=',$where['auction_id']);
  37. }
  38. if (trim(($where['store_name'])) != ''){
  39. $model->where('a.id|a.name|u.nickname', 'like','%'.$where['store_name'].'%');
  40. }
  41. if ( trim($where['is_show']) != ''){
  42. $where['is_show'] = $where['is_show'] == 2? 0: 1;
  43. $model->where('a.is_show', '=',$where['is_show']);
  44. }
  45. $data['count'] = $model->count();
  46. if ($where['page'] && $where['limit']){
  47. $model->page($where['page'], $where['limit']);
  48. }else{
  49. $model->page(20, 1);
  50. }
  51. $data['data'] = $model->select()->toArray();
  52. foreach ($data['data'] as $k => $v)
  53. {
  54. if ($v['is_admin'] == 2){
  55. $time = AuctionTime::where('product_id', $v['id'])->find();
  56. if ($time){
  57. $data['data'][$k]['time'] = date('Y-m-d', $time['add_time']);
  58. }else{
  59. $data['data'][$k]['time'] = '未上架';
  60. }
  61. }else{
  62. $data['data'][$k]['time'] = date('Y-m-d', time());
  63. }
  64. }
  65. return $data;
  66. }
  67. }