public function actionDownload($type = 'none', $value = 'none') { if ($type == '' && $value == '') { $couponDetail = new Coupon(); $result = $couponDetail->getAllCouponDetail(); } else { if ($type == 'category') { $couponDetail = new Coupon(); $result = $couponDetail->getAllCouponDetailByCategory($value); } else { if ($type == 'coupontype') { $couponDetail = new Coupon(); $result = $couponDetail->getAllCouponDetailByType($value); } else { if ($type == 'store') { $couponDetail = new Coupon(); $result = $couponDetail->getAllCouponDetailBySite($value); } else { echo '<strong>oops!!</strong><br>seems like it\'s not working...:(<br>'; } } } } $data = array(); // CouponType, Website.WebsiteName AS Site, Coupon.Description AS Description, Coupon.Expiry AS Expiry, CouponCode, WebsiteURL AS url array_push($data, array('Coupon Type' => "Coupon Type", 'Store name' => 'Store name', 'Coupon Description' => 'Coupon Description', 'Coupon Expiry' => 'Coupon Expiry', 'Coupon Code' => 'Coupon Code', 'store url' => 'Store URL')); foreach ($result as $row) { $expiry = $row['Expiry']; if ($expiry == NULL) { $expiry = "2020-01-01 23:59:59"; } array_push($data, array('Coupon Type' => $row['CouponType'], 'Store name' => $row['Site'], 'Coupon Description' => $row['Description'], 'Coupon Expiry' => $expiry, 'Coupon Code' => $row['CouponCode'], 'store url' => $row['url'])); } //print_r($data); $obj = new \PHPExcel(); // Create new PHPExcel object $objPHPExcel = new \PHPExcel(); // Fill worksheet from values in array $objPHPExcel->getActiveSheet()->fromArray($data, null, 'A1'); // Rename worksheet $objPHPExcel->getActiveSheet()->setTitle('Members'); // Set AutoSize for name and email fields $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true); //print_r($objPHPExcel); // Save Excel 2007 file $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('CouponExcel.xlsx'); $fileLocation = '../web/CouponExcel.xlsx'; }
static function nearest($latitude, $longitude) { $max_distance = 100; $radius = 6371; $distance = sprintf("( %d * acos( cos( radians(%s) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(%s) ) + sin( radians(%s) ) * sin( radians( latitude ) ) ) ) AS distance", $radius, $latitude, $longitude, $latitude); return Coupon::having('distance', '<', $max_distance)->orderBy('distance', 'ASC')->take(30)->get(array('*', DB::raw($distance))); }
public static function isValid($code) { $couponCount = Coupon::whereCode($code)->count(); if ($couponCount > 0) { return true; } return false; }
public function getAllCoupons($pageSize = '100') { $coupons1 = Coupon::find(); $pagination = new Pagination(['defaultPageSize' => $pageSize, 'totalCount' => $coupons1->count()]); $coupons = $coupons1->with('website')->joinWith('couponCategories')->offset($pagination->offset)->limit($pagination->limit)->all(); //this one works and to display just 60 coupons on the main page //$this->lastresult = $coupons; return ['coupons' => $coupons, 'pagination' => $pagination]; }
function couponType() { $result = Coupon::find()->orderBy('CouponType')->distinct(true)->select('CouponType')->limit(10)->all(); $myarray = array(); $i = 0; foreach ($result as $value) { $myarray[$i++] = $value->CouponType; } return $myarray; }
/** * This method add a coupon * * @param string $couponName * @return Response */ public function add($couponName) { $couponName = strtolower($couponName); $coupon = Coupon::findByCode($couponName); if (!$coupon) { return redirect()->route('cart.index'); } Cart::addCoupon($couponName, $coupon->discount); return redirect()->route('cart.index'); }
/** * Return the field values from the model * * @param integer $id * @param array $fields * @return array */ protected function fieldsFromModel($id, array $fields) { $post = Coupon::findOrFail($id); $fieldNames = $fields; $fields = ['id' => $id]; foreach ($fieldNames as $field) { $fields[$field] = $post->{$field}; } return $fields; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Coupon::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'expireDatetime' => $this->expireDatetime, 'lastModifyDatetime' => $this->lastModifyDatetime, 'requireScore' => $this->requireScore]); $query->andFilterWhere(['like', 'Coupon_name', $this->Coupon_name])->andFilterWhere(['like', 'Coupon_description', $this->Coupon_description])->andFilterWhere(['like', 'image', $this->image]); return $dataProvider; }
/** * list function. * * @description Listado de las notificaciones de la base de datos * @access public * @return void */ public function getIndex() { $limit = Input::get('limit', 10); $page = Input::get('page', 1) - 1; $search = Input::get('search', ''); $order = Input::get('order', 'id|asc'); $rows = Notification::leftJoin('coupons', 'notifications.coupon_id', '=', 'coupons.id'); if ($search != "") { $where_search = '(message LIKE ? OR title LIKE ?)'; $registers->whereRaw($where_search, array("%{$search}%", "%{$search}%")); $total = $rows->count(); } else { $total = $rows->count(); } $order = explode("|", $order); $rows->take($limit)->skip($page * $limit)->orderBy($order[0], $order[1]); $rows = $rows->get(array('notifications.*', 'coupons.title')); $devices = DB::table('user_users_tokens')->count(); $coupons = Coupon::orderBy('title', 'ASC')->select('coupons.*')->lists('title', 'id'); return View::make('admin.notifications.index')->with("rows", $rows)->with("devices", $devices)->with("coupons", $coupons)->with("search", $search)->with("page", $page)->with("limit", $limit)->with("total", $total)->with("show", min(($page + 1) * $limit, $total))->with("torder", $order[1] == "asc" ? "desc" : "asc"); }
public function store(CouponCreateRequest $request) { $coupon = Coupon::create($request->fillData()); return redirect()->route('admin.coupon.index')->withSuccess('添加成功!'); }
private function _get_user_coupons($ids) { global $ids_check; $ids_check = $ids; $coupons = Coupon::leftJoin("clients", "coupons.client_id", "=", "clients.id")->where("clients.user_id", "=", Auth::user()->id)->get("coupons.id"); $user_coupons = array_map(function ($object) { global $ids_check; return in_array($object->id, $ids_check) ? $object->id : false; }, $coupons); return $user_coupons; }
/** * Display a listing of the resource. * * @return Response */ public function index() { return view('backoffice.coupon.index', ['items' => Coupon::all()]); }
/** * @return \yii\db\ActiveQuery */ public function getCoupons() { return $this->hasMany(Coupon::className(), ['id' => 'coupon_id'])->viaTable('Participant_has_coupon', ['Participant_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getCoupon() { return $this->hasOne(Coupon::className(), ['id' => 'coupon_id']); }
private function _validate_coupon($id) { return Coupon::find($id); }
public function actionDisplayCouponByType() { $type = $_GET['type']; $couponDetail = new Coupon(); $resultType = $couponDetail->couponDetailByType($type); if (count($resultType) == 0) { echo '<strong>oops!!</strong><br>Looks like there\'s no offer for you...:(<br>'; } else { return $this->renderPartial('displaycouponbytype', ['resultType' => $resultType]); } }
public function actionDownload() { $model = new Coupon(); if (isset($_GET['filter'])) { $filter = strval($_GET['filter']); } if (isset($_GET['value'])) { $value = intval($_GET['value']); } $result = $model->getFilterResult($filter, $value); //$result = Coupon::$lastresult; // Instantiate a new PHPExcel object $objPHPExcel = new \PHPExcel(); // Set the active Excel worksheet to sheet 0 $objPHPExcel->setActiveSheetIndex(0); // Iterate through each result from the SQL query in turn // We fetch each database result row into $row in turn $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(4); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(40); $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(40); //Make Headings $objPHPExcel->getActiveSheet()->setCellValue('A1', 'S.No')->setCellValue('B1', 'Vendor')->setCellValue('C1', 'Coupon Title')->setCellValue('D1', 'Coupon Details'); // Initialise the Excel row number $rowCount = 2; foreach ($result as $row) { // Set cell An to the "name" column from the database (assuming you have a column called name) // where n is the Excel row number (ie cell A1 in the first row) $objPHPExcel->getActiveSheet()->SetCellValue('A' . $rowCount, $rowCount - 1); // Set cell Bn to the "age" column from the database (assuming you have a column called age) // where n is the Excel row number (ie cell A1 in the first row) $objPHPExcel->getActiveSheet()->SetCellValue('B' . $rowCount, $row->website->WebsiteName); $objPHPExcel->getActiveSheet()->SetCellValue('C' . $rowCount, $row->Title); $objPHPExcel->getActiveSheet()->SetCellValue('D' . $rowCount, $row->Description); // Increment the Excel row counter $rowCount++; } // Instantiate a Writer to create an OfficeOpenXML Excel .xlsx file $objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel); // Write the Excel file to filename some_excel_file.xlsx in the current directory $objWriter->save('CouponData.xlsx'); }
function getAllCouponType() { $result = Coupon::find()->orderBy('CouponType')->distinct(true)->select('CouponType')->limit(10)->all(); $type = array(); $ind = 0; foreach ($result as $value) { $type[$ind++] = $value->CouponType; } return $type; }
/** * Finds the Coupon model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Coupon the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Coupon::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }