Store.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. <?php
  2. /**
  3. * 店铺设置
  4. *
  5. */
  6. namespace app\common\model;
  7. use app\common\model\Storedepositlog;
  8. use think\facade\Db;
  9. /**
  10. * ============================================================================
  11. *
  12. * ============================================================================
  13. *
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 数据层模型
  18. */
  19. class Store extends BaseModel
  20. {
  21. public $page_info;
  22. /**
  23. * 自营店铺的ID
  24. * @access protected
  25. * @author csdeshang
  26. * array(
  27. * '店铺ID(int)' => '是否绑定了全部商品类目(boolean)',
  28. * // ..
  29. * )
  30. */
  31. protected $ownShopIds;
  32. /**
  33. * 删除缓存自营店铺的ID
  34. * @access public
  35. * @author csdeshang
  36. */
  37. public function dropCachedOwnShopIds()
  38. {
  39. $this->ownShopIds = null;
  40. dkcache('own_shop_ids');
  41. }
  42. /**
  43. * 获取自营店铺的ID
  44. * @access public
  45. * @author csdeshang
  46. * @param boolean $bind_all_gc = false 是否只获取绑定全部类目的自营店 默认否(即全部自营店)
  47. * @return int
  48. */
  49. public function getOwnShopIds($bind_all_gc = false)
  50. {
  51. $data = $this->ownShopIds;
  52. // 属性为空则取缓存
  53. if (!$data) {
  54. $data = rkcache('own_shop_ids');
  55. // 缓存为空则查库
  56. if (!$data) {
  57. $data = array();
  58. $all_own_shops = Db::name('store')->field('store_id,bind_all_gc')->where(array('is_platform_store' => 1,))->select()->toArray();
  59. foreach ((array) $all_own_shops as $v) {
  60. $data[$v['store_id']] = (int) (bool) $v['bind_all_gc'];
  61. }
  62. // 写入缓存
  63. wkcache('own_shop_ids', $data);
  64. }
  65. // 写入属性
  66. $this->ownShopIds = $data;
  67. }
  68. return array_keys($bind_all_gc ? array_filter($data) : $data);
  69. }
  70. /**
  71. * 查询店铺列表
  72. * @access public
  73. * @author csdeshang
  74. * @param array $condition 查询条件
  75. * @param int $pagesize 分页数
  76. * @param string $order 排序
  77. * @param string $field 字段
  78. * @param string $limit 限制条数
  79. * @return array
  80. */
  81. public function getStoreList($condition, $pagesize = null, $order = '', $field = '*', $limit = 0)
  82. {
  83. if ($pagesize) {
  84. $result = Db::name('store')->field($field)->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  85. $this->page_info = $result;
  86. return $result->items();
  87. } else {
  88. $result = Db::name('store')->field($field)->where($condition)->order($order)->limit($limit)->select()->toArray();
  89. return $result;
  90. }
  91. }
  92. /**
  93. * 查询有效店铺列表
  94. * @access public
  95. * @author csdeshang
  96. * @param array $condition 查询条件
  97. * @param int $pagesize 分页数
  98. * @param string $order 排序
  99. * @param string $field 字段
  100. * @return array
  101. */
  102. public function getStoreOnlineList($condition, $pagesize = null, $order = '', $field = '*')
  103. {
  104. $condition[] = array('store_state', '=', 1);
  105. return $this->getStoreList($condition, $pagesize, $order, $field);
  106. }
  107. /**
  108. * 店铺数量
  109. * @access public
  110. * @author csdeshang
  111. * @param type $condition 条件
  112. * @return type
  113. */
  114. public function getStoreCount($condition)
  115. {
  116. return Db::name('store')->where($condition)->count();
  117. }
  118. /**
  119. * 按店铺编号查询店铺的信息
  120. * @access public
  121. * @author csdeshang
  122. * @param type $storeid_array 店铺ID编号
  123. * @param type $field 字段
  124. * @return type
  125. */
  126. public function getStoreMemberIDList($storeid_array, $field = 'store_id,member_id,store_name')
  127. {
  128. $store_list = Db::name('store')->where('store_id', 'in', $storeid_array)->field($field)->select()->toArray();
  129. $store_list = ds_change_arraykey($store_list, 'store_id');
  130. return $store_list;
  131. }
  132. /**
  133. * 查询店铺信息
  134. * @access public
  135. * @author csdeshang
  136. * @param array $condition 查询条件
  137. * @return array
  138. */
  139. public function getStoreInfo($condition)
  140. {
  141. $store_info = Db::name('store')->where($condition)->find();
  142. if (!empty($store_info)) {
  143. if (!empty($store_info['store_presales']))
  144. $store_info['store_presales'] = unserialize($store_info['store_presales']);
  145. if (!empty($store_info['store_aftersales']))
  146. $store_info['store_aftersales'] = unserialize($store_info['store_aftersales']);
  147. //商品数
  148. $goods_model = model('goods');
  149. $store_info['goods_count'] = $goods_model->getGoodsCommonOnlineCount(array(array('store_id', '=', $store_info['store_id'])));
  150. //店铺评价
  151. $evaluatestore_model = model('evaluatestore');
  152. $store_evaluate_info = $evaluatestore_model->getEvaluatestoreInfoByStoreID($store_info['store_id'], $store_info['storeclass_id']);
  153. $store_info = array_merge($store_info, $store_evaluate_info);
  154. }
  155. return $store_info;
  156. }
  157. /**
  158. * 通过店铺编号查询店铺信息
  159. * @access public
  160. * @author csdeshang
  161. * @param int $store_id 店铺编号
  162. * @return array
  163. */
  164. public function getStoreInfoByID($store_id)
  165. {
  166. $prefix = 'store_info';
  167. $store_info = rcache($store_id, $prefix);
  168. if (empty($store_info)) {
  169. $store_info = $this->getStoreInfo(array('store_id' => $store_id));
  170. $cache = array();
  171. $cache['store_info'] = serialize($store_info);
  172. wcache($store_id, $cache, $prefix, 60 * 24);
  173. } else {
  174. $store_info = unserialize($store_info['store_info']);
  175. }
  176. return $store_info;
  177. }
  178. /**
  179. * 获取店铺信息根据店铺id
  180. * @access public
  181. * @author csdeshang
  182. * @param type $store_id 店铺ID
  183. * @return type
  184. */
  185. public function getStoreOnlineInfoByID($store_id)
  186. {
  187. $store_info = $this->getStoreInfoByID($store_id);
  188. if (empty($store_info) || $store_info['store_state'] == '0') {
  189. return array();
  190. } else {
  191. return $store_info;
  192. }
  193. }
  194. /**
  195. * 获取店铺ID字符串
  196. * @access public
  197. * @author csdeshang
  198. * @param array $condition 条件
  199. * @return string
  200. */
  201. public function getStoreIDString($condition)
  202. {
  203. $condition[] = array('store_state', '=', 1);
  204. $store_list = $this->getStoreList($condition);
  205. $store_id_string = '';
  206. foreach ($store_list as $value) {
  207. $store_id_string .= $value['store_id'] . ',';
  208. }
  209. return $store_id_string;
  210. }
  211. /**
  212. * 添加店铺
  213. * @access public
  214. * @author csdeshang
  215. * @param type $data 店铺数据
  216. * @return type
  217. */
  218. public function addStore($data)
  219. {
  220. return Db::name('store')->insertGetId($data);
  221. }
  222. /**
  223. * 编辑店铺
  224. * @access public
  225. * @author csdeshang
  226. * @param type $update 更新数据
  227. * @param type $condition 条件
  228. * @return type
  229. */
  230. public function editStore($update, $condition)
  231. {
  232. //清空缓存
  233. $store_list = $this->getStoreList($condition);
  234. foreach ($store_list as $value) {
  235. dcache($value['store_id'], 'store_info');
  236. }
  237. return Db::name('store')->where($condition)->update($update);
  238. }
  239. /**
  240. * 删除店铺
  241. * @access public
  242. * @author csdeshang
  243. * @param array $condition 条件
  244. * @return bool
  245. */
  246. public function delStore($condition)
  247. {
  248. $store_info = $this->getStoreInfo($condition);
  249. //删除店铺相关图片
  250. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_STORE . DIRECTORY_SEPARATOR . $store_info['store_logo']);
  251. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_STORE . DIRECTORY_SEPARATOR . $store_info['store_banner']);
  252. if (isset($store_info['store_slide']) && $store_info['store_slide'] != '') {
  253. foreach (explode(',', $store_info['store_slide']) as $val) {
  254. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_SLIDE . DIRECTORY_SEPARATOR . $val);
  255. }
  256. }
  257. //清空缓存
  258. dcache($store_info['store_id'], 'store_info');
  259. return Db::name('store')->where($condition)->delete();
  260. }
  261. /**
  262. * 完全删除店铺 包括店主账号、店铺的管理员账号、店铺相册、店铺扩展
  263. * @access public
  264. * @author csdeshang
  265. * @param type $condition 条件
  266. */
  267. public function delStoreEntirely($condition)
  268. {
  269. $this->delStore($condition);
  270. model('seller')->delSeller($condition);
  271. model('sellergroup')->delSellergroup($condition);
  272. model('album')->delAlbum($condition['store_id']);
  273. model('storeextend')->delStoreextend($condition);
  274. model('storegoodsclass')->delStoregoodsclass($condition, $condition['store_id']);
  275. model('storemsg')->delStoremsg($condition);
  276. model('storenavigation')->delStorenavigation(array('storenav_store_id' => $condition['store_id']));
  277. model('storeplate')->delStoreplate($condition);
  278. model('storereopen')->delStorereopen(array('storereopen_store_id' => $condition['store_id']));
  279. model('storewatermark')->delStorewatermark($condition);
  280. }
  281. /**
  282. * 获取商品销售排行(每天更新一次)
  283. * @access public
  284. * @author csdeshang
  285. * @param int $store_id 店铺编号
  286. * @param int $limit 限制数量
  287. * @return array
  288. */
  289. public function getHotSalesList($store_id, $limit = 5)
  290. {
  291. $prefix = 'store_hot_sales_list_' . $limit;
  292. $hot_sales_list = rcache($store_id, $prefix);
  293. if (empty($hot_sales_list)) {
  294. $goods_model = model('goods');
  295. $hot_sales_list = $goods_model->getGoodsOnlineList(array(array('store_id', '=', $store_id)), '*', 0, 'goods_salenum desc', $limit);
  296. $cache = array();
  297. $cache['hot_sales'] = serialize($hot_sales_list);
  298. wcache($store_id, $cache, $prefix, 60 * 24);
  299. } else {
  300. $hot_sales_list = unserialize($hot_sales_list['hot_sales']);
  301. }
  302. return $hot_sales_list;
  303. }
  304. /**
  305. * 获取商品收藏排行(每天更新一次)
  306. * @access public
  307. * @author csdeshang
  308. * @param int $store_id 店铺编号
  309. * @param int $limit 限制数量
  310. * @return array 商品信息
  311. */
  312. public function getHotCollectList($store_id, $limit = 5)
  313. {
  314. $prefix = 'store_collect_sales_list_' . $limit;
  315. $hot_collect_list = rcache($store_id, $prefix);
  316. if (empty($hot_collect_list)) {
  317. $goods_model = model('goods');
  318. $hot_collect_list = $goods_model->getGoodsOnlineList(array(array('store_id', '=', $store_id)), '*', 0, 'goods_collect desc', $limit);
  319. $cache = array();
  320. $cache['collect_sales'] = serialize($hot_collect_list);
  321. wcache($store_id, $cache, $prefix, 60 * 24);
  322. } else {
  323. $hot_collect_list = unserialize($hot_collect_list['collect_sales']);
  324. }
  325. return $hot_collect_list;
  326. }
  327. /**
  328. * 获取店铺列表页附加信息
  329. * @access public
  330. * @author csdeshang
  331. * @param array $store_array 店铺数组
  332. * @return array 包含近期销量和8个推荐商品的店铺数组
  333. */
  334. public function getStoreSearchList($store_array)
  335. {
  336. $store_array_new = array();
  337. if (!empty($store_array)) {
  338. $no_cache_store = array();
  339. foreach ($store_array as $value) {
  340. //$store_search_info = rcache($value['store_id']);
  341. //print_r($store_array);exit();
  342. //if($store_search_info !== FALSE) {
  343. // $store_array_new[$value['store_id']] = $store_search_info;
  344. //} else {
  345. // $no_cache_store[$value['store_id']] = $value;
  346. //}
  347. $no_cache_store[$value['store_id']] = $value;
  348. }
  349. if (!empty($no_cache_store)) {
  350. //获取店铺商品数
  351. $no_cache_store = $this->getStoreInfoBasic($no_cache_store);
  352. //获取店铺近期销量
  353. $no_cache_store = $this->getGoodsCountJq($no_cache_store);
  354. //获取店铺推荐商品
  355. $no_cache_store = $this->getGoodsListBySales($no_cache_store);
  356. //写入缓存
  357. foreach ($no_cache_store as $value) {
  358. wcache($value['store_id'], $value, 'store_search_info');
  359. }
  360. $store_array_new = array_merge($store_array_new, $no_cache_store);
  361. }
  362. }
  363. return $store_array_new;
  364. }
  365. /**
  366. * 获得店铺标志、信用、商品数量、店铺评分等信息
  367. * @access public
  368. * @author csdeshang
  369. * @param type $list 店铺数组
  370. * @param type $day 天数
  371. * @return type
  372. */
  373. public function getStoreInfoBasic($list, $day = 0)
  374. {
  375. $list_new = array();
  376. if (!empty($list) && is_array($list)) {
  377. foreach ($list as $key => $value) {
  378. if (!empty($value)) {
  379. $value['store_logo'] = get_store_logo($value['store_logo']);
  380. //店铺评价
  381. $evaluatestore_model = model('evaluatestore');
  382. $store_evaluate_info = $evaluatestore_model->getEvaluatestoreInfoByStoreID($value['store_id'], $value['storeclass_id']);
  383. $value = array_merge($value, $store_evaluate_info);
  384. if (!empty($value['store_presales']))
  385. $value['store_presales'] = unserialize($value['store_presales']);
  386. if (!empty($value['store_aftersales']))
  387. $value['store_aftersales'] = unserialize($value['store_aftersales']);
  388. $list_new[$value['store_id']] = $value;
  389. $list_new[$value['store_id']]['goods_count'] = 0;
  390. }
  391. }
  392. //全部商品数直接读取缓存
  393. if ($day > 0) {
  394. $store_id_string = implode(',', array_keys($list_new));
  395. //指定天数直接查询数据库
  396. $condition = array();
  397. $condition[] = array('goods_show', '=', 1);
  398. $condition[] = array('store_id', 'in', $store_id_string);
  399. $condition[] = array('goods_addtime', '>', strtotime("-{$day} day"));
  400. $goods_count_array = Db::name('goods')->field('store_id,count(*) as goods_count')->where($condition)->group('store_id')->select()->toArray();
  401. if (!empty($goods_count_array)) {
  402. foreach ($goods_count_array as $value) {
  403. $list_new[$value['store_id']]['goods_count'] = $value['goods_count'];
  404. }
  405. }
  406. } else {
  407. $list_new = $this->getGoodsCountByStoreArray($list_new);
  408. }
  409. }
  410. return $list_new;
  411. }
  412. /**
  413. * 获取店铺商品数
  414. * @access public
  415. * @author csdeshang
  416. * @param type $store_array 店铺数组
  417. * @return type
  418. */
  419. public function getGoodsCountByStoreArray($store_array)
  420. {
  421. $store_array_new = array();
  422. $no_cache_store = '';
  423. foreach ($store_array as $value) {
  424. $goods_count = rcache($value['store_id'], 'store_goods_count');
  425. if (!empty($goods_count) && $goods_count !== FALSE) {
  426. //有缓存的直接赋值
  427. $value['goods_count'] = $goods_count;
  428. } else {
  429. //没有缓存记录store_id,统计从数据库读取
  430. $no_cache_store .= $value['store_id'] . ',';
  431. $value['goods_count'] = '0';
  432. }
  433. $store_array_new[$value['store_id']] = $value;
  434. }
  435. if (!empty($no_cache_store)) {
  436. //从数据库读取店铺商品数赋值并缓存
  437. $no_cache_store = rtrim($no_cache_store, ',');
  438. $condition = array();
  439. $condition[] = array('goods_state', '=', 1);
  440. $condition[] = array('store_id', 'in', $no_cache_store);
  441. $goods_count_array = Db::name('goods')->field('store_id,count(*) as goods_count')->where($condition)->group('store_id')->select()->toArray();
  442. if (!empty($goods_count_array)) {
  443. foreach ($goods_count_array as $value) {
  444. $store_array_new[$value['store_id']]['goods_count'] = $value['goods_count'];
  445. wcache($value['store_id'], $value['goods_count'], 'store_goods_count');
  446. }
  447. }
  448. }
  449. return $store_array_new;
  450. }
  451. /**
  452. * 获取近期销量
  453. * @access public
  454. * @author csdeshang
  455. * @param type $store_array 店铺数组
  456. * @return type
  457. */
  458. private function getGoodsCountJq($store_array)
  459. {
  460. $order_count_array = Db::name('order')->field('store_id,count(*) as order_count')->where('store_id', 'in', implode(',', array_keys($store_array)))->where('order_state', '<>', '0')->where('add_time', '>', TIMESTAMP - 3600 * 24 * 90)->group('store_id')->select()->toArray();
  461. foreach ((array) $order_count_array as $value) {
  462. $store_array[$value['store_id']]['num_sales_jq'] = $value['order_count'];
  463. }
  464. return $store_array;
  465. }
  466. /**
  467. * 获取店铺8个销量最高商品
  468. * @access public
  469. * @author csdeshang
  470. * @param type $store_array 店铺数组
  471. * @return type
  472. */
  473. private function getGoodsListBySales($store_array)
  474. {
  475. $field = 'goods_id,store_id,goods_name,goods_image,goods_price,goods_salenum';
  476. foreach ($store_array as $value) {
  477. $store_array[$value['store_id']]['search_list_goods'] = Db::name('goods')->field($field)->where(array('store_id' => $value['store_id'], 'goods_state' => 1))->order('goods_salenum desc')->limit(8)->select()->toArray();
  478. }
  479. return $store_array;
  480. }
  481. /**
  482. * 编辑
  483. * @param type $condition
  484. * @param type $data
  485. * @return type
  486. */
  487. public function editGoodscommon($condition, $data)
  488. {
  489. return Db::name('goodscommon')->where($condition)->update($data);
  490. }
  491. /**
  492. * 编辑商品
  493. * @param type $condition
  494. * @param type $data
  495. * @return type
  496. */
  497. public function editGoods($condition, $data)
  498. {
  499. return Db::name('goods')->where($condition)->update($data);
  500. }
  501. /**
  502. * 插入店铺扩展表
  503. * @param type $condition
  504. * @return type
  505. */
  506. public function addStoreextend($condition)
  507. {
  508. return Db::name('storeextend')->insert($condition);
  509. }
  510. /**
  511. * 获取单个店铺
  512. * @param type $condition
  513. * @param type $field
  514. * @return type
  515. */
  516. public function getOneStore($condition, $field)
  517. {
  518. return Db::name('store')->field($field)->where($condition)->find();
  519. }
  520. /**
  521. * 店铺流量统计入库
  522. */
  523. public function flowstat_record($store_id, $goods_id, $controller_param, $action_param, $store_info)
  524. {
  525. if (!empty($store_info)) {
  526. if ($store_id <= 0 || $store_info['store_id'] == $store_id) {
  527. return false;
  528. }
  529. }
  530. //确定统计分表名称
  531. $last_num = $store_id % 10; //获取店铺ID的末位数字
  532. $tablenum = ($t = intval(config('ds_config.flowstat_tablenum'))) > 1 ? $t : 1; //处理流量统计记录表数量
  533. $flow_tablename = ($t = ($last_num % $tablenum)) > 0 ? "flowstat_$t" : 'flowstat';
  534. //判断是否存在当日数据信息
  535. $stattime = strtotime(date('Y-m-d', TIMESTAMP));
  536. $stat_model = model('stat');
  537. //查询店铺流量统计数据是否存在
  538. // halt($flow_tablename);
  539. if ($flow_tablename == 'flowstat') {
  540. $flow_tablename_condition = array('flowstat_stattime' => $stattime, 'store_id' => $store_id, 'flowstat_type' => 'sum');
  541. } else {
  542. $flow_tablename_condition = array('flowstat_stattime' => $stattime, 'store_id' => $store_id, 'flowstat_type' => 'sum');
  543. }
  544. $store_exist = $stat_model->getoneByFlowstat($flow_tablename, $flow_tablename_condition);
  545. if ($controller_param == 'Goods' && $action_param == 'index') { //统计商品页面流量
  546. $goods_id = intval($goods_id);
  547. if ($goods_id <= 0) {
  548. return false;
  549. }
  550. if ($flow_tablename == 'flowstat') {
  551. $flow_tablename_condition = array('flowstat_stattime' => $stattime, 'goods_id' => $goods_id, 'flowstat_type' => 'goods');
  552. } else {
  553. $flow_tablename_condition = array('flowstat_stattime' => $stattime, 'goods_id' => $goods_id, 'flowstat_type' => 'goods');
  554. }
  555. $goods_exist = $stat_model->getoneByFlowstat($flow_tablename, $flow_tablename_condition);
  556. }
  557. //向数据库写入访问量数据
  558. $insert_arr = array();
  559. if ($store_exist) {
  560. Db::name($flow_tablename)->where(array('flowstat_stattime' => $stattime, 'store_id' => $store_id, 'flowstat_type' => 'sum'))->inc('flowstat_clicknum')->update();
  561. } else {
  562. $insert_arr[] = array('flowstat_stattime' => $stattime, 'flowstat_clicknum' => 1, 'store_id' => $store_id, 'flowstat_type' => 'sum', 'goods_id' => 0);
  563. }
  564. if ($controller_param == 'Goods' && $action_param == 'index') { //已经存在数据则更新
  565. if ($goods_exist) {
  566. Db::name($flow_tablename)->where(array('flowstat_stattime' => $stattime, 'goods_id' => $goods_id, 'flowstat_type' => 'goods'))->inc('flowstat_clicknum')->update();
  567. } else {
  568. $insert_arr[] = array('flowstat_stattime' => $stattime, 'flowstat_clicknum' => 1, 'store_id' => $store_id, 'flowstat_type' => 'goods', 'goods_id' => $goods_id);
  569. }
  570. }
  571. if ($insert_arr) {
  572. Db::name($flow_tablename)->insertAll($insert_arr);
  573. }
  574. }
  575. /**
  576. * 店铺开店成功
  577. * @param type $condition
  578. * @param type $field
  579. * @return type
  580. */
  581. public function setStoreOpen($joinin_detail, $param)
  582. {
  583. $storejoinin_model = model('storejoinin');
  584. $seller_model = model('seller');
  585. //验证卖家用户名是否已经存在
  586. if ($seller_model->isSellerExist(array('seller_name' => $joinin_detail['seller_name']))) {
  587. throw new \think\Exception('卖家用户名已存在', 10006);
  588. }
  589. $predeposit_model = model('predeposit');
  590. //下单,支付被冻结的充值卡
  591. $rcb_amount = floatval($joinin_detail['rcb_amount']);
  592. if ($rcb_amount > 0) {
  593. $data_pd = array();
  594. $data_pd['member_id'] = $joinin_detail['member_id'];
  595. $data_pd['member_name'] = $joinin_detail['member_name'];
  596. $data_pd['amount'] = $rcb_amount;
  597. $data_pd['order_sn'] = $joinin_detail['pay_sn'];
  598. $predeposit_model->changeRcb('storejoinin_comb_pay', $data_pd);
  599. }
  600. //下单,支付被冻结的预存款
  601. $pd_amount = floatval($joinin_detail['pd_amount']);
  602. if ($pd_amount > 0) {
  603. $data_pd = array();
  604. $data_pd['member_id'] = $joinin_detail['member_id'];
  605. $data_pd['member_name'] = $joinin_detail['member_name'];
  606. $data_pd['amount'] = $pd_amount;
  607. $data_pd['order_sn'] = $joinin_detail['pay_sn'];
  608. $predeposit_model->changePd('storejoinin_comb_pay', $data_pd);
  609. }
  610. //开店
  611. $shop_array = array();
  612. $shop_array['member_id'] = $joinin_detail['member_id'];
  613. $shop_array['member_name'] = $joinin_detail['member_name'];
  614. $shop_array['seller_name'] = $joinin_detail['seller_name'];
  615. $shop_array['grade_id'] = $joinin_detail['storegrade_id'];
  616. $shop_array['store_name'] = $joinin_detail['store_name'];
  617. $shop_array['storeclass_id'] = $joinin_detail['storeclass_id'];
  618. $shop_array['store_company_name'] = $joinin_detail['company_name'];
  619. $shop_array['region_id'] = $joinin_detail['company_province_id'];
  620. $shop_array['store_longitude'] = $joinin_detail['store_longitude'];
  621. $shop_array['store_latitude'] = $joinin_detail['store_latitude'];
  622. $shop_array['area_info'] = $joinin_detail['company_address'];
  623. $shop_array['store_address'] = $joinin_detail['company_address_detail'];
  624. $shop_array['store_zip'] = '';
  625. $shop_array['store_mainbusiness'] = '';
  626. $shop_array['store_state'] = 1;
  627. $shop_array['store_addtime'] = TIMESTAMP;
  628. $shop_array['store_endtime'] = strtotime(date('Y-m-d 23:59:59', strtotime('+1 day')) . " +" . intval($joinin_detail['joinin_year']) . " year");
  629. //$shop_array['store_avaliable_deposit']=$joinin_detail['storeclass_bail'];
  630. $store_id = $this->addStore($shop_array);
  631. if ($store_id) {
  632. //记录保证金
  633. if ($joinin_detail['storeclass_bail'] > 0) {
  634. $storedepositlog_model = model('storedepositlog');
  635. $storedepositlog_model->changeStoredeposit(array(
  636. 'store_id' => $store_id,
  637. 'storedepositlog_type' => Storedepositlog::TYPE_PAY,
  638. 'storedepositlog_state' => Storedepositlog::STATE_VALID,
  639. 'storedepositlog_add_time' => TIMESTAMP,
  640. 'store_avaliable_deposit' => $joinin_detail['storeclass_bail'],
  641. 'storedepositlog_desc' => '店铺入驻保证金',
  642. ));
  643. }
  644. //写入卖家账号
  645. $seller_array = array();
  646. $seller_array['seller_name'] = $joinin_detail['seller_name'];
  647. $seller_array['member_id'] = $joinin_detail['member_id'];
  648. $seller_array['sellergroup_id'] = 0;
  649. $seller_array['store_id'] = $store_id;
  650. $seller_array['is_admin'] = 1;
  651. $state = $seller_model->addSeller($seller_array);
  652. //改变店铺状态
  653. $storejoinin_model->editStorejoinin($param, array('member_id' => $joinin_detail['member_id']));
  654. } else {
  655. throw new \think\Exception('店铺新增失败', 10006);
  656. }
  657. if ($state) {
  658. // 添加相册默认
  659. $album_model = model('album');
  660. $album_arr = array();
  661. $album_arr['aclass_name'] = '默认相册';
  662. $album_arr['store_id'] = $store_id;
  663. $album_arr['aclass_des'] = '';
  664. $album_arr['aclass_sort'] = '255';
  665. $album_arr['aclass_cover'] = '';
  666. $album_arr['aclass_uploadtime'] = TIMESTAMP;
  667. $album_arr['aclass_isdefault'] = '1';
  668. $album_model->addAlbumclass($album_arr);
  669. //插入店铺扩展表
  670. $this->addStoreextend(array('store_id' => $store_id));
  671. //插入店铺绑定分类表
  672. $store_bind_class_array = array();
  673. $store_bind_class = unserialize($joinin_detail['store_class_ids']);
  674. $store_bind_commis_rates = explode(',', $joinin_detail['store_class_commis_rates']);
  675. for ($i = 0, $length = count($store_bind_class); $i < $length; $i++) {
  676. @list($class1, $class2, $class3) = explode(',', $store_bind_class[$i]);
  677. $store_bind_class_array[] = array(
  678. 'store_id' => $store_id,
  679. 'commis_rate' => $store_bind_commis_rates[$i],
  680. 'class_1' => intval($class1),
  681. 'class_2' => intval($class2),
  682. 'class_3' => intval($class3),
  683. 'storebindclass_state' => 1
  684. );
  685. }
  686. $storebindclass_model = model('storebindclass');
  687. $storebindclass_model->addStorebindclassAll($store_bind_class_array);
  688. } else {
  689. throw new \think\Exception('店铺新增失败', 10006);
  690. }
  691. return true;
  692. }
  693. }