JRecordController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. $tmp = Business::model()->findAll();
  15. // foreach ($tmp as $k) {
  16. // $k->delete();
  17. // }
  18. // $tmp = JRecord::model()->findAll();
  19. // foreach ($tmp as $k) {
  20. // $k->delete();
  21. // }
  22. // $tmp = JCoupon::model()->findAll();
  23. // foreach ($tmp as $k) {
  24. // $k->delete();
  25. // }
  26. // $tmp = Gift::model()->findAll();
  27. // foreach ($tmp as $k) {
  28. // $k->delete();
  29. // }
  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. $flow_time = Yii::app()->request->getParam('flow_time','');
  61. $status = (int)Yii::app()->request->getParam('status',0);
  62. if (!$name ||!$mobile || !$address || !$flow||!$flow_number ) {
  63. CommonFn::requestAjax(false,'请填写完整信息');exit;
  64. }
  65. if (!CommonFn::isMongoId($id)) {
  66. CommonFn::requestAjax(false, '修改失败', array());
  67. }
  68. $record = JRecord::get(new MongoId($id));
  69. $record->user_info = array(
  70. 'name' => $name,
  71. 'mobile' => $mobile,
  72. );
  73. $record->address = $address;
  74. $record->status = $status;
  75. // 改动前后不想等 则判断为修改物流信息 则发送短信
  76. if ($flow != $record->flow || $flow_number != $record->flow_number || $flow_time != $record->flow_time) {
  77. }
  78. $record->flow = $flow;
  79. $record->flow_number = $flow_number;
  80. $record->flow_time = strtotime($flow_time);
  81. $record->save();
  82. CommonFn::requestAjax(true,'修改成功');exit;
  83. }
  84. public function actionAdd()
  85. {
  86. $name = Yii::app()->request->getParam('name','');
  87. $mobile = Yii::app()->request->getParam('mobile','');
  88. $address = Yii::app()->request->getParam('address','');
  89. $pwd = Yii::app()->request->getParam('pwd','');
  90. // $coding_num = Yii::app()->request->getParam('coding_num','');
  91. if (!$name ||!$mobile || !$address || !$pwd) {
  92. CommonFn::requestAjax(false,'请填写完整信息');exit;
  93. }
  94. $coupon = JCoupon::getByPwdOne($pwd);
  95. if (empty($coupon) || $coupon->status >= 2) {
  96. CommonFn::requestAjax(false,'兑换券不存在或已失效');exit;
  97. }
  98. $record = new JRecord();
  99. $record->user_info = array(
  100. 'name' => $name,
  101. 'mobile' => $mobile,
  102. );
  103. $record->address = $address;
  104. $record->coupon_id = (string)$coupon->_id;
  105. $record->status = 0;
  106. $record->time = time();
  107. $record->save();
  108. $coupon->status = 1;
  109. $coupon->save();
  110. CommonFn::requestAjax(true,'生成成功');exit;
  111. }
  112. public function actionOutputExcel()
  113. {
  114. $start_time = Yii::app()->request->getParam('start_time','');
  115. $end_time = Yii::app()->request->getParam('end_time','');
  116. $criteria = new EMongoCriteria();
  117. $criteria->addCond('time','>=',strtotime(date('Y-m-d 00:00:00',strtotime($start_time))));
  118. $criteria->addCond('time','<=',strtotime(date('Y-m-d 23:59:59',strtotime($start_time))));
  119. $cursor = JRecord::model()->findAll($criteria);
  120. $rows = CommonFn::getRowsFromCursor($cursor);
  121. $parsedRows = JRecord::model()->parse($rows);
  122. foreach ($cursor as $item) {
  123. $item->status = 2;
  124. $item->save();
  125. }
  126. $res=Service::factory('JRecordService')->push($parsedRows);
  127. }
  128. }