Info.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <?php
  2. namespace Product\Lib;
  3. use Dever;
  4. class Info
  5. {
  6. # 获取商品列表
  7. public function getList()
  8. {
  9. }
  10. # 获取商品详情
  11. public function getInfo_api($id)
  12. {
  13. $info = Dever::db('product/info')->getOne($id);
  14. $info = $this->get($info);
  15. print_r($info);die;
  16. return $info;
  17. }
  18. private function get($info)
  19. {
  20. # 基本信息
  21. $info['udate'] = date('Y-m-d H:i', $info['udate']);
  22. $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
  23. # 获取分类
  24. $info['category_info'] = Dever::load('product/lib/category')->getInfo($info['category']);
  25. # 获取属性
  26. $attr = Dever::db('product/info_attr')->select(array('info_id' => $info['id']));
  27. if ($attr) {
  28. foreach ($attr as $k => $v) {
  29. $attr_info = Dever::load('product/lib/attr')->getInfo($v['attr_id'], $v['attr_value']);
  30. if ($attr_info) {
  31. $info['attr'][] = $attr_info;
  32. }
  33. }
  34. }
  35. # 获取规格
  36. $info['spec'] = Dever::load('product/lib/spec')->getData($info['id'], 'getData');
  37. # 获取价格
  38. $info['sku'] = Dever::load('product/lib/sku')->getData($info['id']);
  39. # 获取组合商品
  40. if ($info['type'] > 10) {
  41. $info['goods'] = Dever::json_decode($info['goods']);
  42. } else {
  43. unset($info['goods']);
  44. }
  45. # 获取单位信息
  46. if ($info['unit'] > 0) {
  47. $info['unit'] = Dever::db('product/unit')->find($info['unit']);
  48. }
  49. return $info;
  50. }
  51. # 获取商品及其属性列表
  52. public function getSetList($table, $other_where, $cate_id = false, $col = 'goods_id', $set = array())
  53. {
  54. $price = Dever::input('price', 0);
  55. $buy_price = Dever::input('buy_price', 0);
  56. $total = Dever::input('total', 1);
  57. if ($cate_id) {
  58. $where['top_category_id'] = $cate_id;
  59. }
  60. $where['status'] = 1;
  61. $data = Dever::db('product/info')->getData($where);
  62. $result = array();
  63. if ($data) {
  64. $i = 0;
  65. foreach ($data as $k => $v) {
  66. $sku = Dever::db('product/info_sku')->select(array('info_id' => $v['id']));
  67. if ($sku) {
  68. $other_where[$col] = $v['id'];
  69. $other_where['sku_id'] = -1;
  70. $other = Dever::db($table)->find($other_where);
  71. if ($set) {
  72. $result[$i]['set'] = $set;
  73. }
  74. $result[$i]['id'] = $v['id'];
  75. $result[$i]['name'] = $v['name'];
  76. $result[$i]['type'] = $v['type'];
  77. $result[$i]['stock'] = $v['stock'];
  78. $result[$i]['commission'] = $v['commission'];
  79. $result[$i]['old_price'] = 0;
  80. $result[$i]['old_buy_price'] = 0;
  81. $result[$i]['price'] = $price;
  82. $result[$i]['buy_price'] = $buy_price;
  83. $result[$i]['select'] = 2;
  84. $result[$i]['del'] = 1;
  85. $result[$i]['total'] = 0;
  86. if ($other) {
  87. if (isset($other['commission']) && $other['commission']) {
  88. $result[$i]['commission'] = $other['commission'];
  89. }
  90. if (isset($other['price']) && $other['price']) {
  91. $result[$i]['price'] = $other['price'];
  92. }
  93. if (isset($other['buy_price']) && $other['buy_price']) {
  94. $result[$i]['buy_price'] = $other['buy_price'];
  95. }
  96. if (isset($other['min']) && $other['min']) {
  97. $result[$i]['min'] = $other['min'];
  98. }
  99. if (isset($other['in_num'])) {
  100. if (isset($other['out_num'])) {
  101. $result[$i]['total'] = $other['in_num'] - $other['out_num'];
  102. } else {
  103. $result[$i]['total'] = $other['in_num'];
  104. }
  105. } elseif (isset($other['num'])) {
  106. $result[$i]['total'] = $other['num'];
  107. }
  108. $result[$i]['select'] = $other['state'];
  109. }
  110. $result[$i]['total'] = $result[$i]['total'] * $total;
  111. $result[$i]['children'] = array();
  112. $num = count($sku);
  113. if ($sku[0]['key'] == -1) {
  114. $result[$i]['old_price'] = $sku[0]['price'];
  115. $result[$i]['old_buy_price'] = $sku[0]['buy_price'];
  116. if (!$price && $result[$i]['price'] <= 0) {
  117. $result[$i]['price'] = $sku[0]['price'];
  118. }
  119. if (!$buy_price && $result[$i]['buy_price'] <= 0) {
  120. $result[$i]['buy_price'] = $sku[0]['buy_price'];
  121. }
  122. //$result[$i]['id'] .= '-' . $sku[0]['id'];
  123. $result[$i]['end'] = true;
  124. } else {
  125. foreach ($sku as $k1 => $v1) {
  126. $v1['sku_name'] = '';
  127. if ($v1['key']) {
  128. $key = str_replace('-', ',', $v1['key']);
  129. $spec = Dever::db('product/info_spec_value')->getData(array('ids' => $key));
  130. $v1['sku_name'] = $spec['name'];
  131. }
  132. $name = $v['name'];
  133. if ($v1['sku_name']) {
  134. $name .= '-' . $v1['sku_name'];
  135. }
  136. $children = array
  137. (
  138. 'id' => $v['id'] . '-' . $v1['id'],
  139. 'name' => $name,
  140. 'stock' => $v['stock'],
  141. 'commission' => $v['commission'],
  142. 'old_price' => $v1['price'] ? $v1['price'] : 0,
  143. 'old_buy_price' => $v1['buy_price'] ? $v1['buy_price'] : 0,
  144. 'price' => $price ? $price : $v1['price'],
  145. 'buy_price' => $buy_price ? $buy_price : $v1['buy_price'],
  146. 'type' => $v['type'],
  147. 'del' => 1,
  148. 'end' => true,
  149. 'total' => 0,
  150. );
  151. $other_where['sku_id'] = $v1['id'];
  152. $other_sku = Dever::db($table)->find($other_where);
  153. $children['select'] = 2;
  154. $children['total'] = 0;
  155. if ($set) {
  156. $children['set'] = $set;
  157. }
  158. if ($other_sku) {
  159. if (isset($other_sku['commission']) && $other_sku['commission']) {
  160. $children['commission'] = $other_sku['commission'];
  161. }
  162. if (isset($other_sku['price']) && $other_sku['price']) {
  163. $children['price'] = $other_sku['price'];
  164. }
  165. if (isset($other_sku['buy_price']) && $other_sku['buy_price']) {
  166. $children['buy_price'] = $other_sku['buy_price'];
  167. }
  168. if (isset($other_sku['min']) && $other_sku['min']) {
  169. $children['min'] = $other_sku['min'];
  170. }
  171. if (isset($other_sku['in_num'])) {
  172. if (isset($other_sku['out_num'])) {
  173. $children['total'] = $other_sku['in_num'] - $other_sku['out_num'];
  174. } else {
  175. $children['total'] = $other_sku['in_num'];
  176. }
  177. } elseif (isset($other_sku['num'])) {
  178. $children['total'] = $other_sku['num'];
  179. }
  180. $children['select'] = $other_sku['state'];
  181. }
  182. $children['total'] = $children['total']*$total;
  183. $result[$i]['children'][] = $children;
  184. }
  185. }
  186. $i++;
  187. }
  188. }
  189. }
  190. return $result;
  191. }
  192. # 获取支付所需要的信息
  193. public function getPayInfo($id, $sku = 0, $type = 1, $value = '')
  194. {
  195. $info = is_array($id) ? $id : Dever::db($this->table_info)->one($id);
  196. if ($info) {
  197. if ($type == 2) {
  198. $info['price'] = $info['f_price'];
  199. unset($info['s_price']);
  200. } else {
  201. unset($info['f_price']);
  202. }
  203. $info['sku_name'] = '';
  204. $sku = $sku > 0 ? $sku : $info['sku_id'];
  205. if ($sku > 0) {
  206. $where['info_id'] = $info['id'];
  207. $where['id'] = $sku;
  208. $sku = Dever::db('goods/info_sku')->find($where);
  209. if ($sku) {
  210. if ($sku['type'] == 3) {
  211. $price = $sku['price'];
  212. $s_price = $sku['s_price'];
  213. $f_price = $sku['f_price'];
  214. $c_price = $sku['c_price'];
  215. $sku['price'] = 0;
  216. $sku['s_price'] = 0;
  217. $sku['f_price'] = 0;
  218. $sku['c_price'] = 0;
  219. # 计算价格
  220. $key = explode('_', $sku['key']);
  221. $attr = Dever::db('attr/info')->find($key[0]);
  222. if ($attr) {
  223. if ($value >= $attr['sell_value']) {
  224. $sku['price'] = $price;
  225. $sku['s_price'] = $s_price;
  226. $sku['f_price'] = $f_price;
  227. $sku['c_price'] = $c_price;
  228. }
  229. }
  230. }
  231. $info['sku_id'] = $sku['id'];
  232. if ($type == 2) {
  233. $info['price'] = $sku['f_price'];
  234. } else {
  235. $info['price'] = $sku['price'];
  236. $info['s_price'] = $sku['s_price'];
  237. $info['c_price'] = $sku['c_price'];
  238. }
  239. $info['min'] = $sku['min'];
  240. //$info['attr_json'] = $sku['attr'];
  241. $info['attr'] = Dever::json_decode($sku['attr']);
  242. if ($info['attr']) {
  243. $info['attr'] = Dever::load('attr/api')->getInfoByJson($info['attr']);
  244. $info['sku_name'] = $info['attr']['string'];
  245. }
  246. }
  247. }
  248. $this->getGroup($info);
  249. if (floor($info['min']) == $info['min']) {
  250. $info['min'] = intval($info['min']);
  251. }
  252. /*
  253. $info['freight_id'] = 0;
  254. $info['freight_price'] = 0;
  255. $freight = $this->freight($info, $info['price'], $user, $num);
  256. if ($freight) {
  257. $info['freight_id'] = $freight['id'];
  258. $info['freight_price'] = $freight['price'];
  259. }
  260. */
  261. # 佣金计算
  262. //$info['reward'] = $this->reward($info, $info['price']*$num);
  263. }
  264. if (isset($info['price'])) {
  265. $info['price'] = trim($info['price']);
  266. }
  267. if (isset($info['s_price'])) {
  268. $info['s_price'] = trim($info['s_price']);
  269. }
  270. if (isset($info['c_price'])) {
  271. $info['c_price'] = trim($info['c_price']);
  272. }
  273. if (isset($info['f_price'])) {
  274. $info['f_price'] = trim($info['f_price']);
  275. }
  276. return $info;
  277. }
  278. }