M230915020143AgentMigrate.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace addons\Agent\console\migrations;
  3. use common\models\common\CrontabTask;
  4. use common\models\common\GlobalVarMap;
  5. use yii\db\Migration;
  6. /**
  7. * Class M230915020143AgentMigrate
  8. */
  9. class M230915020143AgentMigrate extends Migration
  10. {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function safeUp()
  15. {
  16. $table = 'qimall_addons_agent_team_achievement';
  17. $sql = "select * from information_schema.TABLES where TABLE_NAME = '{$table}';";
  18. $res = $this->db->createCommand($sql)->execute();
  19. if (empty($res)) {
  20. $sql = "
  21. CREATE TABLE `qimall_addons_agent_team_achievement` (
  22. `id` bigint(18) NOT NULL AUTO_INCREMENT,
  23. `mall_id` int(11) NOT NULL DEFAULT '0' COMMENT '商城ID',
  24. `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户ID',
  25. `personal_performance` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '个人业绩',
  26. `team_performance` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '渠道业绩',
  27. `month` varchar(255) NOT NULL DEFAULT '0.00' COMMENT '月份',
  28. `rate` decimal(5,2) NOT NULL DEFAULT '0.00' COMMENT '百分比',
  29. `level` tinyint(1) NOT NULL DEFAULT '0' COMMENT '渠道等级',
  30. `is_settlement` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否结算',
  31. `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  32. `created_at` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
  33. `updated_at` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
  34. PRIMARY KEY (`id`) USING BTREE,
  35. KEY `mall_id` (`mall_id`) USING BTREE,
  36. KEY `user_id` (`user_id`) USING BTREE
  37. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='渠道业绩';";
  38. $this->execute($sql);
  39. }
  40. $table = 'qimall_addons_agent_team_achievement_order_log';
  41. $sql = "select * from information_schema.TABLES where TABLE_NAME = '{$table}';";
  42. $res = $this->db->createCommand($sql)->execute();
  43. if (empty($res)) {
  44. $sql = "
  45. CREATE TABLE `qimall_addons_agent_team_achievement_order_log` (
  46. `id` bigint(18) NOT NULL AUTO_INCREMENT,
  47. `mall_id` int(11) NOT NULL DEFAULT '0' COMMENT '商城ID',
  48. `order_no` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '订单编号',
  49. `settlement_type` tinyint(1) NOT NULL DEFAULT '0' COMMENT '结算类型:0:订单完成结算;1:按月结算',
  50. `buy_user_id` int(11) NOT NULL DEFAULT '0' COMMENT '购买者id',
  51. `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '此订单计入给谁的个人业绩',
  52. `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  53. `created_at` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
  54. `updated_at` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
  55. PRIMARY KEY (`id`) USING BTREE,
  56. KEY `mall_id` (`mall_id`) USING BTREE,
  57. KEY `order_no` (`order_no`) USING BTREE
  58. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='渠道业绩订单记录';";
  59. $this->execute($sql);
  60. }
  61. $res = CrontabTask::findOne(['command'=>'agent/agent/index']);
  62. if(empty($res)){
  63. $sql="INSERT INTO `qimall_crontab_task`( `name`, `command`, `type`, `rule`, `is_warning`, `status`, `created_at`, `updated_at`) VALUES ('按月结算渠道业绩额外奖励', 'agent/agent/index', 2, '0 0 0 0 1 *', 0, 1, 1658479952, 1658479952);";
  64. $this->execute($sql);
  65. }
  66. $res = GlobalVarMap::findOne(['name'=>'Agent','type'=>'IncomeMap']);
  67. if(empty($res)){
  68. $sql ="INSERT INTO `qimall_global_var_map`(`name`, `title`, `type`, `is_addons`, `status`, `created_at`, `updated_at`) VALUES
  69. ('Agent', '渠道分红', 'IncomeMap', 1, 1, 1654569888, 1654569888);";
  70. $this->execute($sql);
  71. }
  72. }
  73. /**
  74. * {@inheritdoc}
  75. */
  76. public function safeDown()
  77. {
  78. echo "M230915020143AgentMigrate cannot be reverted.\n";
  79. return false;
  80. }
  81. /*
  82. // Use up()/down() to run migration code without a transaction.
  83. public function up()
  84. {
  85. }
  86. public function down()
  87. {
  88. echo "M230915020143AgentMigrate cannot be reverted.\n";
  89. return false;
  90. }
  91. */
  92. }