Store.php 29 KB

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