ImportStore.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\command\test\ln;
  3. use app\common\repositories\user\UserRepository;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\Output;
  7. use think\facade\Db;
  8. class ImportStore extends Command
  9. {
  10. protected function configure()
  11. {
  12. // 指令配置
  13. $this->setName('import_store')->setDescription('导入一壶茶商城148');
  14. }
  15. protected function execute(Input $input, Output $output)
  16. {
  17. $mer_info = Db::connect('chuxubao')->query("select * from rrx_merchant where mer_id = 148")[0] ?? [];
  18. //查询产品信息
  19. $store_product_list = Db::connect('chuxubao')->query('select * from rrx_store_product where mer_id = 148');
  20. foreach ($store_product_list as $store_product) {
  21. $product_info = Db::name('store_product')->where('mer_id', $store_product['mer_id'])->where('store_name', $store_product['store_name'])->find();
  22. if (empty($product_info)) {
  23. unset($product_info['product_id']);
  24. Db::name('store_product')->insert($product_info);
  25. }
  26. $attr_list = Db::connect('chuxubao')->query("select * from rrx_store_product_attr where product_id = {$store_product['product_id']}");
  27. foreach ($attr_list as $attr) {
  28. $temp = Db::name('store_product_attr')->where('product_id', $attr['product_id'])->where('attr_name', $attr['attr_name'])->find();
  29. if (empty($temp)) {
  30. $product_attr_id = Db::name('store_product_attr')->insert($attr);
  31. }
  32. }
  33. $attr_sort_list = Db::connect('chuxubao')->query("select * from rrx_store_product_attr_sort where product_id = {$store_product['product_id']}");
  34. foreach ($attr_sort_list as $attr_sort) {
  35. $temp = Db::name('store_product_attr')->where('product_id', $attr_sort['product_id'])->where('attr_id', $attr_sort['attr_id'])->find();
  36. if (empty($temp)) {
  37. $product_attr_sort_id = Db::name('store_product_attr_sort')->insert($attr_sort);
  38. }
  39. }
  40. $attr_value_list = Db::connect('chuxubao')->query("select * from rrx_store_product_attr_value where product_id = {$store_product['product_id']}");
  41. foreach ($attr_value_list as $attr_value) {
  42. var_dump($attr_value);
  43. $temp = Db::name('store_product_attr_value')->where('product_id', $attr_value['product_id'])->where('unique', $attr_value['unique'])->find();
  44. if (empty($temp)) {
  45. $attr_value_id = Db::name('store_product_attr_value')->insert($attr_value);
  46. }
  47. }
  48. $product_cate_list = Db::connect('chuxubao')->query("select * from rrx_store_product_cate where product_id = {$store_product['product_id']}");
  49. foreach ($product_cate_list as $product_cate) {
  50. var_dump($product_cate);
  51. $temp = Db::name('store_product_cate')->where('product_id', $product_cate['product_id'])->where('mer_cate_id', $product_cate['mer_cate_id'])->find();
  52. if (empty($temp)) {
  53. $attr_value_id = Db::name('store_product_cate')->insert($product_cate);
  54. }
  55. }
  56. }
  57. }
  58. }