ProductCode.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @author: xaboy<365615158@qq.com>
  4. * @day: 2017/11/11
  5. */
  6. namespace app\admin\model\store;
  7. use app\admin\model\user\User;
  8. use crmeb\traits\ModelTrait;
  9. use crmeb\basic\BaseModel;
  10. /**
  11. * Class StoreCategory
  12. * @package app\admin\model\store
  13. */
  14. class ProductCode extends BaseModel
  15. {
  16. /**
  17. * 数据表主键
  18. * @var string
  19. */
  20. protected $pk = 'id';
  21. /**
  22. * 模型名称
  23. * @var string
  24. */
  25. protected $name = 'product_code';
  26. use ModelTrait;
  27. protected $autoWriteTimestamp = true;
  28. public static function list($where)
  29. {
  30. $model = self::alias('a')
  31. ->field('a.*,b.nickname')
  32. ->leftJoin('user b', 'a.uid = b.uid')
  33. ->where('a.product_id', $where['id'])
  34. ->order('id DESC');
  35. if ($where['bd'] == 1) $model->where('a.uid' , '=', 0);
  36. if ($where['bd'] == 2) $model->where('a.uid' , '>', 0);
  37. $data['count'] = $model->count();
  38. if ($where['page'] && $where['limit']){
  39. $model->page($where['page'], $where['limit']);
  40. }else{
  41. $model->page(20, 1);
  42. }
  43. $list = $model->select()->toArray();
  44. foreach ($list as &$item){
  45. if (empty($item['nickname'])){
  46. $item['nickname'] = '未绑定';
  47. }
  48. if (empty($item['end_time'])){
  49. $item['end_time'] = '未使用';
  50. }else{
  51. $item['end_time'] = date('Y-m-d H:i:s', $item['end_time']);
  52. }
  53. }
  54. $data['data'] = $list;
  55. return $data;
  56. }
  57. }