SellerModel.class.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Admin\Model;
  15. class SellerModel{
  16. /**
  17. *显示分页
  18. */
  19. public function show_seller_user_page($search){
  20. $sql="select * from ".C('DB_PREFIX')."seller ";
  21. //s_true_name s_true_name
  22. if( !empty($search) && !empty($search['s_true_name']))
  23. {
  24. $sql .= " where s_true_name LIKE '%".$search['s_true_name']."%' ";
  25. }
  26. $count=count(M()->query($sql));
  27. $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
  28. $show = $Page->show();// 分页显示输出
  29. $sql.=' order by s_id desc LIMIT '.$Page->firstRow.','.$Page->listRows;
  30. $list=M()->query($sql);
  31. $site_c = M('config')->where( array('name' => 'SITE_URL') )->find();
  32. foreach($list as $key => $val)
  33. {
  34. $seller_view_link = $site_c['value']."/index.php?s=/seller/info/seller_id/".$val['s_id'];
  35. $apply_relship = M('apply_relship')->where( array('seller_id' => $val['s_id']) )->find();
  36. $list[$key]['seller_view_link'] = $seller_view_link;
  37. }
  38. return array(
  39. 'empty'=>'<tr><td colspan="20">~~暂无数据</td></tr>',
  40. 'list'=>$list,
  41. 'page'=>$show
  42. );
  43. }
  44. public function validate($data){
  45. $error=array();
  46. if(empty($data['image'])){
  47. $error='图片必须';
  48. }
  49. if($error){
  50. return array(
  51. 'status'=>'back',
  52. 'message'=>$error
  53. );
  54. }
  55. }
  56. public function edit_ad($data){
  57. $error=$this->validate($data);
  58. if($error){
  59. return $error;
  60. }
  61. $r=M('seller_ad')->save($data);
  62. if($r){
  63. return array(
  64. 'status'=>'success',
  65. 'message'=>'修改成功',
  66. 'jump'=>U('Seller/adlist')
  67. );
  68. }else{
  69. return array(
  70. 'status'=>'fail',
  71. 'message'=>'修改失败',
  72. 'jump'=>U('Seller/adlist')
  73. );
  74. }
  75. }
  76. public function add_ad($data)
  77. {
  78. $error=$this->validate($data);
  79. if($error){
  80. return $error;
  81. }
  82. $data['addtime'] = time();
  83. $r=M('seller_ad')->add($data);
  84. if($r){
  85. return array(
  86. 'status'=>'success',
  87. 'message'=>'新增成功',
  88. 'jump'=>U('Seller/adlist')
  89. );
  90. }else{
  91. return array(
  92. 'status'=>'fail',
  93. 'message'=>'新增失败',
  94. 'jump'=>U('Seller/adlist')
  95. );
  96. }
  97. }
  98. public function show_slider_page($seller_id){
  99. $count=M('seller_ad')->where( array('seller_id' => $seller_id) )->count();
  100. $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
  101. $show = $Page->show();// 分页显示输出
  102. $list = M('seller_ad')->where(array('seller_id' => $seller_id))->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
  103. foreach ($list as $key => $value) {
  104. $list[$key]['image']=resize($value['image'], 100, 100);
  105. }
  106. return array(
  107. 'empty'=>'<tr><td colspan="20">~~暂无数据</td></tr>',
  108. 'list'=>$list,
  109. 'page'=>$show
  110. );
  111. }
  112. function show_apply_user_page($search = array())
  113. {
  114. $sql="select * from ".C('DB_PREFIX')."apply ";
  115. if(!empty($search))
  116. {
  117. if(isset($search['state']))
  118. {
  119. $where = ' where state = '.intval($search['state']);
  120. $sql .= $where;
  121. }
  122. }
  123. $count=count(M()->query($sql));
  124. $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
  125. $show = $Page->show();// 分页显示输出
  126. $sql.=' order by state asc,id desc LIMIT '.$Page->firstRow.','.$Page->listRows;
  127. $list=M()->query($sql);
  128. foreach($list as $key => $val)
  129. {
  130. $goods_category = M('goods_category')->where( array('id' => $val['category_id']) )->find();
  131. $val['category_name'] = $goods_category['name'];
  132. $list[$key] = $val;
  133. }
  134. return array(
  135. 'empty'=>'<tr><td colspan="20">~~暂无数据</td></tr>',
  136. 'list'=>$list,
  137. 'page'=>$show
  138. );
  139. }
  140. function add_seller_user($data){
  141. if(empty($data['s_uname'])){
  142. $error="卖家名不能为空!!";
  143. }elseif(empty($data['s_passwd'])){
  144. $error="密码不能为空!!";
  145. }
  146. if($error){
  147. return array(
  148. 'status'=>'back',
  149. 'message'=>$error
  150. );
  151. }
  152. $data['s_passwd'] =think_ucenter_encrypt($data['s_passwd'],C('SELLER_PWD_KEY'));
  153. $data['s_create_time'] =time();
  154. $data['s_status'] =1;
  155. $res = M('Seller')->add($data);
  156. $s_id = M('Seller')->getLastInsID();
  157. if($res){
  158. return array(
  159. 's_id' => $s_id,
  160. 'status'=>'success',
  161. 'message'=>'新增成功',
  162. 'jump'=>U('SellerManage/index')
  163. );
  164. }else{
  165. return array(
  166. 'status'=>'back',
  167. 'message'=>'新增失败'
  168. );
  169. }
  170. }
  171. function edit_seller_user($d){
  172. /**
  173. array(3) {
  174. ["s_uname"]=>
  175. string(9) "狮子鱼"
  176. ["s_passwd"]=>
  177. string(1) "1"
  178. ["s_id"]=>
  179. string(1) "1"
  180. }
  181. **/
  182. if(empty($d['s_passwd']))
  183. {
  184. unset($d['s_passwd']);
  185. }else
  186. $d['s_passwd']=think_ucenter_encrypt($d['s_passwd'],C('SELLER_PWD_KEY'));
  187. $d['s_true_name'] = $d['s_uname'];
  188. $r=M('Seller')->where(array('s_id'=>$d['s_id']))->save($d);
  189. if($r){
  190. return true;
  191. }else{
  192. return false;
  193. }
  194. }
  195. }
  196. ?>