Material.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * 物资
  4. * @author zhouxuchen 2015-09-16
  5. */
  6. class Material extends MongoAr {
  7. public $_id;
  8. public $name; // 物资的名称
  9. public $unit_str; // 物资的单位(文字)
  10. public $unit; // 物资的单位
  11. public $price; // 物资的单价
  12. public $stock; // 物资的库存
  13. public $stockWarnLine; // 库存警戒线
  14. public $addTime; // 物资加入的时间
  15. public $status; // 物资的库存状态
  16. public $status_str; // 物资的库存状态(文字)
  17. public $enable; // 是否启用此物资
  18. public $enable_str; // 是否启用此物资
  19. public $remarks; // 该物资的备注
  20. public static $status_option = array(
  21. 0 => array('name' => '无库存'),
  22. 1 => array('name' => '紧张'),
  23. 2 => array('name' => '充足'),
  24. 3 => array('name' => '未知')
  25. );
  26. public static $enable_option = array(
  27. 0 => array('name' => '停用'),
  28. 1 => array('name' => '启用')
  29. );
  30. public static $unit_option = array(
  31. 1 => array('name' => '瓶'),
  32. 2 => array('name' => '袋'),
  33. 3 => array('name' => '盒'),
  34. 4 => array('name' => '台'),
  35. 5 => array('name' => '件'),
  36. 6 => array('name' => '双'),
  37. 7 => array('name' => '只'),
  38. 8 => array('name' => '个'),
  39. 9 => array('name' => '套'),
  40. 10 => array('name' => '副'),
  41. 11 => array('name' => '毫升')
  42. );
  43. public function __construct($scenario='insert') {
  44. $this->setMongoDBComponent(Yii::app()->getComponent('mongodb_o2o'));
  45. parent::__construct($scenario);
  46. }
  47. public static function model($className = __CLASS__) {
  48. return parent::model($className);
  49. }
  50. public static function get($_id) {
  51. if(CommonFn::isMongoId($_id)){
  52. $criteria = new EMongoCriteria();
  53. $criteria->_id('==', $_id);
  54. $model = self::model()->find($criteria);
  55. return $model;
  56. }else{
  57. return false;
  58. }
  59. }
  60. public function getCollectionName () {
  61. return 'material';
  62. }
  63. public function parseRow($row, $output = array()) {
  64. $newRow = array();
  65. $newRow['id'] = (string)$row['_id'];
  66. $newRow['name'] = CommonFn::get_val_if_isset($row, 'name', '');
  67. $newRow['unit_str'] = CommonFn::get_val_if_isset($row, 'unit_str', '');
  68. $newRow['unit'] = CommonFn::get_val_if_isset($row, 'unit', 0);
  69. $newRow['price'] = CommonFn::get_val_if_isset($row, 'price', 0.00);
  70. $newRow['stock'] = CommonFn::get_val_if_isset($row, 'stock', 0);
  71. $newRow['stockWarnLine'] = CommonFn::get_val_if_isset($row, 'stockWarnLine', 0);
  72. $newRow['addTime'] = date('Y-m-d H:i', CommonFn::get_val_if_isset($row, 'addTime', 0));
  73. $newRow['status_str'] = CommonFn::get_val_if_isset($row, 'status_str', '');
  74. $newRow['status'] = CommonFn::get_val_if_isset($row, 'status', 0);
  75. $newRow['enable'] = CommonFn::get_val_if_isset($row, 'enable', 0);
  76. $newRow['enable_str'] = CommonFn::get_val_if_isset($row, 'enable_str', 0);
  77. $newRow['action_user'] = CommonFn::get_val_if_isset($row, 'action_user', '');
  78. $newRow['action_time'] = CommonFn::get_val_if_isset($row, 'action_time', '');
  79. $newRow['action_log'] = CommonFn::get_val_if_isset($row, 'action_log', '');
  80. $newRow['material_remarks'] = CommonFn::get_val_if_isset($row, 'remarks', '');
  81. return $this->output($newRow, $output);
  82. }
  83. }
  84. ?>