importer_check.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/1/19
  6. * Time: 下午10:50
  7. */
  8. class importer_check
  9. {
  10. private $goods;
  11. private $goods_common;
  12. private $goods_images;
  13. private $album_pic;
  14. public function __construct()
  15. {
  16. $this->goods = Model('goods');
  17. $this->goods_common = Model('goods_common');
  18. $this->goods_images = Model('goods_images');
  19. $this->album_pic = Model('album_pic');
  20. }
  21. private function check_goods($comm_id)
  22. {
  23. $goods = $this->goods->field('goods_id,color_id')->where(array('goods_commonid' => $comm_id))->limit(false)->select();
  24. if(empty($goods)) {
  25. return false;
  26. }
  27. if(count($goods) == 0) {
  28. return false;
  29. }
  30. return $goods;
  31. }
  32. private function check_goods_common($comm_id)
  33. {
  34. $goods = $this->goods_common->field('goods_commonid')->where(array('goods_commonid' => $comm_id))->select();
  35. if(empty($goods)) {
  36. return false;
  37. }
  38. if(count($goods) == 0) {
  39. return false;
  40. }
  41. return $goods;
  42. }
  43. private function check_images($comm_id)
  44. {
  45. $goods = $this->goods_images->field('goods_image_id,color_id')->where(array('goods_commonid' => $comm_id))->group('filesig')->limit(false)->select();
  46. if(empty($goods)) {
  47. return false;
  48. }
  49. if(count($goods) == 0) {
  50. return false;
  51. }
  52. return $goods;
  53. }
  54. public function proc($del = true)
  55. {
  56. $commonids = $this->goods_common->field('goods_commonid')->limit(false)->select();
  57. if(empty($commonids)) {
  58. Log::record("cannot find any goods from goods_common table.",Log::DEBUG);
  59. return;
  60. }
  61. foreach($commonids as $val)
  62. {
  63. $cid = $val['goods_commonid'];
  64. $goods = $this->check_goods($cid);
  65. $images = $this->check_images($cid);
  66. if($goods == false || $images == false)
  67. {
  68. if($del) {
  69. $this->goods_common->where(array('goods_commonid' => $cid))->delete();
  70. $this->goods->where(array('goods_commonid' => $cid))->delete();
  71. $this->goods_images->where(array('goods_commonid' => $cid))->delete();
  72. Log::record("delete goods when goods_commonid = {$cid}", Log::DEBUG);
  73. } else {
  74. Log::record("goods_commonid = {$cid} goods has error.",Log::DEBUG);
  75. }
  76. }
  77. }
  78. $commonids = $this->goods->field('goods_commonid')->group('goods_commonid')->limit(false)->select();
  79. if(empty($commonids)) {
  80. Log::record("cannot find any goods_commonid from goods table.",Log::DEBUG);
  81. return;
  82. }
  83. foreach($commonids as $val)
  84. {
  85. $cid = $val['goods_commonid'];
  86. $goods = $this->check_goods_common($cid);
  87. $images = $this->check_images($cid);
  88. if($goods == false || $images == false)
  89. {
  90. if($del) {
  91. $this->goods_common->where(array('goods_commonid' => $cid))->delete();
  92. $this->goods->where(array('goods_commonid' => $cid))->delete();
  93. $this->goods_images->where(array('goods_commonid' => $cid))->delete();
  94. Log::record("delete goods when goods_commonid = {$cid}",Log::DEBUG);
  95. } else {
  96. Log::record("goods_commonid = {$cid} goods has error.",Log::DEBUG);
  97. }
  98. }
  99. }
  100. }
  101. }