Goods.php 71 KB

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