ps_workorder_spec_run.php 785 B

1234567891011121314151617181920
  1. <?php
  2. $root = dirname(dirname(__DIR__));
  3. define('APP_PATH', $root . '/application/');
  4. require $root . '/thinkphp/base.php';
  5. \think\App::initCommon();
  6. $prefix = \think\Db::getConfig('prefix');
  7. $table = $prefix . 'ps_workorder';
  8. $rows = \think\Db::query("SHOW COLUMNS FROM `{$table}` LIKE 'spec'");
  9. if ($rows) {
  10. echo $table . ".spec exists\n";
  11. } else {
  12. \think\Db::execute("ALTER TABLE `{$table}` ADD COLUMN `spec` varchar(100) NOT NULL DEFAULT '' COMMENT '规格,可不关联产品档案' AFTER `product_name`");
  13. echo $table . ".spec added\n";
  14. }
  15. $updated = \think\Db::execute(
  16. "UPDATE `{$table}` w LEFT JOIN `{$prefix}ps_product` p ON p.id = w.product_id SET w.spec = IFNULL(p.spec, '') WHERE w.spec = '' AND w.product_id > 0"
  17. );
  18. echo "backfilled {$updated} rows\n";