SystemStoreStockBill.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\models\system;
  3. use crmeb\basic\BaseModel;
  4. use crmeb\traits\ModelTrait;
  5. class SystemStoreStockBill extends BaseModel
  6. {
  7. use ModelTrait;
  8. public static function getAddTimeAttr($value)
  9. {
  10. return date("Y-m-d H:i:s",$value);
  11. }
  12. public static function getAuditTimeAttr($value)
  13. {
  14. return $value?date("Y-m-d H:i:s",$value):'-';
  15. }
  16. public static function getStatusAttr($value)
  17. {
  18. switch ($value)
  19. {
  20. case 0:
  21. return '待审核';
  22. break;
  23. case 1:
  24. return '已通过';
  25. break;
  26. case -1:
  27. return '已拒绝';
  28. break;
  29. }
  30. }
  31. /**
  32. *创建记录
  33. */
  34. public static function order_create($store_id,$data)
  35. {
  36. if ($data['product_id'] > 0 && $data['in_stock'] > 0) {
  37. $data['add_time'] = time();
  38. $data['store_id'] = $store_id;
  39. self::create($data);
  40. return true;
  41. }
  42. return false;
  43. }
  44. /**
  45. *获取列表
  46. */
  47. public static function lst($where)
  48. {
  49. $model = new self;
  50. $model = $model->alias("a")->join("store_product b","a.product_id=b.id","right");
  51. if(isset($where['store_id']) && $where['store_id']>0) $model = $model->where('a.store_id',$where['store_id']);
  52. if(isset($where['status']) && $where['status']>-2) $model = $model->where('a.status',$where['status']);
  53. if(isset($where['key']) && $where['key']) $model = $model->wherelike('b.store_name',"%".$where['key']."%");
  54. if(isset($where['product_id']) && $where['product_id']) $model = $model->wherelike('a.product_id',$where['product_id']);
  55. $model = $model->where('a.id','>',0);
  56. $model = $model->field('a.*,b.image,b.is_show,b.is_del,b.store_name');
  57. $count = $model->count();
  58. $data = $model->page($where['page'],$where['limit'])->order("product_id desc")->select()->toarray();
  59. foreach ($data as &$v)
  60. {
  61. $v['store'] = SystemStore::where('id',$v['store_id'])->value('name');
  62. }
  63. return compact('count','data');
  64. }
  65. }