GiftController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 GiftController extends AdminController
  10. {
  11. public function actionIndex()
  12. {
  13. $c = new EMongoCriteria();
  14. $c->type('==',0);
  15. $bs = Business::model()->findAll($c);
  16. $tmp =[];
  17. foreach ($bs as $gift) {
  18. $tmp[] = array('name' => "$gift->source-$gift->name-$gift->mobile",'id' => (string)$gift->_id);
  19. }
  20. $tmp = CommonFn::getComboboxData($tmp, 0, false );
  21. $type_option = CommonFn::getComboboxData(Gift::$type_options, 1, true, 100);
  22. $this->render('index',[
  23. 'gifts' => $tmp,
  24. 'type' => $type_option,
  25. ]);
  26. }
  27. public function actionList()
  28. {
  29. $pageParams = CommonFn::getPageParams();
  30. $search = Yii::app()->request->getParam('search', '');
  31. $status = intval(Yii::app()->request->getParam('status', 100));
  32. $criteria = new EMongoCriteria($pageParams);
  33. if ($status != 100 ) {
  34. $criteria->status('==',$status);
  35. }
  36. if ($search) {
  37. $criteria->addCond('title','or',new MongoRegex('/' . $search . '/'));
  38. }
  39. $cursor = Gift::model()->findAll($criteria);
  40. $rows = CommonFn::getRowsFromCursor($cursor);
  41. $parsedRows = Gift::model()->parse($rows);
  42. $total = $cursor->count();
  43. echo CommonFn::composeDatagridData($parsedRows, $total);
  44. }
  45. public function actionEdit()
  46. {
  47. $id = Yii::app()->request->getParam('id','');
  48. $title = Yii::app()->request->getParam('title','');
  49. $gift_num = Yii::app()->request->getParam('gift_num','');
  50. $desc = Yii::app()->request->getParam('desc','');
  51. $type = (int)Yii::app()->request->getParam('type','');
  52. $supplier = Yii::app()->request->getParam('supplier','');
  53. if ($type == 100) {
  54. CommonFn::requestAjax(false,'请选择礼包类型');exit;
  55. }
  56. if (!CommonFn::isMongoId($id)) {
  57. CommonFn::requestAjax(false,'id错误');exit;
  58. }
  59. $gift = Gift::get(new MongoId($id));
  60. $gift->title = $title;
  61. $gift->gift_num = $gift_num;
  62. $gift->desc = $desc;
  63. $gift->supplier = $supplier;
  64. $gift->type = (int)$type;
  65. $gift->save();
  66. CommonFn::requestAjax(true,'保存成功');exit;
  67. }
  68. public function actionAdd()
  69. {
  70. $title = Yii::app()->request->getParam('title','');
  71. $desc = Yii::app()->request->getParam('desc','');
  72. $gift_num = Yii::app()->request->getParam('gift_num','');
  73. $supplier = Yii::app()->request->getParam('supplier','');
  74. $type = (int)Yii::app()->request->getParam('type','');
  75. if ($type == 100) {
  76. CommonFn::requestAjax(false,'请选择礼包类型');exit;
  77. }
  78. if(!$title || !$desc || !$gift_num || !$supplier ) {
  79. CommonFn::requestAjax(false,'请填写完整数据');exit;
  80. }
  81. $gift = new Gift();
  82. $gift->title = $title;
  83. $gift->gift_num = $gift_num;
  84. $gift->desc = $desc;
  85. $gift->type = (int)$type;
  86. $gift->supplier = $supplier;
  87. $gift->save();
  88. CommonFn::requestAjax(true,'保存成功');exit;
  89. }
  90. public function actionOutputExcel()
  91. {
  92. $data = JGEmploye::model()->findAll();
  93. $res=Service::factory('ExcelService')->push($data);
  94. }
  95. }