123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/1/19
- * Time: 下午10:50
- */
- class importer_check
- {
- private $goods;
- private $goods_common;
- private $goods_images;
- private $album_pic;
- public function __construct()
- {
- $this->goods = Model('goods');
- $this->goods_common = Model('goods_common');
- $this->goods_images = Model('goods_images');
- $this->album_pic = Model('album_pic');
- }
- private function check_goods($comm_id)
- {
- $goods = $this->goods->field('goods_id,color_id')->where(array('goods_commonid' => $comm_id))->limit(false)->select();
- if(empty($goods)) {
- return false;
- }
- if(count($goods) == 0) {
- return false;
- }
- return $goods;
- }
- private function check_goods_common($comm_id)
- {
- $goods = $this->goods_common->field('goods_commonid')->where(array('goods_commonid' => $comm_id))->select();
- if(empty($goods)) {
- return false;
- }
- if(count($goods) == 0) {
- return false;
- }
- return $goods;
- }
- private function check_images($comm_id)
- {
- $goods = $this->goods_images->field('goods_image_id,color_id')->where(array('goods_commonid' => $comm_id))->group('filesig')->limit(false)->select();
- if(empty($goods)) {
- return false;
- }
- if(count($goods) == 0) {
- return false;
- }
- return $goods;
- }
- public function proc($del = true)
- {
- $commonids = $this->goods_common->field('goods_commonid')->limit(false)->select();
- if(empty($commonids)) {
- Log::record("cannot find any goods from goods_common table.",Log::DEBUG);
- return;
- }
- foreach($commonids as $val)
- {
- $cid = $val['goods_commonid'];
- $goods = $this->check_goods($cid);
- $images = $this->check_images($cid);
- if($goods == false || $images == false)
- {
- if($del) {
- $this->goods_common->where(array('goods_commonid' => $cid))->delete();
- $this->goods->where(array('goods_commonid' => $cid))->delete();
- $this->goods_images->where(array('goods_commonid' => $cid))->delete();
- Log::record("delete goods when goods_commonid = {$cid}", Log::DEBUG);
- } else {
- Log::record("goods_commonid = {$cid} goods has error.",Log::DEBUG);
- }
- }
- }
- $commonids = $this->goods->field('goods_commonid')->group('goods_commonid')->limit(false)->select();
- if(empty($commonids)) {
- Log::record("cannot find any goods_commonid from goods table.",Log::DEBUG);
- return;
- }
- foreach($commonids as $val)
- {
- $cid = $val['goods_commonid'];
- $goods = $this->check_goods_common($cid);
- $images = $this->check_images($cid);
- if($goods == false || $images == false)
- {
- if($del) {
- $this->goods_common->where(array('goods_commonid' => $cid))->delete();
- $this->goods->where(array('goods_commonid' => $cid))->delete();
- $this->goods_images->where(array('goods_commonid' => $cid))->delete();
- Log::record("delete goods when goods_commonid = {$cid}",Log::DEBUG);
- } else {
- Log::record("goods_commonid = {$cid} goods has error.",Log::DEBUG);
- }
- }
- }
- }
- }
|