goods_common.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/8/25
  6. * Time: 下午4:18
  7. */
  8. require_once(BASE_ROOT_PATH . '/helper/brand_helper.php');
  9. require_once (BASE_ROOT_PATH . '/helper/user_session/fcode.php');
  10. abstract class common_base
  11. {
  12. protected $commonid;
  13. protected $common_info;
  14. protected $store_id;
  15. public function __construct($param)
  16. {
  17. if (is_array($param)) {
  18. $this->common_info = $param;
  19. $this->commonid = intval($this->common_info['goods_commonid']);
  20. $this->store_id = intval($this->common_info['store_id']);
  21. }
  22. }
  23. public abstract function format();
  24. }
  25. class common_sumary extends common_base
  26. {
  27. public function __construct($param)
  28. {
  29. parent::__construct($param);
  30. }
  31. public function format()
  32. {
  33. $ret['goods_commonid'] = intval($this->common_info['goods_commonid']);
  34. $ret['goods_commend'] = intval($this->common_info['goods_jingle']);
  35. $brand_id = intval($this->common_info['brand_id']);
  36. $ret['brand_id'] = $brand_id;
  37. $ret['brand_name'] = brand_helper::instance()->name($brand_id);
  38. $ret['type_id'] = intval($this->common_info['type_id']);
  39. $ret['gc_id'] = intval($this->common_info['gc_id_3']);
  40. $ret['goods_selltime'] = intval($this->common_info['goods_selltime']);
  41. $ret['goods_freight'] = doubleval($this->common_info['goods_freight']);
  42. $is_fcode = intval($this->common_info['is_fcode']) == 1 ? true : false;
  43. $ret['is_fcode'] = $is_fcode;
  44. if($is_fcode) {
  45. $fcode = new user_session\fcode();
  46. $ret['has_fcode'] = $fcode->usable_num($this->commonid,$lock_num) == false ? false : true;
  47. } else {
  48. $ret['has_fcode'] = false;
  49. }
  50. if($ret['has_fcode']) {
  51. $ret['fcode_desc'] = "你有F码,可以购买";
  52. }
  53. else
  54. {
  55. if(isset($lock_num) && $lock_num > 0) {
  56. $ret['fcode_desc'] = "F码处于锁定状态,激活后可以购买";
  57. } else {
  58. $ret['fcode_desc'] = "你没有该商品的F码";
  59. }
  60. }
  61. return $ret;
  62. }
  63. }
  64. class common_spec extends common_base
  65. {
  66. private $have_spec;
  67. private $spec_name;
  68. private $spec_list;
  69. private $attr_list;
  70. public function __construct($param,$goods_list)
  71. {
  72. parent::__construct($param);
  73. $spec_name = unserialize($this->common_info['spec_name']);
  74. if(empty($spec_name)) {
  75. $this->have_spec = false;
  76. $this->spec_name = '';
  77. }
  78. else
  79. {
  80. $this->have_spec = true;
  81. foreach ($spec_name as $spid => $spname) {
  82. $this->spec_name = $spname;
  83. break;
  84. }
  85. }
  86. $spec_value = unserialize($this->common_info['spec_value']);
  87. if(!empty($spec_value))
  88. {
  89. foreach ($spec_value as $sp_id => $sp_val)
  90. {
  91. foreach ($sp_val as $spv_id => $spv_name) {
  92. $this->spec_list[$spv_id]['spv_name'] = $spv_name;
  93. }
  94. }
  95. }
  96. else
  97. {
  98. $this->spec_list = array();
  99. }
  100. foreach ($goods_list as $value)
  101. {
  102. $goods_id = intval($value['goods_id']);
  103. $spec = unserialize($value['goods_spec']);
  104. if(!empty($spec))
  105. {
  106. foreach ($spec as $spv_id => $spv_name) {
  107. $this->spec_list[$spv_id]['goods_id'] = $goods_id;
  108. }
  109. }
  110. }
  111. $attrs = unserialize($this->common_info['goods_attr']);
  112. foreach ($attrs as $key => $val)
  113. {
  114. foreach ($val as $attr_key => $attr_val)
  115. {
  116. if($attr_key === 'name') {
  117. $name = $attr_val;
  118. } else {
  119. $value = $attr_val;
  120. }
  121. }
  122. $this->attr_list[] = array("name" => $name,"value" => $value);
  123. }
  124. }
  125. public function format()
  126. {
  127. $ret['have_spec'] = $this->have_spec;
  128. $ret['spec_name'] = $this->spec_name;
  129. $ret['skus'] = array();
  130. foreach ($this->spec_list as $key => $value) {
  131. array_push($ret['skus'],$value);
  132. }
  133. $ret['attrs'] = $this->attr_list;
  134. return $ret;
  135. }
  136. }
  137. class goods_common extends common_base
  138. {
  139. private $goods_list;
  140. private $goods_ids;
  141. private $show_gid;
  142. public function __construct($common_info,$goods_list,$show_gid)
  143. {
  144. parent::__construct($common_info);
  145. $this->goods_list = $goods_list;
  146. $this->goods_ids = $this->goods_ids();
  147. $show_gid = intval($show_gid);
  148. if(in_array($show_gid,$this->goods_ids)) {
  149. $this->show_gid = $show_gid;
  150. } else {
  151. $this->show_gid = $this->goods_ids[0];
  152. }
  153. }
  154. public function goods_ids()
  155. {
  156. $ids = array();
  157. foreach ($this->goods_list as $value) {
  158. $gid = intval($value['goods_id']);
  159. array_push($ids,$gid);
  160. }
  161. return $ids;
  162. }
  163. static private function img_url($value,$store_id)
  164. {
  165. return cthumb($value, 1280, $store_id);
  166. }
  167. private function goods_images()
  168. {
  169. $mod = Model('goods');
  170. $items = $mod->getGoodsImageListEx(array('goods_commonid' => $this->commonid));
  171. $images = array();
  172. foreach ($items as $val) {
  173. $img = $val['goods_image'];
  174. $images[] = self::img_url($img,$this->store_id);
  175. }
  176. return $images;
  177. }
  178. public function format()
  179. {
  180. $summary = new common_sumary($this->common_info);
  181. $base_info = $summary->format();
  182. $goods_spec = new common_spec($this->common_info,$this->goods_list);
  183. $spec = $goods_spec->format();
  184. $ret = array_merge($base_info,$spec);
  185. $ret['images'] = $this->goods_images();
  186. $ret['show_goods'] = $this->show_gid;
  187. return $ret;
  188. }
  189. }