JRecordController.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. $type = CommonFn::getComboboxData(Gift::$type_options, 100, true, 100);
  15. $tmp = Business::model()->findAll();
  16. // foreach ($tmp as $k) {
  17. // $k->delete();
  18. //// }
  19. // $tmp = JRecord::model()->findAll();
  20. // foreach ($tmp as $k) {
  21. // $k->delete();
  22. // }
  23. // $tmp = JCoupon::model()->findAll();
  24. // foreach ($tmp as $k) {
  25. // $k->delete();
  26. // }
  27. // $tmp = Gift::model()->findAll();
  28. // foreach ($tmp as $k) {
  29. // $k->delete();
  30. // }
  31. $this->render('index',array(
  32. 'status' => $status,
  33. 'type' => $type,
  34. ));
  35. }
  36. public function actionList()
  37. {
  38. $pageParams = CommonFn::getPageParams();
  39. $search = Yii::app()->request->getParam('search', '');
  40. $status = intval(Yii::app()->request->getParam('status', 100));
  41. $criteria = new EMongoCriteria($pageParams);
  42. if ($status != 100 ) {
  43. $criteria->status('==',$status);
  44. }
  45. if ($search) {
  46. $criteria->addCond('title','or',new MongoRegex('/' . $search . '/'));
  47. }
  48. $cursor = JRecord::model()->findAll($criteria);
  49. $rows = CommonFn::getRowsFromCursor($cursor);
  50. $parsedRows = JRecord::model()->parse($rows);
  51. $total = $cursor->count();
  52. echo CommonFn::composeDatagridData($parsedRows, $total);
  53. }
  54. public function actionEdit()
  55. {
  56. $id = Yii::app()->request->getParam('id','');
  57. $name = Yii::app()->request->getParam('name','');
  58. $mobile = Yii::app()->request->getParam('mobile','');
  59. $address = Yii::app()->request->getParam('address','');
  60. $flow = Yii::app()->request->getParam('flow','');
  61. $flow_number = Yii::app()->request->getParam('flow_number','');
  62. $flow_time = Yii::app()->request->getParam('flow_time','');
  63. $status = (int)Yii::app()->request->getParam('status',0);
  64. if (!$name ||!$mobile || !$address || !$flow||!$flow_number ) {
  65. CommonFn::requestAjax(false,'请填写完整信息');exit;
  66. }
  67. if (!CommonFn::isMongoId($id)) {
  68. CommonFn::requestAjax(false, '修改失败', array());
  69. }
  70. $record = JRecord::get(new MongoId($id));
  71. $record->user_info = array(
  72. 'name' => $name,
  73. 'mobile' => $mobile,
  74. );
  75. $record->address = $address;
  76. $record->status = $status;
  77. // 改动前后不想等 则判断为修改物流信息 则发送短信
  78. if ($flow != $record->flow || $flow_number != $record->flow_number || $flow_time != $record->flow_time) {
  79. }
  80. $record->flow = $flow;
  81. $record->flow_number = $flow_number;
  82. $record->flow_time = strtotime($flow_time);
  83. $record->save();
  84. CommonFn::requestAjax(true,'修改成功');exit;
  85. }
  86. public function actionAdd()
  87. {
  88. $name = Yii::app()->request->getParam('name','');
  89. $mobile = Yii::app()->request->getParam('mobile','');
  90. $address = Yii::app()->request->getParam('address','');
  91. $pwd = Yii::app()->request->getParam('pwd','');
  92. // $coding_num = Yii::app()->request->getParam('coding_num','');
  93. if (!$name ||!$mobile || !$address || !$pwd) {
  94. CommonFn::requestAjax(false,'请填写完整信息');exit;
  95. }
  96. $coupon = JCoupon::getByPwdOne($pwd);
  97. if (empty($coupon) || $coupon->status >= 2) {
  98. CommonFn::requestAjax(false,'兑换券不存在或已失效');exit;
  99. }
  100. $record = new JRecord();
  101. $record->user_info = array(
  102. 'name' => $name,
  103. 'mobile' => $mobile,
  104. );
  105. $record->address = $address;
  106. $record->coupon_id = (string)$coupon->_id;
  107. $record->status = 0;
  108. $record->time = time();
  109. $record->save();
  110. $coupon->status = 1;
  111. $coupon->save();
  112. CommonFn::requestAjax(true,'生成成功');exit;
  113. }
  114. public function actionOutputExcel()
  115. {
  116. $start_time = Yii::app()->request->getParam('start_time','');
  117. $end_time = Yii::app()->request->getParam('end_time','');
  118. $type = (int)Yii::app()->request->getParam('type','');
  119. $criteria = new EMongoCriteria();
  120. $criteria->addCond('time','>=',strtotime(date('Y-m-d H:i:s',strtotime($start_time))));
  121. $criteria->addCond('time','<=',strtotime(date('Y-m-d H:i:s',strtotime($end_time))));
  122. $cursor = JRecord::model()->findAll($criteria);
  123. $rows = CommonFn::getRowsFromCursor($cursor);
  124. $parsedRows = JRecord::model()->parse($rows);
  125. foreach ($cursor as $item) {
  126. $item->status = 2;
  127. $item->save();
  128. }
  129. $data = [];
  130. if ($type != 100) {
  131. foreach ($parsedRows as &$row) {
  132. if ($row['type'] == $type) {
  133. $data[] = $row;
  134. }
  135. }
  136. $type_name = Gift::$type_options[$type]['name'];
  137. } else {
  138. $data = $parsedRows;
  139. $type_name = '全部';
  140. }
  141. $res=Service::factory('JRecordService')->push($data,$type_name,['start' => $start_time, 'end' => $end_time]);
  142. }
  143. }