Store.php 29 KB

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