M241203101341Huolihuoban2.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace addons\CloudStock\console\migrations;
  3. use addons\CloudStock\common\services\AgentService;
  4. use addons\CloudStock\common\services\CloudStockStatisticService;
  5. use addons\CloudStock\common\services\EqualAwardService;
  6. use common\models\mall\Mall;
  7. use yii\db\Migration;
  8. /**
  9. * Class M241203101341Huolihuoban2
  10. */
  11. class M241203101341Huolihuoban2 extends Migration
  12. {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public function safeUp()
  17. {
  18. $sql = "CREATE TABLE `qimall_addons_cloud_stock_price_difference_profit` (
  19. `id` int(11) NOT NULL AUTO_INCREMENT,
  20. `mall_id` int(11) NOT NULL COMMENT '商城id',
  21. `user_id` int(11) NOT NULL COMMENT '代理商用户id',
  22. `order_no` varchar(255) NOT NULL COMMENT '订单编号',
  23. `type` tinyint(1) NOT NULL default 0 COMMENT '业务类型:1:上级配货,2:下级补货;3:会员买货',
  24. `child_id` int(11) NOT NULL COMMENT '下级代理商用户id',
  25. `num` int(11) NOT NULL default 0 COMMENT '商品件数',
  26. `money` decimal(12,2) NOT NULL default 0 COMMENT '价差利润',
  27. `goods_id` int(11) NOT NULL default 0 COMMENT '商品id',
  28. `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  29. `created_at` int(11) NOT NULL DEFAULT '0',
  30. `updated_at` int(11) NOT NULL DEFAULT '0',
  31. PRIMARY KEY (`id`) USING BTREE,
  32. KEY (`user_id`) USING BTREE
  33. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='差价利润表';
  34. CREATE TABLE `qimall_addons_cloud_stock_loss_amount` (
  35. `id` int(11) NOT NULL AUTO_INCREMENT,
  36. `mall_id` int(11) NOT NULL COMMENT '商城id',
  37. `user_id` int(11) NOT NULL COMMENT '代理商用户id',
  38. `order_no` varchar(255) NOT NULL COMMENT '订单编号',
  39. `type` tinyint(1) NOT NULL default 0 COMMENT '业务类型:1:上级配货,2:下级补货;3:会员买货',
  40. `child_id` int(11) NOT NULL COMMENT '下级代理商用户id',
  41. `num` int(11) NOT NULL default 0 COMMENT '商品件数',
  42. `money` decimal(12,2) NOT NULL default 0 COMMENT '流失金额',
  43. `goods_id` int(11) NOT NULL default 0 COMMENT '商品id',
  44. `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  45. `created_at` int(11) NOT NULL DEFAULT '0',
  46. `updated_at` int(11) NOT NULL DEFAULT '0',
  47. PRIMARY KEY (`id`) USING BTREE,
  48. KEY (`user_id`) USING BTREE
  49. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='流失金额表';
  50. CREATE TABLE `qimall_addons_cloud_stock_early_warning_log` (
  51. `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  52. `mall_id` int(11) NOT NULL DEFAULT '0' COMMENT '商城ID',
  53. `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '会员id',
  54. `goods_id` int(11) NOT NULL DEFAULT '0' COMMENT '导入的商品的id',
  55. `status` tinyint(1) NOT NULL DEFAULT 1,
  56. `updated_at` int(11) NOT NULL DEFAULT '0',
  57. `created_at` int(11) NOT NULL DEFAULT '0' COMMENT '添加时间',
  58. PRIMARY KEY (`id`) USING BTREE
  59. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='库存预警通知发送日志';
  60. CREATE TABLE `qimall_addons_cloud_stock_statistic` (
  61. `id` int(11) NOT NULL AUTO_INCREMENT,
  62. `mall_id` int(11) NOT NULL DEFAULT '0' COMMENT '商城id',
  63. `capital_type` varchar(255) NOT NULL DEFAULT '0' COMMENT '奖励类型',
  64. `settlement_status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0:待结算;1:已结算',
  65. `money` decimal(12,2) NOT NULL DEFAULT '0' COMMENT '数量',
  66. `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  67. `created_at` int(11) NOT NULL DEFAULT '0',
  68. `updated_at` int(11) NOT NULL DEFAULT '0',
  69. PRIMARY KEY (`id`) USING BTREE,
  70. KEY `mall_id` (`mall_id`) USING BTREE
  71. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='云库存奖励统计';
  72. CREATE TABLE `qimall_addons_cloud_stock_dispense_order` (
  73. `id` int(11) NOT NULL AUTO_INCREMENT,
  74. `mall_id` int(11) NOT NULL COMMENT '商城id',
  75. `type` tinyint(3) NOT NULL DEFAULT '0' COMMENT '1上级配货;2:平台充值',
  76. `user_id` int(11) NOT NULL COMMENT '代理商用户id',
  77. `agent_price` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '代理拿货价',
  78. `child_id` int(11) NOT NULL COMMENT '配货下级用户id',
  79. `child_price` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '配货下级的拿货价',
  80. `money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '配货金额',
  81. `order_no` varchar(255) NOT NULL COMMENT '补货订单编号',
  82. `goods_id` int(11) NOT NULL COMMENT '商品id',
  83. `num` int(11) NOT NULL DEFAULT '0' COMMENT '补货商品数量',
  84. `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  85. `created_at` int(11) NOT NULL DEFAULT '0',
  86. `updated_at` int(11) NOT NULL DEFAULT '0',
  87. PRIMARY KEY (`id`) USING BTREE,
  88. KEY `user_id` (`user_id`) USING BTREE,
  89. KEY `order_no` (`order_no`) USING BTREE
  90. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='配货订单表';
  91. ALTER table qimall_addons_cloud_stock_agent add `equal_award_frozen_price` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '待结算平级奖';
  92. ALTER table qimall_addons_cloud_stock_agent add `equal_award_price` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '已结算平级奖';
  93. ALTER table qimall_addons_cloud_stock_agent add `loss_amount` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '流失金额';
  94. ALTER table qimall_addons_cloud_stock_agent add `difference_profit` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '价差利润';
  95. ALTER TABLE qimall_addons_cloud_stock_agent add `is_equal_award_restriction` tinyint(1) not null DEFAULT 0 COMMENT '是否开启平级奖限制:1是;0:否';
  96. ALTER table qimall_addons_cloud_stock_goods add `warning_quantity` varchar(5) NOT NULL DEFAULT '' COMMENT '预警数量';
  97. ";
  98. $this->execute($sql);
  99. $this->execute("INSERT INTO `qimall_crontab_task` ( `name`, `command`, `type`, `rule`, `is_warning`, `status`, `created_at`, `updated_at`) VALUES ('云库存-平级奖结算', 'cloud-stock/index/settlement-equal-reward', 2, '0 0 1 * * *', 0, 1, 1735121957, 1735121957)");
  100. $mall_list = Mall::getEnableMallList(true);
  101. foreach ($mall_list as $mall) {
  102. (new EqualAwardService(['mall_id' => $mall['id']]))->fixOrderNo('commission');
  103. (new EqualAwardService(['mall_id' => $mall['id']]))->fixOrderNo('commission_frozen');
  104. (new CloudStockStatisticService(['mall_id' => $mall['id']]))->fix('commission');
  105. (new CloudStockStatisticService(['mall_id' => $mall['id']]))->fix('commission_frozen');
  106. (new AgentService(['mall_id' => $mall['id']]))->fix('commission');
  107. (new AgentService(['mall_id' => $mall['id']]))->fix('commission_frozen');
  108. }
  109. }
  110. /**
  111. * {@inheritdoc}
  112. */
  113. public function safeDown()
  114. {
  115. echo "M241203101341Huolihuoban2 cannot be reverted.\n";
  116. return false;
  117. }
  118. /*
  119. // Use up()/down() to run migration code without a transaction.
  120. public function up()
  121. {
  122. }
  123. public function down()
  124. {
  125. echo "M241203101341Huolihuoban2 cannot be reverted.\n";
  126. return false;
  127. }
  128. */
  129. }