Goods.php 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Goods extends BaseModel
  12. {
  13. const STATE1 = 1; // 出售中
  14. const STATE0 = 0; // 下架
  15. const STATE10 = 10; // 违规
  16. const VERIFY1 = 1; // 审核通过
  17. const VERIFY0 = 0; // 审核失败
  18. const VERIFY10 = 10; // 等待审核
  19. public $lock = false; //是否加锁
  20. public $page_info;
  21. /**
  22. * 新增商品数据
  23. * @access public
  24. * @author csdeshang
  25. * @param type $data 数据
  26. * @return type
  27. */
  28. public function addGoods($data)
  29. {
  30. $result = Db::name('goods')->insertGetId($data);
  31. if ($result) {
  32. $this->_dGoodsCache($result);
  33. $this->_dGoodsCommonCache($data['goods_commonid']);
  34. $this->_dGoodsSpecCache($data['goods_commonid']);
  35. }
  36. return $result;
  37. }
  38. /**
  39. * 新增商品公共数据
  40. * @access public
  41. * @author csdeshang
  42. * @param type $data 数据
  43. * @return type
  44. */
  45. public function addGoodsCommon($data)
  46. {
  47. return Db::name('goodscommon')->insertGetId($data);
  48. }
  49. /**
  50. * 新增多条商品数据
  51. * @access public
  52. * @author csdeshang
  53. * @param type $data 数据
  54. * @return type
  55. */
  56. public function addGoodsImagesAll($data)
  57. {
  58. $result = Db::name('goodsimages')->insertAll($data);
  59. if ($result) {
  60. foreach ($data as $val) {
  61. $this->_dGoodsImageCache($val['goods_commonid'] . '|' . $val['color_id']);
  62. }
  63. }
  64. return $result;
  65. }
  66. /**
  67. * 商品SKU列表
  68. * @access public
  69. * @author csdeshang
  70. * @param type $condition 条件
  71. * @param type $field 字段
  72. * @param type $group 分组
  73. * @param type $order 排序
  74. * @param type $limit 限制
  75. * @param type $pagesize 分页
  76. * @param type $lock 是否锁定
  77. * @param type $count 计数
  78. * @return array
  79. */
  80. public function getGoodsList($condition, $field = '*', $group = '', $order = '', $limit = 0, $pagesize = 0, $lock = false, $count = 0)
  81. {
  82. // $condition = $this->_getRecursiveClass($condition);
  83. if ($pagesize) {
  84. $result = Db::name('goods')->field($field)->where($condition);
  85. if ($group) {
  86. $result = $result->group($group);
  87. }
  88. $result = $result->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  89. $this->page_info = $result;
  90. return $result->items();
  91. } else {
  92. $result = Db::name('goods')->field($field)->where($condition)->limit($limit)->group($group)->order($order)->select()->toArray();
  93. return $result;
  94. }
  95. }
  96. /**
  97. * 获取指定分类指定店铺下的随机商品列表
  98. * @access public
  99. * @author csdeshang
  100. * @param int $gcId 一级分类ID
  101. * @param int $storeId 店铺ID
  102. * @param int $notEqualGoodsId 此商品ID除外
  103. * @param int $size 列表最大长度
  104. * @return array|null
  105. */
  106. public function getGoodsGcStoreRandList($gcId, $storeId, $notEqualGoodsId = 0, $size = 4)
  107. {
  108. $condition = array();
  109. $condition[] = array('store_id', '=', $storeId);
  110. $condition[] = array('gc_id_1', '=', $gcId);
  111. if ($notEqualGoodsId > 0) {
  112. $condition[] = array('goods_id', '<>', $notEqualGoodsId);
  113. }
  114. return Db::name('goods')->where($condition)->limit($size)->select()->toArray();
  115. }
  116. /**
  117. * 出售中的商品SKU列表(只显示不同颜色的商品,前台商品索引,店铺也商品列表等使用)
  118. * @access public
  119. * @author csdeshang
  120. * @param type $condition 条件
  121. * @param string $field 字段
  122. * @param type $order 排序
  123. * @param type $pagesize 分页
  124. * @param type $limit 限制
  125. * @return type
  126. */
  127. public function getGoodsListByColorDistinct($condition, $field = '*', $order = 'goods_id asc', $pagesize = 0, $limit = 0)
  128. {
  129. $condition[] = array('goods_state', '=', self::STATE1);
  130. $condition[] = array('goods_verify', '=', self::VERIFY1);
  131. // $condition = $this->_getRecursiveClass($condition);
  132. $field = "CONCAT(goods_commonid) as nc_distinct ," . $field;
  133. $count = Db::name('goods')->where($condition)->field("distinct CONCAT(goods_commonid)")->count();
  134. $goods_list = array();
  135. if ($count != 0) {
  136. $goods_list = $this->getGoodsOnlineList($condition, $field, $pagesize, $order, $limit, 'CONCAT(goods_commonid)', false, $count);
  137. }
  138. return $goods_list;
  139. }
  140. /**
  141. * 获取goodscommon和goods联表列表
  142. * @access public
  143. * @author csdeshang
  144. * @param type $condition 条件
  145. * @param string $field 字段
  146. * @param type $order 排序
  147. * @param type $pagesize 分页
  148. * @param type $limit 限制
  149. * @return type
  150. */
  151. public function getGoodsUnionList($condition, $field, $order = 'goodscommon.mall_goods_commend desc,goodscommon.mall_goods_sort asc', $group = '', $pagesize = 0, $limit = 0)
  152. {
  153. $condition[] = array('goodscommon.goods_state', '=', self::STATE1);
  154. $condition[] = array('goodscommon.goods_verify', '=', self::VERIFY1);
  155. // if(isset($condition['goodscommon.gc_id'])){
  156. // $condition = $this->_getRecursiveClass($condition,'goodscommon.');
  157. // }
  158. $result = Db::name('goodscommon')->alias('goodscommon')->join('goods goods', 'goods.goods_commonid=goodscommon.goods_commonid')->field($field)->where($condition)->order($order);
  159. if ($group) {
  160. $result = $result->group($group);
  161. }
  162. if ($pagesize) {
  163. $result = $result->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  164. $this->page_info = $result;
  165. return $result->items();
  166. } else {
  167. $result = $result->limit($limit)->select()->toArray();
  168. return $result;
  169. }
  170. }
  171. /**
  172. * 在售商品SKU列表
  173. * @access public
  174. * @author csdeshang
  175. * @param array $condition 条件
  176. * @param string $field 字段
  177. * @param int $pagesize 分页
  178. * @param string $order 排序
  179. * @return array
  180. */
  181. public function getGeneralGoodsList($condition, $field = '*', $pagesize = 0, $order = 'goods_id desc')
  182. {
  183. $condition[] = array('is_virtual', '=', 0);
  184. $condition[] = array('is_goodsfcode', '=', 0);
  185. $condition[] = array('goods_state', '=', 1);
  186. return $this->getGoodsList($condition, $field, '', $order, 0, $pagesize, false, 0);
  187. }
  188. /**
  189. * 在售商品SKU列表
  190. * @access public
  191. * @author csdeshang
  192. * @param array $condition 条件
  193. * @param str $field 字段
  194. * @param int $pagesize 分页
  195. * @param str $order 排序
  196. * @param int $limit 限制
  197. * @param str $group 分组
  198. * @param bool $lock 是否锁定
  199. * @param int $count 计数
  200. * @return array
  201. */
  202. public function getGoodsOnlineList($condition, $field = '*', $pagesize = 0, $order = 'goods_id desc', $limit = 0, $group = '', $lock = false, $count = 0)
  203. {
  204. $condition[] = array('goods_state', '=', self::STATE1);
  205. $condition[] = array('goods_verify', '=', self::VERIFY1);
  206. return $this->getGoodsList($condition, $field, $group, $order, $limit, $pagesize, $lock, $count);
  207. }
  208. /**
  209. * 出售中的普通商品列表,即不包括虚拟商品、F码商品、预售商品
  210. * @access public
  211. * @author csdeshang
  212. * @param type $condition 条件
  213. * @param type $field 字段
  214. * @param type $pagesize 分页
  215. * @param type $type 类型
  216. * @return array
  217. */
  218. public function getGoodsListForPromotion($condition, $field = '*', $pagesize = 0, $type = '')
  219. {
  220. switch ($type) {
  221. case 'wholesale':
  222. $condition[] = array('goodscommon.is_virtual', '=', 0);
  223. $condition[] = array('goodscommon.is_goodsfcode', '=', 0);
  224. $condition[] = array('goods.goods_lock', '=', 0);
  225. $condition[] = array('goodscommon.goods_state', '=', self::STATE1);
  226. $condition[] = array('goodscommon.goods_verify', '=', self::VERIFY1);
  227. return $this->getGoodsUnionList($condition, $field, 'goodscommon.goods_commonid asc', 'goodscommon.goods_commonid', $pagesize);
  228. case 'xianshi':
  229. case 'bargain':
  230. case 'presell':
  231. case 'bundling':
  232. $condition[] = array('goodscommon.is_virtual', '=', 0);
  233. $condition[] = array('goodscommon.is_goodsfcode', '=', 0);
  234. $condition[] = array('goods.goods_lock', '=', 0);
  235. $condition[] = array('goodscommon.goods_state', '=', self::STATE1);
  236. $condition[] = array('goodscommon.goods_verify', '=', self::VERIFY1);
  237. return $this->getGoodsUnionList($condition, $field, 'goodscommon.goods_commonid asc', '', $pagesize);
  238. case 'combo':
  239. $condition[] = array('is_virtual', '=', 0);
  240. $condition[] = array('is_goodsfcode', '=', 0);
  241. $condition[] = array('goods_state', '=', self::STATE1);
  242. $condition[] = array('goods_verify', '=', self::VERIFY1);
  243. return $this->getGoodsList($condition, $field, '', '', 0, $pagesize);
  244. case 'gift':
  245. $condition[] = array('is_virtual', '=', 0);
  246. return $this->getGoodsList($condition, $field, '', '', 0, $pagesize);
  247. default:
  248. break;
  249. }
  250. }
  251. /**
  252. * 商品列表 卖家中心使用
  253. * @access public
  254. * @author csdeshang
  255. * @param array $condition 条件
  256. * @param array $field 字段
  257. * @param string $pagesize 分页
  258. * @param string $order 排序
  259. * @return array
  260. */
  261. public function getGoodsCommonList($condition, $field = '*', $pagesize = 10, $order = 'goods_commonid desc')
  262. {
  263. // $condition = $this->_getRecursiveClass($condition);
  264. if ($pagesize) {
  265. $result = Db::name('goodscommon')->field($field)->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  266. $this->page_info = $result;
  267. return $result->items();
  268. } else {
  269. return Db::name('goodscommon')->field($field)->where($condition)->order($order)->select()->toArray();
  270. }
  271. }
  272. /**
  273. * 出售中的商品列表 卖家中心使用
  274. * @access public
  275. * @author csdeshang
  276. * @param array $condition 条件
  277. * @param array $field 字段
  278. * @param string $pagesize 分页
  279. * @param string $order 排序
  280. * @return array
  281. */
  282. public function getGoodsCommonOnlineList($condition, $field = '*', $pagesize = 10, $order = "goods_commonid desc")
  283. {
  284. $condition[] = array('goods_state', '=', self::STATE1);
  285. $condition[] = array('goods_verify', '=', self::VERIFY1);
  286. return $this->getGoodsCommonList($condition, $field, $pagesize, $order);
  287. }
  288. /**
  289. * 出售中的普通商品列表,即不包括虚拟商品、F码商品、预售商品
  290. * @access public
  291. * @author csdeshang
  292. * @param array $condition 条件
  293. * @param str $field 字段
  294. * @param int $pagesize 分页
  295. * @param str $type 排序
  296. * @return array
  297. */
  298. public function getGoodsCommonListForPromotion($condition, $field = '*', $pagesize = 10, $type)
  299. {
  300. if ($type == 'groupbuy') {
  301. $condition[] = array('is_virtual', '=', 0);
  302. $condition[] = array('is_goodsfcode', '=', 0);
  303. $condition[] = array('goods_lock', '=', 0);
  304. $condition[] = array('goods_state', '=', self::STATE1);
  305. $condition[] = array('goods_verify', '=', self::VERIFY1);
  306. }
  307. return $this->getGoodsCommonList($condition, $field, $pagesize);
  308. }
  309. /**
  310. * 出售中的未参加促销的虚拟商品列表
  311. * @access public
  312. * @author csdeshang
  313. * @param array $condition 条件
  314. * @param str $field 字段
  315. * @param int $pagesize 分页
  316. * @return array
  317. */
  318. public function getGoodsCommonListForVrPromotion($condition, $field = '*', $pagesize = 10)
  319. {
  320. $condition[] = array('is_virtual', '=', 1);
  321. $condition[] = array('is_goodsfcode', '=', 0);
  322. $condition[] = array('goods_lock', '=', 0);
  323. $condition[] = array('goods_state', '=', self::STATE1);
  324. $condition[] = array('goods_verify', '=', self::VERIFY1);
  325. return $this->getGoodsCommonList($condition, $field, $pagesize);
  326. }
  327. /**
  328. * 仓库中的商品列表 卖家中心使用
  329. * @access public
  330. * @author csdeshang
  331. * @param array $condition 条件
  332. * @param array $field 字段
  333. * @param string $pagesize 分页
  334. * @param string $order 排序
  335. * @return array
  336. */
  337. public function getGoodsCommonOfflineList($condition, $field = '*', $pagesize = 10, $order = "goods_commonid desc")
  338. {
  339. $condition[] = array('goods_state', '=', self::STATE0);
  340. $condition[] = array('goods_verify', '=', self::VERIFY1);
  341. return $this->getGoodsCommonList($condition, $field, $pagesize, $order);
  342. }
  343. /**
  344. * 违规的商品列表 卖家中心使用
  345. * @access public
  346. * @author csdeshang
  347. * @param array $condition 条件
  348. * @param array $field 字段
  349. * @param string $pagesize 分页
  350. * @param string $order 排序
  351. * @return array
  352. */
  353. public function getGoodsCommonLockUpList($condition, $field = '*', $pagesize = 10, $order = "goods_commonid desc")
  354. {
  355. $condition[] = array('goods_state', '=', self::STATE10);
  356. $condition[] = array('goods_verify', '=', self::VERIFY1);
  357. return $this->getGoodsCommonList($condition, $field, $pagesize, $order);
  358. }
  359. /**
  360. * 等待审核或审核失败的商品列表 卖家中心使用
  361. * @access public
  362. * @author csdeshang
  363. * @param array $condition 条件
  364. * @param array $field 字段
  365. * @param string $pagesize 分页
  366. * @param string $order 排序
  367. * @return array
  368. */
  369. public function getGoodsCommonWaitVerifyList($condition, $field = '*', $pagesize = 10, $order = "goods_commonid desc")
  370. {
  371. $condition[] = array('goods_verify', '<>', self::VERIFY1);
  372. return $this->getGoodsCommonList($condition, $field, $pagesize, $order);
  373. }
  374. /**
  375. * 查询商品SUK及其店铺信息
  376. * @access public
  377. * @author csdeshang
  378. * @param array $condition 条件
  379. * @param string $field 字段
  380. * @return array
  381. */
  382. public function getGoodsStoreList($condition, $field = '*')
  383. {
  384. // $condition = $this->_getRecursiveClass($condition);
  385. return Db::name('goods')->alias('goods')->field($field)->join('store store', 'goods.store_id = store.store_id', 'inner')->where($condition)->select()->toArray();
  386. }
  387. /**
  388. * 查询推荐商品(随机排序)
  389. * @access public
  390. * @author csdeshang
  391. * @param int $store_id 店铺
  392. * @param int $limit 限制
  393. * @return array
  394. */
  395. public function getGoodsCommendList($store_id, $limit = 5)
  396. {
  397. $goods_commend_list = $this->getGoodsOnlineList(array(array('store_id', '=', $store_id), array('goods_commend', '=', 1)), 'goods_id,goods_name,goods_advword,goods_image,store_id,goods_promotion_price,goods_price,goods_salenum', 0, '', $limit, 'goods_commonid');
  398. if (!empty($goods_id_list)) {
  399. $tmp = array();
  400. foreach ($goods_id_list as $v) {
  401. $tmp[] = $v['goods_id'];
  402. }
  403. $goods_commend_list = $this->getGoodsOnlineList(array(array('goods_id', 'in', $tmp)), 'goods_id,goods_name,goods_advword,goods_image,store_id,goods_promotion_price,goods_salenum', 0, '', $limit);
  404. }
  405. return $goods_commend_list;
  406. }
  407. /**
  408. * 计算商品库存
  409. * @access public
  410. * @author csdeshang
  411. * @param array $goods_list 商品列表
  412. * @return array|boolean
  413. */
  414. public function calculateStorage($goods_list)
  415. {
  416. // 计算库存
  417. if (!empty($goods_list)) {
  418. $goodsid_array = array();
  419. foreach ($goods_list as $value) {
  420. $goodscommonid_array[] = $value['goods_commonid'];
  421. }
  422. $goods_storage = $this->getGoodsList(array(array('goods_commonid', 'in', $goodscommonid_array)), 'goods_storage,goods_commonid,goods_id,goods_storage_alarm');
  423. $storage_array = array();
  424. foreach ($goods_storage as $val) {
  425. if ($val['goods_storage_alarm'] != 0 && $val['goods_storage'] <= $val['goods_storage_alarm']) {
  426. $storage_array[$val['goods_commonid']]['alarm'] = true;
  427. }
  428. //初始化
  429. if (!isset($storage_array[$val['goods_commonid']]['sum'])) {
  430. $storage_array[$val['goods_commonid']]['sum'] = 0;
  431. }
  432. $storage_array[$val['goods_commonid']]['sum'] += $val['goods_storage'];
  433. $storage_array[$val['goods_commonid']]['goods_id'] = $val['goods_id'];
  434. }
  435. return $storage_array;
  436. } else {
  437. return false;
  438. }
  439. }
  440. /**
  441. * 更新商品SUK数据
  442. * @access public
  443. * @author csdeshang
  444. * @param array $update 更新数据
  445. * @param array $condition 条件
  446. * @return boolean
  447. */
  448. public function editGoods($update, $condition)
  449. {
  450. $goods_list = $this->getGoodsList($condition, 'goods_id');
  451. if (empty($goods_list)) {
  452. return true;
  453. }
  454. $goodsid_array = array();
  455. foreach ($goods_list as $value) {
  456. $goodsid_array[] = $value['goods_id'];
  457. }
  458. return $this->editGoodsById($update, $goodsid_array);
  459. }
  460. /**
  461. * 更新商品SUK数据
  462. * @access public
  463. * @author csdeshang
  464. * @param array $update 更新数据
  465. * @param int|array $goodsid_array 商品ID
  466. * @return boolean|unknown
  467. */
  468. public function editGoodsById($update, $goodsid_array)
  469. {
  470. if (empty($goodsid_array)) {
  471. return true;
  472. }
  473. $update['goods_edittime'] = TIMESTAMP;
  474. $result = Db::name('goods')->where('goods_id', 'in', (array)$goodsid_array)->update($update);
  475. if ($result) {
  476. foreach ((array) $goodsid_array as $value) {
  477. $this->_dGoodsCache($value);
  478. }
  479. }
  480. return $result;
  481. }
  482. /**
  483. * 更新商品促销价 (需要验证抢购和秒杀是否进行)
  484. * @access public
  485. * @author csdeshang
  486. * @param array $condition 条件
  487. * @return boolean
  488. */
  489. public function editGoodsPromotionPrice($condition)
  490. {
  491. $goods_list = $this->getGoodsList($condition, 'goods_id,goods_commonid');
  492. $goods_array = array();
  493. foreach ($goods_list as $val) {
  494. $goods_array[$val['goods_commonid']][$val['goods_id']] = $val;
  495. }
  496. $groupbuy_model = model('groupbuy');
  497. $pxianshigoods_model = model('pxianshigoods');
  498. foreach ($goods_array as $key => $val) {
  499. // 查询抢购时候进行
  500. $groupbuy = $groupbuy_model->getGroupbuyOnlineInfo(array(array('goods_commonid', '=', $key)));
  501. if (!empty($groupbuy)) {
  502. // 更新价格
  503. $this->editGoods(array('goods_promotion_price' => $groupbuy['groupbuy_price'], 'goods_promotion_type' => 1), array('goods_commonid' => $key));
  504. continue;
  505. }
  506. foreach ($val as $k => $v) {
  507. // 查询秒杀时候进行
  508. $condition = array();
  509. $condition[] = array('goods_id', '=', $k);
  510. $condition[] = array('xianshigoods_state', '=', 1);
  511. $condition[] = array('xianshigoods_starttime', '<', TIMESTAMP);
  512. $condition[] = array('xianshigoods_end_time', '>', TIMESTAMP);
  513. $xianshigoods = $pxianshigoods_model->getXianshigoodsInfo($condition);
  514. if (!empty($xianshigoods)) {
  515. // 更新价格
  516. $this->editGoodsById(array('goods_promotion_price' => $xianshigoods['xianshigoods_price'], 'goods_promotion_type' => 2), $k);
  517. continue;
  518. }
  519. // 没有促销使用原价
  520. $this->editGoodsById(array('goods_promotion_price' => Db::raw('goods_price'), 'goods_promotion_type' => 0), $k);
  521. }
  522. }
  523. return true;
  524. }
  525. /**
  526. * 更新商品数据
  527. * @access public
  528. * @author csdeshang
  529. * @param array $update 更新数据
  530. * @param array $condition 条件
  531. * @return boolean
  532. */
  533. public function editGoodsCommon($update, $condition)
  534. {
  535. $common_list = $this->getGoodsCommonList($condition, 'goods_commonid', 0);
  536. if (empty($common_list)) {
  537. return false;
  538. }
  539. $commonid_array = array();
  540. foreach ($common_list as $val) {
  541. $commonid_array[] = $val['goods_commonid'];
  542. }
  543. return $this->editGoodsCommonById($update, $commonid_array);
  544. }
  545. /**
  546. * 更新商品数据
  547. * @access public
  548. * @author csdeshang
  549. * @param array $update 更新数据
  550. * @param int|array $commonid_array 商品ID
  551. * @return boolean|unknown
  552. */
  553. public function editGoodsCommonById($update, $commonid_array)
  554. {
  555. if (empty($commonid_array)) {
  556. return true;
  557. }
  558. $result = Db::name('goodscommon')->where('goods_commonid', 'in', $commonid_array)->update($update);
  559. if ($result) {
  560. foreach ((array) $commonid_array as $val) {
  561. $this->_dGoodsCommonCache($val);
  562. }
  563. }
  564. return $result;
  565. }
  566. /**
  567. * 锁定商品
  568. * @access public
  569. * @author csdeshang
  570. * @param array $condition 条件
  571. * @return boolean
  572. */
  573. public function editGoodsCommonLock($condition)
  574. {
  575. $update = array('goods_lock' => 1);
  576. return $this->editGoodsCommon($update, $condition);
  577. }
  578. /**
  579. * 锁定商品
  580. * @access public
  581. * @author csdeshang
  582. * @param array $condition 条件
  583. * @return boolean
  584. */
  585. public function editGoodsLock($condition)
  586. {
  587. $update = array('goods_lock' => 1);
  588. return $this->editGoods($update, $condition);
  589. }
  590. /**
  591. * 解锁商品
  592. * @access public
  593. * @author csdeshang
  594. * @param array $condition 条件
  595. * @return boolean
  596. */
  597. public function editGoodsCommonUnlock($condition)
  598. {
  599. $update = array('goods_lock' => 0);
  600. return $this->editGoodsCommon($update, $condition);
  601. }
  602. /**
  603. * 解锁商品
  604. * @access public
  605. * @author csdeshang
  606. * @param array $condition 条件
  607. * @return boolean
  608. */
  609. public function editGoodsUnlock($condition)
  610. {
  611. $update = array('goods_lock' => 0);
  612. return $this->editGoods($update, $condition);
  613. }
  614. /**
  615. * 更新商品信息
  616. * @access public
  617. * @author csdeshang
  618. * @param array $condition 更新条件
  619. * @param array $update1 更新数据1
  620. * @param array $update2 更新数据2
  621. * @return boolean
  622. */
  623. public function editProduces($condition, $update1, $update2 = array())
  624. {
  625. $update2 = empty($update2) ? $update1 : $update2;
  626. $goods_array = $this->getGoodsCommonList($condition, 'goods_commonid', 0);
  627. if (empty($goods_array)) {
  628. return true;
  629. }
  630. $commonid_array = array();
  631. foreach ($goods_array as $val) {
  632. $commonid_array[] = $val['goods_commonid'];
  633. }
  634. $return1 = $this->editGoodsCommonById($update1, $commonid_array);
  635. $return2 = $this->editGoods($update2, array(array('goods_commonid', 'in', $commonid_array)));
  636. if ($return1 && $return2) {
  637. return true;
  638. } else {
  639. return false;
  640. }
  641. }
  642. /**
  643. * 更新商品信息(审核失败)
  644. * @access public
  645. * @author csdeshang
  646. * @param array $condition 条件
  647. * @param array $update1 更新数据1
  648. * @param array $update2 更新数据2
  649. * @return boolean
  650. */
  651. public function editProducesVerifyFail($condition, $update1, $update2 = array())
  652. {
  653. $result = $this->editProduces($condition, $update1, $update2);
  654. if ($result) {
  655. $commonlist = $this->getGoodsCommonList($condition, 'goods_commonid,gc_id,goods_name,store_id,goods_verifyremark', 0);
  656. foreach ($commonlist as $val) {
  657. $message = array();
  658. $message['common_id'] = $val['goods_commonid'];
  659. $message['remark'] = $val['goods_verifyremark'];
  660. $ten_message = array($message['remark'], $message['common_id']);
  661. $weixin_param = array(
  662. 'url' => config('ds_config.h5_store_site_url') . '/pages/seller/goods/GoodsForm2?commonid=' . $val['goods_commonid'] . '&class_id=' . $val['gc_id'],
  663. 'data' => array(
  664. "keyword1" => array(
  665. "value" => $val['goods_name'],
  666. "color" => "#333"
  667. ),
  668. "keyword2" => array(
  669. "value" => $val['goods_verifyremark'],
  670. "color" => "#333"
  671. )
  672. )
  673. );
  674. $this->_sendStoremsg('goods_verify', $val['store_id'], $message, $weixin_param, $message, $ten_message);
  675. }
  676. }
  677. }
  678. /**
  679. * 更新未锁定商品信息
  680. * @access public
  681. * @author csdeshang
  682. * @param array $condition 条件
  683. * @param array $update1 更新数据1
  684. * @param array $update2 更新数据2
  685. * @return boolean
  686. */
  687. public function editProducesNoLock($condition, $update1, $update2 = array())
  688. {
  689. $condition[] = array('goods_lock', '=', 0);
  690. return $this->editProduces($condition, $update1, $update2);
  691. }
  692. /**
  693. * 商品下架
  694. * @access public
  695. * @author csdeshang
  696. * @param array $condition 条件
  697. * @return boolean
  698. */
  699. public function editProducesOffline($condition)
  700. {
  701. $update['goods_state'] = self::STATE0;
  702. return $this->editProducesNoLock($condition, $update);
  703. }
  704. /**
  705. * 商品上架
  706. * @access public
  707. * @author csdeshang
  708. * @param array $condition 条件
  709. * @return boolean
  710. */
  711. public function editProducesOnline($condition)
  712. {
  713. $update = array('goods_state' => self::STATE1);
  714. // 禁售商品、审核失败商品不能上架。
  715. $condition[] = array('goods_state', '=', self::STATE0);
  716. $condition[] = array('goods_verify', '<>', self::VERIFY0);
  717. // 修改预约商品状态
  718. $update['is_appoint'] = 0;
  719. return $this->editProduces($condition, $update);
  720. }
  721. /**
  722. * 违规下架
  723. * @access public
  724. * @author csdeshang
  725. * @param array $update 数据
  726. * @param array $condition 条件
  727. * @return boolean
  728. */
  729. public function editProducesLockUp($update, $condition)
  730. {
  731. $update_param['goods_state'] = self::STATE10;
  732. $update = array_merge($update, $update_param);
  733. $return = $this->editProduces($condition, $update, $update_param);
  734. if ($return) {
  735. // 商品违规下架发送店铺消息
  736. $common_list = $this->getGoodsCommonList($condition, 'goods_commonid,gc_id,goods_name,store_id,goods_stateremark', 0);
  737. foreach ($common_list as $val) {
  738. $message = array();
  739. $message['remark'] = $val['goods_stateremark'];
  740. $message['common_id'] = $val['goods_commonid'];
  741. $ten_message = array($message['remark'], $message['common_id']);
  742. $weixin_param = array(
  743. 'url' => config('ds_config.h5_store_site_url') . '/pages/seller/goods/GoodsForm2?commonid=' . $val['goods_commonid'] . '&class_id=' . $val['gc_id'],
  744. 'data' => array(
  745. "keyword1" => array(
  746. "value" => $val['goods_name'],
  747. "color" => "#333"
  748. ),
  749. "keyword2" => array(
  750. "value" => $val['goods_stateremark'],
  751. "color" => "#333"
  752. ),
  753. "keyword3" => array(
  754. "value" => $val['goods_commonid'],
  755. "color" => "#333"
  756. )
  757. )
  758. );
  759. $this->_sendStoremsg('goods_violation', $val['store_id'], $message, $weixin_param, $message, $ten_message);
  760. }
  761. return true;
  762. } else {
  763. return false;
  764. }
  765. }
  766. /**
  767. * 获取单条商品SKU信息
  768. * @access public
  769. * @author csdeshang
  770. * @param array $condition 条件
  771. * @param string $field 字段
  772. * @return array
  773. */
  774. public function getGoodsInfo($condition, $field = '*')
  775. {
  776. $result = Db::name('goods')->field($field)->where($condition);
  777. if ($this->lock) {
  778. $result = $result->lock(true);
  779. }
  780. return $result->find();
  781. }
  782. /**
  783. * 获取单条商品SKU信息及其促销信息
  784. * @access public
  785. * @author csdeshang
  786. * @param int $goods_id 商品ID
  787. * @return type
  788. */
  789. public function getGoodsOnlineInfoForShare($goods_id)
  790. {
  791. $goods_info = $this->getGoodsOnlineInfoAndPromotionById($goods_id);
  792. if (empty($goods_info)) {
  793. return array();
  794. }
  795. //抢购
  796. if (!empty($goods_info['groupbuy_info'])) {
  797. $goods_info['promotion_type'] = '抢购';
  798. $goods_info['promotion_price'] = $goods_info['groupbuy_info']['groupbuy_price'];
  799. }
  800. if (!empty($goods_info['xianshi_info'])) {
  801. $goods_info['promotion_type'] = '秒杀';
  802. $goods_info['promotion_price'] = $goods_info['xianshi_info']['xianshigoods_price'];
  803. }
  804. return $goods_info;
  805. }
  806. /**
  807. * 查询出售中的商品详细信息及其促销信息
  808. * @access public
  809. * @author csdeshang
  810. * @param int $goods_id 商品ID
  811. * @return array
  812. */
  813. public function getGoodsOnlineInfoAndPromotionById($goods_id)
  814. {
  815. $goods_info = $this->getGoodsInfoAndPromotionById($goods_id);
  816. if (empty($goods_info) || $goods_info['goods_state'] != self::STATE1 || $goods_info['goods_verify'] != self::VERIFY1) {
  817. return array();
  818. }
  819. return $goods_info;
  820. }
  821. /**
  822. * 查询商品详细信息及其促销信息
  823. * @access public
  824. * @author csdeshang
  825. * @param int $goods_id 商品ID
  826. * @return array
  827. */
  828. public function getGoodsInfoAndPromotionById($goods_id)
  829. {
  830. $goods_info = $this->getGoodsInfoByID($goods_id);
  831. if (empty($goods_info)) {
  832. return array();
  833. }
  834. $goods_info['groupbuy_info'] = '';
  835. $goods_info['pintuan_info'] = '';
  836. $goods_info['bargain_info'] = '';
  837. $goods_info['presell_info'] = '';
  838. $goods_info['xianshi_info'] = '';
  839. $goods_info['wholesale_info'] = '';
  840. $goods_info['mgdiscount_info'] = '';
  841. //原价
  842. $goods_info['goods_original_price'] = $goods_info['goods_price'];
  843. //抢购
  844. if (config('ds_config.groupbuy_allow')) {
  845. $goods_info['groupbuy_info'] = model('groupbuy')->getGroupbuyInfoByGoodsCommonID($goods_info['goods_commonid']);
  846. }
  847. //拼团
  848. if (empty($goods_info['groupbuy_info'])) {
  849. $goods_info['pintuan_info'] = model('ppintuan')->getPintuanInfoByGoodsCommonID($goods_info['goods_commonid']);
  850. }
  851. //砍价
  852. if (empty($goods_info['bargain_info'])) {
  853. $goods_info['bargain_info'] = model('pbargain')->getBargainInfoByGoodsID($goods_info['goods_id']);
  854. }
  855. //预售
  856. if (empty($goods_info['presell_info'])) {
  857. $goods_info['presell_info'] = model('presell')->getPresellInfoByGoodsID($goods_info['goods_id']);
  858. }
  859. //批发
  860. if (config('ds_config.promotion_allow')) {
  861. $goods_info['wholesale_info'] = model('wholesalegoods')->getWholesalegoodsInfoByGoodsID($goods_info['goods_id']);
  862. }
  863. //秒杀
  864. if (empty($goods_info['groupbuy_info']) && empty($goods_info['pintuan_info'])) {
  865. if (config('ds_config.promotion_allow') && empty($goods_info['groupbuy_info'])) {
  866. $goods_info['xianshi_info'] = model('pxianshigoods')->getXianshigoodsInfoByGoodsID($goods_info['goods_id']);
  867. }
  868. }
  869. //会员等级折扣
  870. if (empty($goods_info['bargain_info']) && empty($goods_info['presell_info']) && empty($goods_info['groupbuy_info']) && empty($goods_info['pintuan_info']) && empty($goods_info['xianshi_info']) && empty($goods_info['wholesale_info'])) {
  871. if (config('ds_config.mgdiscount_allow')) {
  872. $goods_info['mgdiscount_info'] = model('pmgdiscount')->getPmgdiscountInfoByGoodsInfo($goods_info);
  873. }
  874. }
  875. return $goods_info;
  876. }
  877. /**
  878. * 查询出售中的商品列表及其促销信息
  879. * @access public
  880. * @author csdeshang
  881. * @param array $goodsid_array 商品ID数组
  882. * @return array
  883. */
  884. public function getGoodsOnlineListAndPromotionByIdArray($goodsid_array)
  885. {
  886. if (empty($goodsid_array) || !is_array($goodsid_array))
  887. return array();
  888. $goods_list = array();
  889. foreach ($goodsid_array as $goods_id) {
  890. $goods_info = $this->getGoodsOnlineInfoAndPromotionById($goods_id);
  891. if (!empty($goods_info))
  892. $goods_list[] = $goods_info;
  893. }
  894. return $goods_list;
  895. }
  896. /**
  897. * 获取单条商品信息
  898. * @access public
  899. * @author csdeshang
  900. * @param array $condition 条件
  901. * @param string $field 字段
  902. * @return array
  903. */
  904. public function getGoodsCommonInfo($condition, $field = '*')
  905. {
  906. return Db::name('goodscommon')->field($field)->where($condition)->find();
  907. }
  908. /**
  909. * 取得商品详细信息(优先查询缓存)
  910. * @access public
  911. * @author csdeshang
  912. * @param int $goods_commonid 商品ID
  913. * @return array
  914. */
  915. public function getGoodsCommonInfoByID($goods_commonid)
  916. {
  917. $common_info = $this->_rGoodsCommonCache($goods_commonid);
  918. if (empty($common_info)) {
  919. $common_info = $this->getGoodsCommonInfo(array('goods_commonid' => $goods_commonid));
  920. $this->_wGoodsCommonCache($goods_commonid, $common_info);
  921. }
  922. return $common_info;
  923. }
  924. /**
  925. * 获得商品SKU某字段的和
  926. * @access public
  927. * @author csdeshang
  928. * @param array $condition 条件
  929. * @param string $field 字段
  930. * @return boolean
  931. */
  932. public function getGoodsSum($condition, $field)
  933. {
  934. return Db::name('goods')->where($condition)->sum($field);
  935. }
  936. /**
  937. * 获得商品SKU数量
  938. * @access public
  939. * @author csdeshang
  940. * @param array $condition 条件
  941. * @return int
  942. */
  943. public function getGoodsCount($condition)
  944. {
  945. return Db::name('goods')->where($condition)->count();
  946. }
  947. /**
  948. * 获得出售中商品SKU数量
  949. * @access public
  950. * @author csdeshang
  951. * @param array $condition 条件
  952. * @param string $field 字段
  953. * @return int
  954. */
  955. public function getGoodsOnlineCount($condition, $field = '*')
  956. {
  957. $condition[] = array('goods_state', '=', self::STATE1);
  958. $condition[] = array('goods_verify', '=', self::VERIFY1);
  959. return Db::name('goods')->where($condition)->count($field);
  960. }
  961. /**
  962. * 获得商品数量
  963. * @access public
  964. * @author csdeshang
  965. * @param array $condition
  966. * @return int
  967. */
  968. public function getGoodsCommonCount($condition)
  969. {
  970. return Db::name('goodscommon')->where($condition)->count();
  971. }
  972. /**
  973. * 出售中的商品数量
  974. * @access public
  975. * @author csdeshang
  976. * @param array $condition 条件
  977. * @return int
  978. */
  979. public function getGoodsCommonOnlineCount($condition)
  980. {
  981. $condition[] = array('goods_state', '=', self::STATE1);
  982. $condition[] = array('goods_verify', '=', self::VERIFY1);
  983. return $this->getGoodsCommonCount($condition);
  984. }
  985. /**
  986. * 仓库中的商品数量
  987. * @access public
  988. * @author csdeshang
  989. * @param array $condition 条件
  990. * @return int
  991. */
  992. public function getGoodsCommonOfflineCount($condition)
  993. {
  994. $condition[] = array('goods_state', '=', self::STATE0);
  995. $condition[] = array('goods_verify', '=', self::VERIFY1);
  996. return $this->getGoodsCommonCount($condition);
  997. }
  998. /**
  999. * 等待审核的商品数量
  1000. * @access public
  1001. * @author csdeshang
  1002. * @param array $condition 条件
  1003. * @return int
  1004. */
  1005. public function getGoodsCommonWaitVerifyCount($condition)
  1006. {
  1007. $condition[] = array('goods_verify', '=', self::VERIFY10);
  1008. return $this->getGoodsCommonCount($condition);
  1009. }
  1010. /**
  1011. * 审核失败的商品数量
  1012. * @access public
  1013. * @author csdeshang
  1014. * @param array $condition 条件
  1015. * @return int
  1016. */
  1017. public function getGoodsCommonVerifyFailCount($condition)
  1018. {
  1019. $condition[] = array('goods_verify', '=', self::VERIFY0);
  1020. return $this->getGoodsCommonCount($condition);
  1021. }
  1022. /**
  1023. * 违规下架的商品数量
  1024. * @access public
  1025. * @author csdeshang
  1026. * @param array $condition 条件
  1027. * @return int
  1028. */
  1029. public function getGoodsCommonLockUpCount($condition)
  1030. {
  1031. $condition[] = array('goods_state', '=', self::STATE10);
  1032. $condition[] = array('goods_verify', '=', self::VERIFY1);
  1033. return $this->getGoodsCommonCount($condition);
  1034. }
  1035. /**
  1036. * 商品图片列表
  1037. * @access public
  1038. * @author csdeshang
  1039. * @param array $condition 条件
  1040. * @param array $order 字段
  1041. * @param string $field 排序
  1042. * @return array
  1043. */
  1044. public function getGoodsImageList($condition, $field = '*', $order = 'goodsimage_isdefault desc,goodsimage_sort asc')
  1045. {
  1046. return Db::name('goodsimages')->field($field)->where($condition)->order($order)->select()->toArray();
  1047. }
  1048. /**
  1049. * 商品视频列表
  1050. * @access public
  1051. * @author csdeshang
  1052. * @param array $condition 条件
  1053. * @param array $order 字段
  1054. * @param string $field 排序
  1055. * @return array
  1056. */
  1057. public function getGoodsVideoList($condition, $field = '*', $order = 'goodsvideo_id desc', $limit = 0, $pagesize = 0)
  1058. {
  1059. if ($pagesize) {
  1060. $result = Db::name('goodsvideo')->field($field)->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  1061. $this->page_info = $result;
  1062. return $result->items();
  1063. } else {
  1064. return Db::name('goodsvideo')->field($field)->where($condition)->order($order)->limit($limit)->select()->toArray();
  1065. }
  1066. }
  1067. /**
  1068. * 删除商品SKU信息
  1069. * @access public
  1070. * @author csdeshang
  1071. * @param array $condition 条件
  1072. * @return boolean
  1073. */
  1074. public function delGoods($condition)
  1075. {
  1076. $goods_list = $this->getGoodsList($condition, 'goods_id,goods_commonid,store_id');
  1077. if (!empty($goods_list)) {
  1078. $goodsid_array = array();
  1079. // 删除商品二维码
  1080. foreach ($goods_list as $val) {
  1081. $goodsid_array[] = $val['goods_id'];
  1082. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_STORE . DIRECTORY_SEPARATOR . $val['store_id'] . DIRECTORY_SEPARATOR . $val['goods_id'] . '.png');
  1083. // 删除商品缓存
  1084. $this->_dGoodsCache($val['goods_id']);
  1085. // 删除商品规格缓存
  1086. $this->_dGoodsSpecCache($val['goods_commonid']);
  1087. }
  1088. // 删除属性关联表数据
  1089. Db::name('goodsattrindex')->where('goods_id', 'in', $goodsid_array)->delete();
  1090. // 删除优惠套装商品
  1091. model('pbundling')->delBundlingGoods(array(array('goods_id', 'in', $goodsid_array)));
  1092. // 优惠套餐活动下架
  1093. model('pbundling')->editBundlingCloseByGoodsIds(array(array('goods_id', 'in', $goodsid_array)));
  1094. // 推荐展位商品
  1095. model('pbooth')->delBoothgoods(array(array('goods_id', 'in', $goodsid_array)));
  1096. // 秒杀
  1097. model('pxianshigoods')->delXianshigoods(array(array('goods_id', 'in', $goodsid_array)));
  1098. // 预售
  1099. model('presell')->delPresell(array(array('goods_id', 'in', $goodsid_array)));
  1100. // 批发
  1101. model('wholesalegoods')->delWholesalegoods(array(array('goods_id', 'in', $goodsid_array)));
  1102. //删除商品浏览记录
  1103. model('goodsbrowse')->delGoodsbrowse(array(array('goods_id', 'in', $goodsid_array)));
  1104. // 删除买家收藏表数据
  1105. $condition_fav = array();
  1106. $condition_fav[] = array('fav_id', 'in', $goodsid_array);
  1107. $condition_fav[] = array('fav_type', '=', 'goods');
  1108. model('favorites')->delFavorites($condition_fav);
  1109. // 删除商品赠品
  1110. model('goodsgift')->delGoodsgift(array(array('goods_id', 'in', $goodsid_array)));
  1111. model('goodsgift')->delGoodsgift(array(array('gift_goodsid', 'in', $goodsid_array)));
  1112. // 删除推荐组合
  1113. model('goodscombo')->delGoodscombo(array(array('goods_id', 'in', $goodsid_array)));
  1114. model('goodscombo')->delGoodscombo(array(array('combo_goodsid', 'in', $goodsid_array)));
  1115. }
  1116. return Db::name('goods')->where($condition)->delete();
  1117. }
  1118. /**
  1119. * 编辑商品图片表信息
  1120. * @access public
  1121. * @author csdeshang
  1122. * @param array $condition 条件
  1123. * @return boolean
  1124. */
  1125. public function editGoodsImages($update, $condition)
  1126. {
  1127. $result = Db::name('goodsimages')->where($condition)->update($update);
  1128. return $result;
  1129. }
  1130. /**
  1131. * 删除商品图片表信息
  1132. * @access public
  1133. * @author csdeshang
  1134. * @param array $condition 条件
  1135. * @return boolean
  1136. */
  1137. public function delGoodsImages($condition)
  1138. {
  1139. $image_list = $this->getGoodsImageList($condition, 'goods_commonid,color_id');
  1140. if (empty($image_list)) {
  1141. return true;
  1142. }
  1143. $result = Db::name('goodsimages')->where($condition)->delete();
  1144. if ($result) {
  1145. foreach ($image_list as $val) {
  1146. $this->_dGoodsImageCache($val['goods_commonid'] . '|' . $val['color_id']);
  1147. }
  1148. }
  1149. return $result;
  1150. }
  1151. /**
  1152. * 新增商品视频表信息
  1153. * @access public
  1154. * @author csdeshang
  1155. * @param array $data 条件
  1156. * @return boolean
  1157. */
  1158. public function addGoodsVideo($data)
  1159. {
  1160. $result = Db::name('goodsvideo')->insertGetId($data);
  1161. return $result;
  1162. }
  1163. /**
  1164. * 删除商品视频表信息
  1165. * @access public
  1166. * @author csdeshang
  1167. * @param array $condition 条件
  1168. * @return boolean
  1169. */
  1170. public function delGoodsVideo($condition)
  1171. {
  1172. $goodsvideo_list = $this->getGoodsVideoList($condition);
  1173. foreach ($goodsvideo_list as $val) {
  1174. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_STORE . DIRECTORY_SEPARATOR . $val['store_id'] . DIRECTORY_SEPARATOR . $val['goodsvideo_name']);
  1175. }
  1176. $result = Db::name('goodsvideo')->where($condition)->delete();
  1177. return $result;
  1178. }
  1179. /**
  1180. * 商品删除及相关信息
  1181. * @access public
  1182. * @author csdeshang
  1183. * @param array $condition 列表条件
  1184. * @return boolean
  1185. */
  1186. public function delGoodsAll($condition)
  1187. {
  1188. $goods_list = $this->getGoodsList($condition, 'goods_id,goods_commonid,store_id');
  1189. if (empty($goods_list)) {
  1190. return false;
  1191. }
  1192. $goodsid_array = array();
  1193. $commonid_array = array();
  1194. foreach ($goods_list as $val) {
  1195. $goodsid_array[] = $val['goods_id'];
  1196. $commonid_array[] = $val['goods_commonid'];
  1197. // 商品公共缓存
  1198. $this->_dGoodsCommonCache($val['goods_commonid']);
  1199. // 商品规格缓存
  1200. $this->_dGoodsSpecCache($val['goods_commonid']);
  1201. }
  1202. $commonid_array = array_unique($commonid_array);
  1203. // 删除商品表数据
  1204. $this->delGoods(array(array('goods_id', 'in', $goodsid_array)));
  1205. // 删除商品公共表数据
  1206. Db::name('goodscommon')->where('goods_commonid', 'in', $commonid_array)->delete();
  1207. // 删除商品图片表数据
  1208. $this->delGoodsImages(array(array('goods_commonid', 'in', $commonid_array)));
  1209. // 删除商品F码
  1210. model('goodsfcode')->delGoodsfcode(array(array('goods_commonid', 'in', $commonid_array)));
  1211. return true;
  1212. }
  1213. /**删除未锁定商品
  1214. * @access public
  1215. * @author csdeshang
  1216. * @param array $condition 条件
  1217. * @return type
  1218. */
  1219. public function delGoodsNoLock($condition)
  1220. {
  1221. $condition[] = array('goods_lock', '=', 0);
  1222. $common_array = $this->getGoodsCommonList($condition, 'goods_commonid', 0);
  1223. $common_array = array_under_reset($common_array, 'goods_commonid');
  1224. $commonid_array = array_keys($common_array);
  1225. return $this->delGoodsAll(array(array('goods_commonid', 'in', $commonid_array)));
  1226. }
  1227. /**
  1228. * 发送店铺消息
  1229. * @access public
  1230. * @author csdeshang
  1231. * @param string $code 编码
  1232. * @param int $store_id 店铺OD
  1233. * @param array $param 参数
  1234. */
  1235. private function _sendStoremsg($code, $store_id, $param, $weixin_param = array(), $ali_param = array(), $ten_param = array())
  1236. {
  1237. model('cron')->addCron(array('cron_exetime' => TIMESTAMP, 'cron_type' => 'sendStoremsg', 'cron_value' => serialize(array('code' => $code, 'store_id' => $store_id, 'param' => $param, 'weixin_param' => $weixin_param, 'ali_param' => $ali_param, 'ten_param' => $ten_param))));
  1238. }
  1239. /**
  1240. * 获得商品子分类的ID
  1241. * @access public
  1242. * @author csdeshang
  1243. * @param array $condition 条件
  1244. * @return array
  1245. */
  1246. public function _getRecursiveClass($condition, $gc_id, $prefix = '')
  1247. {
  1248. if (!is_array($gc_id)) {
  1249. $gc_list = model('goodsclass')->getGoodsclassForCacheModel();
  1250. if (!empty($gc_list[$gc_id])) {
  1251. $all_gc_id = array($gc_id);
  1252. $gcchild_id = empty($gc_list[$gc_id]['child']) ? array() : explode(',', $gc_list[$gc_id]['child']);
  1253. $gcchildchild_id = empty($gc_list[$gc_id]['childchild']) ? array() : explode(',', $gc_list[$gc_id]['childchild']);
  1254. $all_gc_id = array_merge($all_gc_id, $gcchild_id, $gcchildchild_id);
  1255. if ($prefix) {
  1256. $prefix = $prefix . '.';
  1257. }
  1258. $condition[] = array($prefix . 'gc_id', 'in', implode(',', $all_gc_id));
  1259. }
  1260. }
  1261. return $condition;
  1262. }
  1263. /**
  1264. * 由ID取得在售单个虚拟商品信息
  1265. * @access public
  1266. * @author csdeshang
  1267. * @param array $goods_id 商品ID
  1268. * @return array
  1269. */
  1270. public function getVirtualGoodsOnlineInfoByID($goods_id)
  1271. {
  1272. $goods_info = $this->getGoodsInfoByID($goods_id);
  1273. return $goods_info['is_virtual'] == 1 && $goods_info['virtual_indate'] >= TIMESTAMP ? $goods_info : array();
  1274. }
  1275. /**
  1276. * 取得商品详细信息(优先查询缓存)(在售)
  1277. * 如果未找到,则缓存所有字段
  1278. * @access public
  1279. * @author csdeshang
  1280. * @param int $goods_id 商品ID
  1281. * @return array
  1282. */
  1283. public function getGoodsOnlineInfoByID($goods_id)
  1284. {
  1285. $goods_info = $this->getGoodsInfoByID($goods_id);
  1286. if ($goods_info['goods_state'] != self::STATE1 || $goods_info['goods_verify'] != self::VERIFY1) {
  1287. $goods_info = array();
  1288. }
  1289. return $goods_info;
  1290. }
  1291. /**
  1292. * 取得商品详细信息(优先查询缓存)
  1293. * 如果未找到,则缓存所有字段
  1294. * @access public
  1295. * @author csdeshang
  1296. * @param int $goods_id 商品ID
  1297. * @return array
  1298. */
  1299. public function getGoodsInfoByID($goods_id)
  1300. {
  1301. $goods_info = $this->_rGoodsCache($goods_id);
  1302. if (empty($goods_info) || $this->lock) {
  1303. $goods_info = $this->getGoodsInfo(array('goods_id' => $goods_id));
  1304. $this->_wGoodsCache($goods_id, $goods_info);
  1305. }
  1306. return $goods_info;
  1307. }
  1308. /**
  1309. * 验证是否为普通商品
  1310. * @access public
  1311. * @author csdeshang
  1312. * @param array $goods 商品数组
  1313. * @return boolean
  1314. */
  1315. public function checkIsGeneral($goods)
  1316. {
  1317. if ($goods['is_virtual'] == 1 || $goods['is_goodsfcode'] == 1) {
  1318. return false;
  1319. }
  1320. return true;
  1321. }
  1322. /**
  1323. * 验证是否允许送赠品
  1324. * @access public
  1325. * @author csdeshang
  1326. * @param type $goods 商品
  1327. * @return boolean
  1328. */
  1329. public function checkGoodsIfAllowGift($goods)
  1330. {
  1331. if ($goods['is_virtual'] == 1) {
  1332. return false;
  1333. }
  1334. return true;
  1335. }
  1336. /**
  1337. * 验证是否允许关联套餐
  1338. * @access public
  1339. * @author csdeshang
  1340. * @param type $goods 商品
  1341. * @return boolean
  1342. */
  1343. public function checkGoodsIfAllowCombo($goods)
  1344. {
  1345. if ($goods['is_virtual'] == 1 || $goods['is_goodsfcode'] == 1 || $goods['is_appoint'] == 1) {
  1346. return false;
  1347. }
  1348. return true;
  1349. }
  1350. /**
  1351. * 获得有库存的商品
  1352. * @access public
  1353. * @author csdeshang
  1354. * @param type $common_id ID编号
  1355. * @return type
  1356. */
  1357. public function getGoodsStorageByCommonId($common_id)
  1358. {
  1359. $condition = array();
  1360. $condition[] = array('goods_state', '=', self::STATE1);
  1361. $condition[] = array('goods_verify', '=', self::VERIFY1);
  1362. $condition[] = array('goods_commonid', '=', $common_id);
  1363. $condition[] = array('goods_storage', '>', 0);
  1364. $goods_info = $this->getGoodsInfo($condition);
  1365. return $goods_info;
  1366. }
  1367. /**
  1368. * 获得商品规格数组
  1369. * @access public
  1370. * @author csdeshang
  1371. * @param type $common_id ID编号
  1372. * @return type
  1373. */
  1374. public function getGoodsSpecListByCommonId($common_id)
  1375. {
  1376. $spec_list = $this->_rGoodsSpecCache($common_id);
  1377. if (empty($spec_list)) {
  1378. $spec_array = $this->getGoodsList(array('goods_commonid' => $common_id), 'goods_spec,goods_id,store_id,goods_image,color_id,goods_storage,virtual_content');
  1379. $spec_list['spec'] = serialize($spec_array);
  1380. $this->_wGoodsSpecCache($common_id, $spec_list);
  1381. }
  1382. $spec_array = unserialize($spec_list['spec']);
  1383. return $spec_array;
  1384. }
  1385. /**
  1386. * 获得商品图片数组
  1387. * @access public
  1388. * @author csdeshang
  1389. * @param type $key 键值
  1390. * @return type
  1391. */
  1392. public function getGoodsImageByKey($key)
  1393. {
  1394. $image_list = $this->_rGoodsImageCache($key);
  1395. if (empty($image_list)) {
  1396. $array = explode('|', $key);
  1397. list($common_id, $color_id) = $array;
  1398. $image_more = $this->getGoodsImageList(array('goods_commonid' => $common_id, 'color_id' => $color_id), 'goodsimage_url');
  1399. $image_list['image'] = serialize($image_more);
  1400. $this->_wGoodsImageCache($key, $image_list);
  1401. }
  1402. $image_more = unserialize($image_list['image']);
  1403. return $image_more;
  1404. }
  1405. /**
  1406. * 读取商品缓存
  1407. * @access public
  1408. * @author csdeshang
  1409. * @param type $goods_id 商品id
  1410. * @return type
  1411. */
  1412. private function _rGoodsCache($goods_id)
  1413. {
  1414. return rcache($goods_id, 'goods');
  1415. }
  1416. /**
  1417. * 写入商品缓存
  1418. * @access public
  1419. * @author csdeshang
  1420. * @param int $goods_id 商品id
  1421. * @param array $goods_info 商品信息
  1422. * @return boolean
  1423. */
  1424. private function _wGoodsCache($goods_id, $goods_info)
  1425. {
  1426. return wcache($goods_id, $goods_info, 'goods');
  1427. }
  1428. /**
  1429. * 删除商品缓存
  1430. * @access public
  1431. * @author csdeshang
  1432. * @param int $goods_id 商品id
  1433. * @return boolean
  1434. */
  1435. private function _dGoodsCache($goods_id)
  1436. {
  1437. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_TAOBAO . DIRECTORY_SEPARATOR . 'goods_csv_' . $goods_id . '.zip');
  1438. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_TAOBAO . DIRECTORY_SEPARATOR . 'goods_image_' . $goods_id . '.zip');
  1439. return dcache($goods_id, 'goods');
  1440. }
  1441. /**
  1442. * 读取商品公共缓存
  1443. * @access public
  1444. * @author csdeshang
  1445. * @param int $goods_commonid 商品id
  1446. * @return array
  1447. */
  1448. private function _rGoodsCommonCache($goods_commonid)
  1449. {
  1450. return rcache($goods_commonid, 'goodscommon');
  1451. }
  1452. /**
  1453. * 写入商品公共缓存
  1454. * @access public
  1455. * @author csdeshang
  1456. * @param int $goods_commonid 商品ID
  1457. * @param array $common_info 商品信息
  1458. * @return boolean
  1459. */
  1460. private function _wGoodsCommonCache($goods_commonid, $common_info)
  1461. {
  1462. return wcache($goods_commonid, $common_info, 'goodscommon');
  1463. }
  1464. /**
  1465. * 删除商品公共缓存
  1466. * @access public
  1467. * @author csdeshang
  1468. * @param int $goods_commonid 商品ID
  1469. * @return boolean
  1470. */
  1471. private function _dGoodsCommonCache($goods_commonid)
  1472. {
  1473. return dcache($goods_commonid, 'goodscommon');
  1474. }
  1475. /**
  1476. * 读取商品规格缓存
  1477. * @access public
  1478. * @author csdeshang
  1479. * @param int $goods_commonid 商品id
  1480. * @return array
  1481. */
  1482. private function _rGoodsSpecCache($goods_commonid)
  1483. {
  1484. return rcache($goods_commonid, 'goods_spec');
  1485. }
  1486. /**
  1487. * 写入商品规格缓存
  1488. * @access public
  1489. * @author csdeshang
  1490. * @param int $goods_commonid 商品id
  1491. * @param array $spec_list 规格列表
  1492. * @return boolean
  1493. */
  1494. private function _wGoodsSpecCache($goods_commonid, $spec_list)
  1495. {
  1496. return wcache($goods_commonid, $spec_list, 'goods_spec');
  1497. }
  1498. /**
  1499. * 删除商品规格缓存
  1500. * @access public
  1501. * @author csdeshang
  1502. * @param int $goods_commonid 商品id
  1503. * @return boolean
  1504. */
  1505. private function _dGoodsSpecCache($goods_commonid)
  1506. {
  1507. return dcache($goods_commonid, 'goods_spec');
  1508. }
  1509. /**
  1510. * 读取商品图片缓存
  1511. * @access public
  1512. * @author csdeshang
  1513. * @param int $key ($goods_commonid .'|'. $color_id)
  1514. * @return array
  1515. */
  1516. private function _rGoodsImageCache($key)
  1517. {
  1518. return rcache($key, 'goods_image');
  1519. }
  1520. /**
  1521. * 写入商品图片缓存
  1522. * @access public
  1523. * @author csdeshang
  1524. * @param int $key ($goods_commonid .'|'. $color_id)
  1525. * @param array $image_list 图片列表
  1526. * @return boolean
  1527. */
  1528. private function _wGoodsImageCache($key, $image_list)
  1529. {
  1530. return wcache($key, $image_list, 'goods_image');
  1531. }
  1532. /**
  1533. * 删除商品图片缓存
  1534. * @access public
  1535. * @author csdeshang
  1536. * @param int $key ($goods_commonid .'|'. $color_id)
  1537. * @return boolean
  1538. */
  1539. private function _dGoodsImageCache($key)
  1540. {
  1541. return dcache($key, 'goods_image');
  1542. }
  1543. /**
  1544. * 获取单条商品信息
  1545. * @access public
  1546. * @author csdeshang
  1547. * @param int $goods_id 商品ID
  1548. * @return array
  1549. */
  1550. public function getGoodsDetail($goods_id)
  1551. {
  1552. if ($goods_id <= 0) {
  1553. return null;
  1554. }
  1555. $result1 = $this->getGoodsInfoAndPromotionById($goods_id);
  1556. if (empty($result1)) {
  1557. return null;
  1558. }
  1559. $result2 = $this->getGoodsCommonInfoByID($result1['goods_commonid']);
  1560. $goods_info = array_merge($result2, $result1);
  1561. $goods_info['spec_value'] = unserialize($goods_info['spec_value']);
  1562. $goods_info['spec_name'] = unserialize($goods_info['spec_name']);
  1563. $goods_info['goods_spec'] = unserialize($goods_info['goods_spec']);
  1564. $goods_info['goods_attr'] = unserialize($goods_info['goods_attr']);
  1565. // 手机商品描述
  1566. if ($goods_info['mobile_body'] != '') {
  1567. $mobile_body_array = unserialize($goods_info['mobile_body']);
  1568. if (is_array($mobile_body_array)) {
  1569. $mobile_body = '';
  1570. foreach ($mobile_body_array as $val) {
  1571. switch ($val['type']) {
  1572. case 'text':
  1573. $mobile_body .= '<div>' . $val['value'] . '</div>';
  1574. break;
  1575. case 'image':
  1576. $mobile_body .= '<img src="' . $val['value'] . '">';
  1577. break;
  1578. }
  1579. }
  1580. $goods_info['mobile_body'] = $mobile_body;
  1581. }
  1582. }
  1583. // 查询所有规格商品
  1584. $spec_array = $this->getGoodsSpecListByCommonId($goods_info['goods_commonid']);
  1585. $spec_list = array(); // 各规格商品地址,js使用
  1586. $spec_list_mobile = array(); // 各规格商品地址,js使用
  1587. $spec_image = array(); // 各规格商品主图,规格颜色图片使用
  1588. foreach ($spec_array as $key => $value) {
  1589. $s_array = unserialize($value['goods_spec']);
  1590. $tmp_array = array();
  1591. if (!empty($s_array) && is_array($s_array)) {
  1592. foreach ($s_array as $k => $v) {
  1593. $tmp_array[] = $k;
  1594. }
  1595. }
  1596. sort($tmp_array);
  1597. $spec_sign = implode('|', $tmp_array);
  1598. $tpl_spec = array();
  1599. $tpl_spec['stock'] = $value['goods_storage'];
  1600. $tpl_spec['sign'] = $spec_sign;
  1601. $tpl_spec['url'] = (string)url('home/Goods/index', ['goods_id' => $value['goods_id']]);
  1602. $spec_list[] = $tpl_spec;
  1603. $spec_list_mobile[$spec_sign] = $value['goods_id'];
  1604. $spec_image[$value['color_id']] = goods_thumb($value, 240);
  1605. }
  1606. $spec_list = json_encode($spec_list);
  1607. // 商品多图
  1608. $image_more = $this->getGoodsImageByKey($goods_info['goods_commonid'] . '|' . $goods_info['color_id']);
  1609. $goods_image = array();
  1610. $goods_image_mobile = array();
  1611. if (!empty($image_more)) {
  1612. foreach ($image_more as $val) {
  1613. $goods_image[] = array(goods_cthumb($val['goodsimage_url'], 240, $goods_info['store_id']), goods_cthumb($val['goodsimage_url'], 480, $goods_info['store_id']), goods_cthumb($val['goodsimage_url'], 1280, $goods_info['store_id']));
  1614. $goods_image_mobile[] = goods_cthumb($val['goodsimage_url'], 480, $goods_info['store_id']);
  1615. }
  1616. } else {
  1617. $goods_image[] = array(goods_thumb($goods_info, 240), goods_thumb($goods_info, 480), goods_thumb($goods_info, 1280));
  1618. $goods_image_mobile[] = goods_thumb($goods_info, 480);
  1619. }
  1620. //抢购
  1621. if (!empty($goods_info['groupbuy_info'])) {
  1622. $goods_info['promotion_type'] = 'groupbuy';
  1623. $goods_info['title'] = '抢购';
  1624. $goods_info['remark'] = $goods_info['groupbuy_info']['groupbuy_remark'];
  1625. $goods_info['promotion_price'] = $goods_info['groupbuy_info']['groupbuy_price'];
  1626. $goods_info['down_price'] = ds_price_format($goods_info['goods_price'] - $goods_info['groupbuy_info']['groupbuy_price']);
  1627. $goods_info['upper_limit'] = $goods_info['groupbuy_info']['groupbuy_upper_limit'];
  1628. $goods_info['promotion_end_time'] = $goods_info['groupbuy_info']['groupbuy_endtime'];
  1629. unset($goods_info['groupbuy_info']);
  1630. }
  1631. //秒杀
  1632. if (!empty($goods_info['xianshi_info'])) {
  1633. $goods_info['promotion_type'] = 'xianshi';
  1634. $goods_info['title'] = $goods_info['xianshi_info']['xianshi_title'];
  1635. $goods_info['remark'] = $goods_info['xianshi_info']['xianshi_title'];
  1636. $goods_info['promotion_price'] = $goods_info['xianshi_info']['xianshigoods_price'];
  1637. $goods_info['down_price'] = ds_price_format($goods_info['goods_price'] - $goods_info['xianshi_info']['xianshigoods_price']);
  1638. $goods_info['lower_limit'] = $goods_info['xianshi_info']['xianshigoods_lower_limit'];
  1639. $goods_info['explain'] = $goods_info['xianshi_info']['xianshi_explain'];
  1640. $goods_info['promotion_end_time'] = $goods_info['xianshi_info']['xianshigoods_end_time'];
  1641. unset($goods_info['xianshi_info']);
  1642. }
  1643. //预售
  1644. if (!empty($goods_info['presell_info'])) {
  1645. $goods_info['promotion_type'] = 'presell';
  1646. $goods_info['title'] = '预售';
  1647. $goods_info['remark'] = $goods_info['presell_info']['presell_type'] == 1 ? (date('Y-m-d', $goods_info['presell_info']['presell_shipping_time']) . '发货') : ('第一阶段支付' . $goods_info['presell_info']['presell_deposit_amount'] . '元定金,第二阶段' . date('Y-m-d', $goods_info['presell_info']['presell_end_time'] + 72 * 3600) . '前支付' . ds_price_format($goods_info['presell_info']['presell_price'] - $goods_info['presell_info']['presell_deposit_amount']) . '元尾款');
  1648. $goods_info['promotion_price'] = $goods_info['presell_info']['presell_price'];
  1649. $goods_info['down_price'] = ds_price_format($goods_info['goods_price'] - $goods_info['presell_info']['presell_price']);
  1650. $goods_info['presell_start_time'] = $goods_info['presell_info']['presell_start_time'];
  1651. $goods_info['presell_end_time'] = $goods_info['presell_info']['presell_end_time'];
  1652. $goods_info['presell_shipping_time'] = $goods_info['presell_info']['presell_shipping_time'];
  1653. $goods_info['presell_type'] = $goods_info['presell_info']['presell_type'];
  1654. $goods_info['presell_deposit_amount'] = $goods_info['presell_info']['presell_deposit_amount'];
  1655. $goods_info['promotion_end_time'] = $goods_info['presell_info']['presell_end_time'];
  1656. unset($goods_info['presell_info']);
  1657. }
  1658. //批发
  1659. //拼团
  1660. if (!empty($goods_info['pintuan_info'])) {
  1661. $goods_info['pintuan_type'] = 'pintuan';
  1662. $goods_info['pintuan_id'] = $goods_info['pintuan_info']['pintuan_id'];
  1663. $goods_info['pintuan_title'] = $goods_info['pintuan_info']['pintuan_name'];
  1664. $goods_info['pintuan_price'] = round($goods_info['pintuan_info']['pintuan_zhe'] * $goods_info['goods_price'] / 10, 2);
  1665. $goods_info['pintuan_limit_number'] = $goods_info['pintuan_info']['pintuan_limit_number'];
  1666. $goods_info['pintuan_limit_hour'] = $goods_info['pintuan_info']['pintuan_limit_hour'];
  1667. $goods_info['pintuan_limit_quantity'] = $goods_info['pintuan_info']['pintuan_limit_quantity'];
  1668. $goods_info['pintuan_end_time'] = $goods_info['pintuan_info']['pintuan_end_time'];
  1669. //拼团开团信息
  1670. $goods_info['pintuangroup_list'] = $goods_info['pintuan_info']['pintuangroup_list'];
  1671. $goods_info['pintuangroup_count'] = count($goods_info['pintuangroup_list']);
  1672. unset($goods_info['pintuan_info']);
  1673. }
  1674. //会员等级折扣
  1675. if (!empty($goods_info['mgdiscount_info'])) {
  1676. $goods_info['mgdiscount_type'] = 'mgdiscount';
  1677. $goods_info['goods_mgdiscount_arr'] = $goods_info['mgdiscount_info'];
  1678. unset($goods_info['mgdiscount_info']);
  1679. }
  1680. // 验证是否允许送赠品
  1681. $gift_array = array();
  1682. if ($this->checkGoodsIfAllowGift($goods_info)) {
  1683. $gift_array = model('goodsgift')->getGoodsgiftListByGoodsId($goods_id);
  1684. if (!empty($gift_array)) {
  1685. $goods_info['is_have_gift'] = 'gift';
  1686. }
  1687. }
  1688. // 加入购物车按钮
  1689. $goods_info['cart'] = true;
  1690. //虚拟、F码、预售不显示加入购物车
  1691. if ($goods_info['is_virtual'] == 1 || $goods_info['is_goodsfcode'] == 1 || (isset($goods_info['promotion_type']) && $goods_info['promotion_type'] == 'presell')) {
  1692. $goods_info['cart'] = false;
  1693. }
  1694. // 立即购买文字显示
  1695. $goods_info['buynow_text'] = '立即购买';
  1696. if ($goods_info['is_goodsfcode'] == 1) {
  1697. $goods_info['buynow_text'] = 'F码购买';
  1698. }
  1699. if (isset($goods_info['promotion_type']) && $goods_info['promotion_type'] == 'presell') {
  1700. $goods_info['buynow_text'] = '预售购买';
  1701. }
  1702. $mansong_info = model('pmansong')->getMansongInfoByStoreID($goods_info['store_id']);
  1703. if (empty($mansong_info)) {
  1704. $mansong_info = array();
  1705. }
  1706. //满即送
  1707. $mansong_info = ($goods_info['is_virtual'] == 1) ? array() : $mansong_info;
  1708. // 商品受关注次数加1
  1709. $goods_info['goods_click'] = intval($goods_info['goods_click']) + 1;
  1710. if (config('ds_config.cache_open')) {
  1711. wcache('updateRedisDate', array($goods_id => $goods_info['goods_click']), 'goodsClick');
  1712. } else {
  1713. Db::name('goods')->where('goods_id', $goods_id)->inc('goods_click')->update();
  1714. }
  1715. $result = array();
  1716. $result['goods_info'] = $goods_info;
  1717. $result['spec_list'] = $spec_list;
  1718. $result['spec_list_mobile'] = $spec_list_mobile;
  1719. $result['spec_image'] = $spec_image;
  1720. $result['goods_image'] = $goods_image;
  1721. $result['goods_image_mobile'] = $goods_image_mobile;
  1722. $result['mansong_info'] = $mansong_info;
  1723. $result['gift_array'] = $gift_array;
  1724. return $result;
  1725. }
  1726. /**
  1727. * 获取移动端商品
  1728. * @access public
  1729. * @author csdeshang
  1730. * @param type $goods_commonid 商品ID
  1731. * @return array
  1732. */
  1733. public function getMobileBodyByCommonID($goods_commonid)
  1734. {
  1735. $common_info = $this->_rGoodsCommonCache($goods_commonid);
  1736. if (empty($common_info)) {
  1737. $common_info = $this->getGoodsCommonInfo(array('goods_commonid' => $goods_commonid));
  1738. $this->_wGoodsCommonCache($goods_commonid, $common_info);
  1739. }
  1740. // 手机商品描述
  1741. if ($common_info['mobile_body'] != '') {
  1742. $mobile_body_array = unserialize($common_info['mobile_body']);
  1743. if (is_array($mobile_body_array)) {
  1744. $mobile_body = '';
  1745. foreach ($mobile_body_array as $val) {
  1746. switch ($val['type']) {
  1747. case 'text':
  1748. $mobile_body .= '<div>' . $val['value'] . '</div>';
  1749. break;
  1750. case 'image':
  1751. $mobile_body .= '<img src="' . $val['value'] . '">';
  1752. break;
  1753. }
  1754. }
  1755. $common_info['mobile_body'] = $mobile_body;
  1756. }
  1757. }
  1758. return $common_info;
  1759. }
  1760. /**
  1761. * 下单变更库存销量
  1762. * @param unknown $goods_buy_quantity
  1763. */
  1764. public function createOrderUpdateStorage($goods_buy_quantity, $if_unlimited = false)
  1765. {
  1766. foreach ($goods_buy_quantity as $goods_id => $quantity) {
  1767. $data = array();
  1768. if (!$if_unlimited) {
  1769. $data['goods_storage'] = Db::raw('goods_storage-' . $quantity);
  1770. }
  1771. $data['goods_salenum'] = Db::raw('goods_salenum+' . $quantity);
  1772. $condition = array();
  1773. $condition[] = array('goods_id', '=', $goods_id);
  1774. $condition[] = array('goods_storage', '>', 0);
  1775. $result = $this->editGoods($data, $condition);
  1776. if (!$result) {
  1777. break;
  1778. }
  1779. }
  1780. if (!$result) {
  1781. return ds_callback(false, '变更商品库存与销量失败');
  1782. } else {
  1783. return ds_callback(true);
  1784. }
  1785. }
  1786. /**
  1787. * 取消订单变更库存销量
  1788. * @param unknown $goods_buy_quantity
  1789. */
  1790. public function cancelOrderUpdateStorage($goods_buy_quantity, $if_unlimited = false)
  1791. {
  1792. foreach ($goods_buy_quantity as $goods_id => $quantity) {
  1793. $data = array();
  1794. if (!$if_unlimited) {
  1795. $data['goods_storage'] = Db::raw('goods_storage+' . $quantity);
  1796. }
  1797. $data['goods_salenum'] = Db::raw('goods_salenum-' . $quantity);
  1798. $result = $this->editGoodsById($data, $goods_id);
  1799. if (!$result) {
  1800. return ds_callback(false, '变更商品库存与销量失败');
  1801. }
  1802. }
  1803. return ds_callback(true);
  1804. }
  1805. /**
  1806. * 获取卡券商品的库存
  1807. * @param type $goods_id
  1808. */
  1809. public function getAvailableGoodsCard($goods_info)
  1810. {
  1811. if ($goods_info['virtual_content']) {
  1812. $card_list = explode("\r\n", $goods_info['virtual_content']);
  1813. $like_card_list = array();
  1814. foreach ($card_list as $val) {
  1815. $like_card_list[] = '%' . $val . '%';
  1816. }
  1817. $condition = array();
  1818. $condition[] = array('goods_id', '=', $goods_info['goods_id']);
  1819. $condition[] = array('virtual_content', 'like', $like_card_list, 'OR');
  1820. $condition[] = array('order_state', 'in', [ORDER_STATE_NEW, ORDER_STATE_PAY, ORDER_STATE_SUCCESS]);
  1821. $temp = Db::name('vrorder')->where($condition)->column('virtual_content');
  1822. $used_card_list = array();
  1823. foreach ($temp as $val) {
  1824. $used_card_list = array_merge($used_card_list, explode('\r\n', $val));
  1825. }
  1826. $card_list = array_diff($card_list, $used_card_list);
  1827. return ds_callback(true, '', array('card_list' => array_values($card_list), 'card_num' => count($card_list)));
  1828. } else {
  1829. return ds_callback(true, '', array('card_list' => array(), 'card_num' => 0));
  1830. }
  1831. }
  1832. }