JRecordController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. $models = JRecord::model()->findAll();
  14. foreach ($models as $model) {
  15. $model->delete();
  16. }
  17. $models = JCoupon::model()->findAll();
  18. foreach ($models as $model) {
  19. $model->delete();
  20. }
  21. $models = Gift::model()->findAll();
  22. foreach ($models as $model) {
  23. $model->delete();
  24. }
  25. $models = Business::model()->findAll();
  26. foreach ($models as $model) {
  27. $model->delete();
  28. }
  29. $status = CommonFn::getComboboxData(JRecord::$status_options, 100, true, 100);
  30. $this->render('index',array(
  31. 'status' => $status
  32. ));
  33. }
  34. public function actionList()
  35. {
  36. $pageParams = CommonFn::getPageParams();
  37. $search = Yii::app()->request->getParam('search', '');
  38. $status = intval(Yii::app()->request->getParam('status', 100));
  39. $criteria = new EMongoCriteria($pageParams);
  40. if ($status != 100 ) {
  41. $criteria->status('==',$status);
  42. }
  43. if ($search) {
  44. $criteria->addCond('title','or',new MongoRegex('/' . $search . '/'));
  45. }
  46. $cursor = JRecord::model()->findAll($criteria);
  47. $rows = CommonFn::getRowsFromCursor($cursor);
  48. $parsedRows = JRecord::model()->parse($rows);
  49. $total = $cursor->count();
  50. echo CommonFn::composeDatagridData($parsedRows, $total);
  51. }
  52. public function actionEdit()
  53. {
  54. $id = Yii::app()->request->getParam('id','');
  55. $name = Yii::app()->request->getParam('name','');
  56. $mobile = Yii::app()->request->getParam('mobile','');
  57. $address = Yii::app()->request->getParam('address','');
  58. $flow = Yii::app()->request->getParam('flow','');
  59. $flow_number = Yii::app()->request->getParam('flow_number','');
  60. $status = (int)Yii::app()->request->getParam('status',0);
  61. if (!$name ||!$mobile || !$address || !$flow||!$flow_number ) {
  62. CommonFn::requestAjax(false,'请填写完整信息');exit;
  63. }
  64. if (!CommonFn::isMongoId($id)) {
  65. CommonFn::requestAjax(false, '修改失败', array());
  66. }
  67. $record = JRecord::get(new MongoId($id));
  68. $record->user_info = array(
  69. 'name' => $name,
  70. 'mobile' => $mobile,
  71. );
  72. $record->address = $address;
  73. $record->status = $status;
  74. $record->flow = $flow;
  75. $record->flow_number = $flow_number;
  76. $record->save();
  77. CommonFn::requestAjax(true,'修改成功');exit;
  78. }
  79. public function actionAdd()
  80. {
  81. $name = Yii::app()->request->getParam('name','');
  82. $mobile = Yii::app()->request->getParam('mobile','');
  83. $address = Yii::app()->request->getParam('address','');
  84. $flow = Yii::app()->request->getParam('flow','');
  85. $flow_number = Yii::app()->request->getParam('flow_number','');
  86. // $status = (int)Yii::app()->request->getParam('status',0);
  87. $pwd = Yii::app()->request->getParam('pwd','');
  88. if (!$name ||!$mobile || !$address || !$flow||!$flow_number || !$pwd) {
  89. CommonFn::requestAjax(false,'请填写完整信息');exit;
  90. }
  91. $coupon = JCoupon::getByPwdOne($pwd);
  92. if (empty($coupon) || $coupon->status >= 2) {
  93. CommonFn::requestAjax(false,'兑换券不存在或已失效');exit;
  94. }
  95. $record = new JRecord();
  96. $record->user_info = array(
  97. 'name' => $name,
  98. 'mobile' => $mobile,
  99. );
  100. $record->address = $address;
  101. $record->coupon_id = (string)$coupon->_id;
  102. $record->status = 0;
  103. $record->flow = $flow;
  104. $record->flow_number = $flow_number;
  105. $record->time = time();
  106. $record->save();
  107. $coupon->status = 2;
  108. $coupon->save();
  109. CommonFn::requestAjax(true,'生成成功');exit;
  110. }
  111. public function actionOutputExcel()
  112. {
  113. $start_time = Yii::app()->request->getParam('start_time','');
  114. $end_time = Yii::app()->request->getParam('end_time','');
  115. $criteria = new EMongoCriteria();
  116. $criteria->time('>=',strtotime($start_time));
  117. $criteria->time('<=',strtotime($end_time));
  118. $cursor = JRecord::model()->findAll($criteria);
  119. $rows = CommonFn::getRowsFromCursor($cursor);
  120. $parsedRows = JRecord::model()->parse($rows);
  121. $res=Service::factory('JRecordService')->push($parsedRows);
  122. }
  123. }