Recharge.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: PHP
  5. * Date: 2016/9/26
  6. * Time: 11:57
  7. * 会员充值卡模型
  8. */
  9. class Recharge extends MongoAr
  10. {
  11. public $_id;
  12. public $denomination;//充值面额
  13. public $coupons = array();//赠送的优惠券
  14. public $cash_back;//返现的金额
  15. public $desc;//介绍
  16. public $status=1;//充值卡状态 1 正常使用 0 暂停使用 -1 已删除
  17. public $order;//排序权重
  18. public function __construct($scenario='insert'){
  19. $this->setMongoDBComponent(Yii::app()->getComponent('mongodb_o2o'));
  20. parent::__construct($scenario);
  21. }
  22. public static $status_option = array(
  23. 1 => array('name' => '正常'),
  24. 0 => array('name' => '暂停'),
  25. -1 => array('name' => '删除')
  26. );
  27. public static function model($className=__CLASS__)
  28. {
  29. return parent::model($className);
  30. }
  31. public function getCollectionName()
  32. {
  33. return 'recharge';
  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 parseRow($row,$output=array()){
  46. $newRow = array();
  47. $newRow['id'] = (string)$row['_id'];
  48. $newRow['denomination'] = CommonFn::get_val_if_isset($row,'denomination',0);
  49. $newRow['cash_back'] = CommonFn::get_val_if_isset($row,'cash_back',0);
  50. $newRow['desc'] = CommonFn::get_val_if_isset($row,'desc','');
  51. $newRow['order'] = CommonFn::get_val_if_isset($row,'order',1);
  52. $coupons = array();
  53. if(isset($row['coupons'])&&is_array($row['coupons'])&&!empty($row['coupons'])){
  54. $where = array('_id' => array('$in' => array_values($row['coupons'])));
  55. $cursor = Coupon::model()->getCollection()->find($where, array('_id','name'));
  56. foreach ($cursor as $v){
  57. $_id = (array)$v['_id'];
  58. unset($v['_id']);
  59. $v['id'] = $_id['$id'];
  60. $coupons[] = $v;
  61. }
  62. }
  63. $newRow['coupons'] = $coupons;
  64. $newRow['status'] = CommonFn::get_val_if_isset($row,'status',1);
  65. $newRow['action_user'] = CommonFn::get_val_if_isset($row,'action_user',"");
  66. $newRow['action_time'] = CommonFn::get_val_if_isset($row,'action_time',"");
  67. $newRow['action_log'] = CommonFn::get_val_if_isset($row,'action_log',"");
  68. if (APPLICATION=='api'||APPLICATION=='common'){
  69. unset($newRow['action_user']);
  70. unset($newRow['action_time']);
  71. unset($newRow['action_log']);
  72. }
  73. return $this->output($newRow,$output);
  74. }
  75. }