SystemStoreStockBill.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. case 0:
  20. return '待审核';
  21. break;
  22. case 1:
  23. return '已通过';
  24. break;
  25. case -1:
  26. return '已拒绝';
  27. break;
  28. }
  29. }
  30. /**
  31. *创建记录
  32. */
  33. public static function order_create($store_id, $data)
  34. {
  35. if ($data['product_id'] > 0 && $data['in_stock'] > 0) {
  36. $data['add_time'] = time();
  37. $data['store_id'] = $store_id;
  38. self::create($data);
  39. return true;
  40. }
  41. return false;
  42. }
  43. /**
  44. *获取列表
  45. */
  46. public static function lst($where)
  47. {
  48. $model = new self;
  49. $model = $model->alias("a")->join("store_product b", "a.product_id=b.id", "right");
  50. if (isset($where['store_id']) && $where['store_id'] > 0) $model = $model->where('a.store_id', $where['store_id']);
  51. if (isset($where['status']) && $where['status'] > -2) $model = $model->where('a.status', $where['status']);
  52. if (isset($where['key']) && $where['key']) $model = $model->wherelike('b.store_name', "%" . $where['key'] . "%");
  53. if (isset($where['product_id']) && $where['product_id']) $model = $model->wherelike('a.product_id', $where['product_id']);
  54. $model = $model->where('a.id', '>', 0);
  55. $model = $model->field('a.*,b.image,b.is_show,b.is_del,b.store_name');
  56. $count = $model->count();
  57. $data = $model->page($where['page'], $where['limit'])->order("id desc")->select()->toarray();
  58. foreach ($data as &$v) {
  59. $v['store'] = SystemStore::where('id', $v['store_id'])->value('name');
  60. // $v['type'] = $v['type'] == 1 ? '<b style="color: #00aa00">+</b>' : '<b style="color: #aa0000">+</b>';
  61. }
  62. return compact('count', 'data');
  63. }
  64. }