-- 充值记录：关联操作人员（member）及展示姓名
SET @db = DATABASE();

SET @sql = IF(
  (SELECT COUNT(*) FROM information_schema.columns
   WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'yw_electrical_charge' AND COLUMN_NAME = 'member_id') = 0,
  'ALTER TABLE `yw_electrical_charge` ADD COLUMN `member_id` int DEFAULT NULL COMMENT ''充值操作人员(member.id)'' AFTER `customer_id`',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql = IF(
  (SELECT COUNT(*) FROM information_schema.columns
   WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'yw_electrical_charge' AND COLUMN_NAME = 'recharge_user_name') = 0,
  'ALTER TABLE `yw_electrical_charge` ADD COLUMN `recharge_user_name` varchar(64) DEFAULT NULL COMMENT ''充值人姓名'' AFTER `member_id`',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql = IF(
  (SELECT COUNT(*) FROM information_schema.columns
   WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'yw_wx_pay_order' AND COLUMN_NAME = 'member_id') = 0,
  'ALTER TABLE `yw_wx_pay_order` ADD COLUMN `member_id` int DEFAULT NULL COMMENT ''下单操作人员(member.id)'' AFTER `customer_id`',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
