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