gcid_fill.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/1/20
  6. * Time: 下午4:53
  7. */
  8. require_once(BASE_CRONTAB_PATH . '/crawl/class_tree.php');
  9. class gcid_fill
  10. {
  11. private $cls_tree;
  12. private $mod_goods;
  13. private $mod_goods_common;
  14. public function __construct()
  15. {
  16. $this->mod_goods = Model('goods');
  17. $this->mod_goods_common = Model('goods_common');
  18. $this->cls_tree = new class_tree();
  19. }
  20. private function fill_class($cid,&$val,&$name)
  21. {
  22. $ret = $this->cls_tree->get_info($cid,$cid_1,$cid_2,$cid_3,$name);
  23. if($ret) {
  24. $val['gc_id'] = $cid;
  25. $val['gc_id_1'] = $cid_1;
  26. $val['gc_id_2'] = $cid_2;
  27. $val['gc_id_3'] = $cid_3;
  28. return true;
  29. } else {
  30. return false;
  31. }
  32. }
  33. public function proc()
  34. {
  35. $this->proc_goods_common();
  36. $this->proc_goods();
  37. }
  38. private function proc_goods()
  39. {
  40. $items = $this->mod_goods->field('gc_id')->group('gc_id')->select();
  41. foreach ($items as $item)
  42. {
  43. $cid = $item['gc_id'];
  44. $val = array();
  45. if ($this->fill_class($cid, $val,$name)) {
  46. $ret = $this->mod_goods->where(array('gc_id' => $cid))->update($val);
  47. if ($ret == false) {
  48. Log::record("cannot update goods class id info where gc_id = {$cid}.", Log::DEBUG);
  49. }
  50. } else {
  51. Log::record("cannot find goods class info where gc_id = {$cid}.", Log::DEBUG);
  52. }
  53. }
  54. }
  55. private function proc_goods_common()
  56. {
  57. $items = $this->mod_goods_common->field('gc_id')->group('gc_id')->select();
  58. foreach ($items as $item) {
  59. $cid = $item['gc_id'];
  60. $val = array();
  61. if ($this->fill_class($cid, $val,$name)) {
  62. $val['gc_name'] = $name;
  63. //$val['type_id'] = $cid;
  64. $ret = $this->mod_goods_common->where(array('gc_id' => $cid))->update($val);
  65. if ($ret == false) {
  66. Log::record("cannot update goods class id info where gc_id = {$cid}.", Log::DEBUG);
  67. }
  68. } else {
  69. Log::record("cannot find goods class info where gc_id = {$cid}.", Log::DEBUG);
  70. }
  71. }
  72. }
  73. }