BalanceLog.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: PHP
  5. * Date: 2016/9/26
  6. * Time: 11:57
  7. * 用户余额
  8. */
  9. class BalanceLog extends MongoAr
  10. {
  11. public $_id;
  12. public $user;//用户 mongoid
  13. public $time;//时间
  14. public $memo;//说明
  15. public $type;//操作类型 'recharge 充值;admin_recharge 后台充值;order 下订单;send 赠送;other 其他'
  16. public $amount;//金额 可以为负数
  17. public static $type_option = array(
  18. 'recharge' => '充值',
  19. 'admin_recharge' => '后台充值',
  20. 'order' => '下订单',
  21. 'send' => '赠送',
  22. 'other' => '其他',
  23. );
  24. public function __construct($scenario='insert'){
  25. $this->setMongoDBComponent(Yii::app()->getComponent('mongodb_o2o'));
  26. parent::__construct($scenario);
  27. }
  28. public static function model($className=__CLASS__)
  29. {
  30. return parent::model($className);
  31. }
  32. public function getCollectionName()
  33. {
  34. return 'balance_log';
  35. }
  36. public static function get($_id) {
  37. if(CommonFn::isMongoId($_id)){
  38. $criteria = new EMongoCriteria();
  39. $criteria->_id('==', $_id);
  40. $model = self::model()->find($criteria);
  41. return $model;
  42. }else{
  43. return false;
  44. }
  45. }
  46. public function parseRow($row,$output=array()){
  47. $newRow = array();
  48. $newRow['id'] = (string)$row['_id'];
  49. $newRow['memo'] = CommonFn::get_val_if_isset($row,'memo','');
  50. $newRow['type'] = CommonFn::get_val_if_isset($row,'type','other');
  51. $newRow['type_str'] = self::$type_option[$newRow['type']];
  52. $newRow['time'] = CommonFn::get_val_if_isset($row,'time',time());
  53. $newRow['time_str'] = CommonFn::sgmdate("Y年n月d日", $newRow['time'],1);
  54. $newRow['amount'] = CommonFn::get_val_if_isset($row,'amount',0);
  55. $user = array();
  56. $t_user = new ZUser();
  57. if(isset($row['user'])){
  58. $_user = $t_user->get($row['user']);
  59. $user = RUser::model()->parseRow($_user->attributes,array('id','user_name'));
  60. }
  61. $newRow['user'] = $user;
  62. $newRow['action_user'] = CommonFn::get_val_if_isset($row,'action_user',"");
  63. $newRow['action_time'] = CommonFn::get_val_if_isset($row,'action_time',"");
  64. $newRow['action_log'] = CommonFn::get_val_if_isset($row,'action_log',"");
  65. return $this->output($newRow,$output);
  66. }
  67. }