Explorar el Código

增加订单导入功能

abiao hace 4 años
padre
commit
e8058fbccb

+ 25 - 8
app/models/order.rb

@@ -15,14 +15,19 @@ class Order < ActiveRecord::Base
 
     before_save :before_save
     after_update :patch_send_product
-    #after_create :patch_send_product
-
-    scope :所有订单, -> {}
-    scope :未支付, -> { where("status=?","unpay") }
-    scope :已关闭, -> { where("status=?","closed") }
-    scope :处理中, -> { where("status=?","processing") }
-    scope :待收货, -> { where("status=?","dispatch") }
-    scope :已完成, -> { where("status=?","complete") }
+    after_create :import_orders
+
+    def import_orders
+        # 更新order信息
+        od = Order.where("id = ?", self.id).first
+        if od.source=="sys"
+            od.order_type=0
+            od.pick_way=0
+            od.status="processing"
+            od.has_commission=false
+            od.save
+        end
+    end
 
     def before_save
         if self.express_company.length>0
@@ -31,10 +36,22 @@ class Order < ActiveRecord::Base
                 self.express_code = express.express_code
             end
         end
+        if !self.wx_user.blank?
+            self.errors.add("微信ID不存在")
+        end
         self.depart=self.wx_user.depart
     end
 
 
+    scope :所有订单, -> {}
+    scope :未支付, -> { where("status=?","unpay") }
+    scope :已关闭, -> { where("status=?","closed") }
+    scope :处理中, -> { where("status=?","processing") }
+    scope :待收货, -> { where("status=?","dispatch") }
+    scope :已完成, -> { where("status=?","complete") }
+
+
+
     def patch_send_product
         if  self.status=="processing"
             #发放未发放赠品

+ 1 - 1
config/initializers/rails_admin.rb

@@ -106,7 +106,7 @@ RailsAdmin.config do |config|
     end
     export
     import do
-      only ["UpdateOrder","LiveAward","Order","BaseDetail","OrderDetail"]
+      only ["UpdateOrder","LiveAward","Order","OrderDetail"]
     end
     history_index do
       # PAPER_TRAIL_AUDIT_MODEL

+ 1 - 0
config/locales/models/order.yml

@@ -30,6 +30,7 @@ zh-CN:
        buy_price: 进货现金总价(分)
        paied_time: 支付时间
        paied_at: 支付时间(时间戳)
+       has_commission: 是否分佣
        trade_no: 流水号
        status: 状态
        pay_way: 支付方式

+ 12 - 0
db/migrate/20210901032357_add_has_commission_column_to_orders.rb

@@ -0,0 +1,12 @@
+# This migration and CreateVersionAssociations provide the necessary
+# schema for tracking associations.
+class AddHasCommisionColumnToOrders < ActiveRecord::Migration
+  def self.up
+    add_column :orders, :has_commission, :boolean, :default=>false
+  end
+
+  def self.down
+    remove_column :orders, :has_commission
+
+  end
+end