Goods.php 72 KB

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