Goods.php 71 KB

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