Skip to content

Instantly share code, notes, and snippets.

View wikimo's full-sized avatar
😀

wikimo wikimo

😀
View GitHub Profile
@wikimo
wikimo / yilian_print.rb
Created January 18, 2018 02:36
yilian print
module CM
class Print
class << self
def print(order)
#TODO: 以后需要做改进
return false if order.blank? || order.user.machine_code.blank? || order.user.msign.blank?
created_at = order.created_at.strftime('%Y-%m-%d %H:%M')
print_name = order.user.real_name
# find promotion's products with promotion_id = 2
# if product ids result is 2,7
select product_id from spree_product_promotion_rules
where promotion_rule_id=(select id from spree_promotion_rules where type='Spree::Promotion::Rules::Product' and promotion_id=2)
# find the promotion product's quantity if order_id = 3
select distinct(spree_line_items.variant_id), spree_line_items.quantity from spree_product_promotion_rules
left join spree_line_items on spree_product_promotion_rules.product_id = spree_line_items.variant_id
where spree_product_promotion_rules.product_id in (2,7) and spree_line_items.order_id=3
require_dependency 'spree/calculator'
module Spree
class Calculator::FlatWithProducts < Calculator
preference :amount, :decimal, default: 0
preference :currency, :string, default: ->{ Spree::Config[:currency] }
def self.description
Spree.t(:flat_with_products)
end
@wikimo
wikimo / gist:7dc7817f72afa0fcc634
Last active August 29, 2015 14:14
jpush demo
# encoding: utf-8
require 'JPush'
# 消息推送类
class MessagePush
def initialize
master_secret = 'xxxxxx';
app_key = 'xxxxx';
@client = JPush::JPushClient.new(app_key, master_secret);
@wikimo
wikimo / img_reg.rb
Created October 20, 2014 08:33
Regexp html img tag
str = <<EOF
<li class="cc">
<a href="#" class="cover">
<img src="public/images/food-1.png" alt=""></a>
<div class="info">
<h1>Food One</h1>
</div>
</li>
<li class="cc">
@wikimo
wikimo / bootbox-bootstrap-3.x.js
Last active August 29, 2015 13:57
bootbox-bootstrap-3.x
/**
* bootbox.js v3.3.0
*
* http://bootboxjs.com/license.txt
*/
var bootbox = window.bootbox || (function(document, $) {
/*jshint scripturl:true sub:true */
var _locale = 'en',
_defaultLocale = 'en',
# coding:utf-8
#类似java import class
require 'faraday'
require 'nokogiri'
require 'json'
# http://www.taobao.com/index_inc/2013c/php/ajax/tms.php?ids=cat_1
#用来进行http操作,例get post
conn = Faraday.new(:url =>'http://www.taobao.com') do |f|