Stock.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * 物资领取情况模型
  4. * @author 2015-09-18
  5. */
  6. class Stock extends MongoAr {
  7. public $_id;
  8. public $mid; // 对应物资的id
  9. public $mname; // 对应物资的name
  10. public $user; // 对应的User 的id
  11. public $username; // 对应的Username
  12. public $time; // 操作的时间
  13. public $operate; // 操作的类型 0=>减少 1=>增加
  14. public $operate_str; // 操作的类型
  15. public $num; // 数量
  16. public $tot_price; // 总价
  17. public $lastStock; // 操作前库存数
  18. public $newStock; // 操作后库存数
  19. public $remarks; // 本次操作的备注信息
  20. public $object; // 本次操作的对象ID
  21. public $objectName; // 本次操作对象的name
  22. public $station; // 领取人员所在区域
  23. public $stationName; // 领取人员所在区域的名称
  24. public static $operate_option = array(
  25. 1 => array('name' => '入库'),
  26. 0 => array('name' => '出库')
  27. );
  28. public function __construct($scenario='insert'){
  29. $this->setMongoDBComponent(Yii::app()->getComponent('mongodb_o2o'));
  30. parent::__construct($scenario);
  31. }
  32. public static function model($className=__CLASS__) {
  33. return parent::model($className);
  34. }
  35. public static function get($_id) {
  36. if(CommonFn::isMongoId($_id)){
  37. $criteria = new EMongoCriteria();
  38. $criteria->_id('==', $_id);
  39. $model = self::model()->find($criteria);
  40. return $model;
  41. }else{
  42. return false;
  43. }
  44. }
  45. public function getCollectionName () {
  46. return 'stock';
  47. }
  48. public function parseRow($row, $output = array()) {
  49. $newRow = array();
  50. $newRow['id'] = (string)$row['_id'];
  51. $newRow['mid'] = (string)$row['mid'];
  52. $newRow['mname'] = CommonFn::get_val_if_isset($row, 'mname', '');
  53. $newRow['user'] = CommonFn::get_val_if_isset($row, 'user', '');
  54. $newRow['username'] = CommonFn::get_val_if_isset($row, 'username', '');
  55. $newRow['time'] = date('Y-m-d H:i:s', intval(CommonFn::get_val_if_isset($row, 'time', 0)));
  56. $newRow['operate'] = intval(CommonFn::get_val_if_isset($row,'operate',1));
  57. $newRow['operate_str'] = CommonFn::get_val_if_isset($row,'operate_str', '');
  58. $newRow['num'] = intval(CommonFn::get_val_if_isset($row, 'num', 0));
  59. $newRow['tot_price'] = CommonFn::get_val_if_isset($row,'tot_price', 0);
  60. $newRow['lastStock'] = intval(CommonFn::get_val_if_isset($row, 'lastStock', 0));
  61. $newRow['newStock'] = intval(CommonFn::get_val_if_isset($row, 'newStock', 0));
  62. $newRow['remarks'] = CommonFn::get_val_if_isset($row,'remarks', '');
  63. $newRow['object'] = CommonFn::get_val_if_isset($row, 'object', '');
  64. $newRow['objectName'] = CommonFn::get_val_if_isset($row, 'objectName', '');
  65. $newRow['station'] = isset($row['station']) ? (string)$row['station'] : 'noStation';
  66. $newRow['stationName'] = CommonFn::get_val_if_isset($row, 'stationName', '');
  67. $newRow['action_user'] = CommonFn::get_val_if_isset($row, 'action_user', '');
  68. $newRow['action_time'] = CommonFn::get_val_if_isset($row, 'action_time', '');
  69. $newRow['action_log'] = CommonFn::get_val_if_isset($row, 'action_log', '');
  70. return $this->output($newRow, $output);
  71. }
  72. }
  73. ?>