JRecordController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * Created by north.Deng's MAC
  4. * User: north.Deng
  5. * Date: 2018/2/28
  6. * Time: 下午12:30
  7. * description :
  8. */
  9. class JRecordController extends AdminController
  10. {
  11. public function actionIndex()
  12. {
  13. $status = CommonFn::getComboboxData(JRecord::$status_options, 100, true, 100);
  14. $this->render('index',array(
  15. 'status' => $status
  16. ));
  17. }
  18. public function actionList()
  19. {
  20. $pageParams = CommonFn::getPageParams();
  21. $search = Yii::app()->request->getParam('search', '');
  22. $status = intval(Yii::app()->request->getParam('status', 100));
  23. $criteria = new EMongoCriteria($pageParams);
  24. if ($status != 100 ) {
  25. $criteria->status('==',$status);
  26. }
  27. if ($search) {
  28. $criteria->addCond('title','or',new MongoRegex('/' . $search . '/'));
  29. }
  30. $cursor = JRecord::model()->findAll($criteria);
  31. $rows = CommonFn::getRowsFromCursor($cursor);
  32. $parsedRows = JRecord::model()->parse($rows);
  33. $total = $cursor->count();
  34. echo CommonFn::composeDatagridData($parsedRows, $total);
  35. }
  36. public function actionEdit()
  37. {
  38. $id = Yii::app()->request->getParam('id','');
  39. $name = Yii::app()->request->getParam('name','');
  40. $mobile = Yii::app()->request->getParam('mobile','');
  41. $address = Yii::app()->request->getParam('address','');
  42. $flow = Yii::app()->request->getParam('flow','');
  43. $flow_number = Yii::app()->request->getParam('flow_number','');
  44. $status = (int)Yii::app()->request->getParam('status',0);
  45. if (!$name ||!$mobile || !$address || !$flow||!$flow_number ) {
  46. CommonFn::requestAjax(false,'请填写完整信息');exit;
  47. }
  48. if (!CommonFn::isMongoId($id)) {
  49. CommonFn::requestAjax(false, '修改失败', array());
  50. }
  51. $record = JRecord::get(new MongoId($id));
  52. $record->user_info = array(
  53. 'name' => $name,
  54. 'mobile' => $mobile,
  55. );
  56. $record->address = $address;
  57. $record->status = $status;
  58. $record->flow = $flow;
  59. $record->flow_number = $flow_number;
  60. $record->save();
  61. CommonFn::requestAjax(true,'修改成功');exit;
  62. }
  63. public function actionAdd()
  64. {
  65. $name = Yii::app()->request->getParam('name','');
  66. $mobile = Yii::app()->request->getParam('mobile','');
  67. $address = Yii::app()->request->getParam('address','');
  68. $flow = Yii::app()->request->getParam('flow','');
  69. $flow_number = Yii::app()->request->getParam('flow_number','');
  70. // $status = (int)Yii::app()->request->getParam('status',0);
  71. $pwd = Yii::app()->request->getParam('pwd','');
  72. if (!$name ||!$mobile || !$address || !$flow||!$flow_number || !$pwd) {
  73. CommonFn::requestAjax(false,'请填写完整信息');exit;
  74. }
  75. $coupon = JCoupon::getByPwdOne($pwd);
  76. if (empty($coupon) || $coupon->status >= 2) {
  77. CommonFn::requestAjax(false,'兑换券不存在或已失效');exit;
  78. }
  79. $record = new JRecord();
  80. $record->user_info = array(
  81. 'name' => $name,
  82. 'mobile' => $mobile,
  83. );
  84. $record->address = $address;
  85. $record->coupon_id = (string)$coupon->_id;
  86. $record->status = 0;
  87. $record->flow = $flow;
  88. $record->flow_number = $flow_number;
  89. $record->time = time();
  90. $record->save();
  91. $coupon->status = 2;
  92. $coupon->save();
  93. CommonFn::requestAjax(true,'生成成功');exit;
  94. }
  95. public function actionOutputExcel()
  96. {
  97. $start_time = Yii::app()->request->getParam('start_time','');
  98. $end_time = Yii::app()->request->getParam('end_time','');
  99. $criteria = new EMongoCriteria();
  100. $criteria->time('>=',strtotime($start_time));
  101. $criteria->time('<=',strtotime($end_time));
  102. $cursor = JRecord::model()->findAll($criteria);
  103. $rows = CommonFn::getRowsFromCursor($cursor);
  104. $parsedRows = JRecord::model()->parse($rows);
  105. $res=Service::factory('JRecordService')->push($parsedRows);
  106. }
  107. }