GoodsAction.class.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维p2p借贷系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class GoodsAction extends CommonAction{
  10. public function index()
  11. {
  12. if(strim($_REQUEST['name'])!=''){
  13. $map['name'] = array('like','%'.strim($_REQUEST['name']).'%');
  14. }
  15. if(intval($_REQUEST['cate_id'])!=0){
  16. $map['cate_id'] = intval($_REQUEST['cate_id']);
  17. }
  18. $name=$this->getActionName();
  19. $model = D ($name);
  20. if (! empty ( $model )) {
  21. $this->_list ( $model, $map );
  22. }
  23. $list = $this->get('list');
  24. foreach($list as $k => $v){
  25. $list[$k]['imgs'] = json_decode($v['imgs'],1)[0];
  26. $list[$k]['imgs_details'] = json_decode($v['imgs_details'],1)[0];
  27. }
  28. $this->assign("cate_list",M("GoodsCate")->where('is_effect = 1')->findAll());
  29. $this->assign("list",$list);
  30. $this->display();
  31. }
  32. public function edit() {
  33. $id = intval($_REQUEST ['id']);
  34. $condition['id'] = $id;
  35. $vo = M(MODULE_NAME)->where($condition)->find();
  36. $vo['imgs'] = json_decode($vo['imgs'],1)[0];
  37. $vo['imgs_details'] = json_decode($vo['imgs_details'],1)[0];
  38. $vo['tags_id'] = json_decode($vo['tags_id']);
  39. $this->assign ('vo',$vo );
  40. $cate = $GLOBALS['db']->getAll("select * from ".DB_PREFIX."goods_cate where is_effect=1");
  41. $tags = $GLOBALS['db']->getAll("select * from ".DB_PREFIX."goods_tags");
  42. $this->assign ('cate_info',$cate );
  43. $this->assign ('tags_info',$tags );
  44. $this->display ();
  45. }
  46. public function update() {
  47. B('FilterString');
  48. $data = M(MODULE_NAME)->create();
  49. //clear_auto_cache("prop_list");
  50. $log_info = M(MODULE_NAME)->where("id=".intval($data['id']))->getField("name");
  51. //开始验证有效性
  52. $this->assign("jumpUrl",u(MODULE_NAME."/edit",array("id"=>$data['id'])));
  53. $data['tags_id'] = json_encode($_REQUEST['tags_id']);
  54. if(!check_empty($data['name']))
  55. {
  56. $this->error("请输入名称");
  57. }
  58. if(!check_empty($data['imgs']))
  59. {
  60. $this->error("请输入商品主图片");
  61. }
  62. $data['imgs'] = json_encode(array($data['imgs']),JSON_UNESCAPED_SLASHES);
  63. if(!check_empty($data['imgs_details']))
  64. {
  65. $this->error("请输入商品详情图片");
  66. }
  67. $data['imgs_details'] = json_encode(array($data['imgs_details']),JSON_UNESCAPED_SLASHES);
  68. if(SHOPPING_GOODS == 1){
  69. if(floatval($data['price']) == 0)
  70. {
  71. $this->error("请输入商品价格(人民币)");
  72. }
  73. }
  74. if(intval($data['kd_cost']) == 0)
  75. {
  76. $data['kd_cost'] = 0;
  77. }
  78. if(floatval($data['podcast_ticket']) == 0)
  79. {
  80. $data['podcast_ticket'] = 0;
  81. }
  82. if(intval($data['score']) == 0)
  83. {
  84. $data['score'] = 0;
  85. }
  86. if(intval($data['inventory']) == 0)
  87. {
  88. $this->error("请输入商品库存");
  89. }
  90. if(intval($data['sales']) == 0)
  91. {
  92. $data['sales'] = 0;
  93. }
  94. if(intval($data['number']) == 0)
  95. {
  96. $data['number'] = 0;
  97. }
  98. if(PAI_REAL_BTN == 1){
  99. if(intval($data['pai_diamonds']) == 0)
  100. {
  101. $this->error("请输入商品直播价格(钻石)");
  102. }
  103. if(intval($data['bz_diamonds']) == 0)
  104. {
  105. $this->error("请输入竞拍保证金");
  106. }
  107. if(intval($data['jj_diamonds']) == 0)
  108. {
  109. $this->error("请输入竞拍加价金额");
  110. }
  111. if(floatval($data['pai_time']) == 0)
  112. {
  113. $data['pai_time'] = 0;
  114. }
  115. }
  116. if(!check_empty($data['description']))
  117. {
  118. $this->error("请输入商品描述");
  119. }
  120. // 更新数据
  121. $list=M(MODULE_NAME)->save ($data);
  122. if (false !== $list) {
  123. //成功提示
  124. save_log($log_info.L("UPDATE_SUCCESS"),1);
  125. clear_auto_cache("prop_id",array('id'=>$data['id']));
  126. $this->success(L("UPDATE_SUCCESS"));
  127. } else {
  128. //错误提示
  129. save_log($log_info.L("UPDATE_FAILED"),0);
  130. $this->error(L("UPDATE_FAILED"),0,$log_info.L("UPDATE_FAILED"));
  131. }
  132. }
  133. public function add(){
  134. $vo = $GLOBALS['db']->getAll("select * from ".DB_PREFIX."goods_cate where is_effect=1");
  135. $tags = $GLOBALS['db']->getAll("select * from ".DB_PREFIX."goods_tags");
  136. $this->assign ('cate_info',$vo );
  137. $this->assign ('tags_info',$tags );
  138. $this->display ();
  139. }
  140. public function add_goods() {
  141. $data = M(MODULE_NAME)->create();
  142. $data['tags_id'] = json_encode($_REQUEST['tags_id']);
  143. if(!check_empty($data['name']))
  144. {
  145. $this->error("请输入名称");
  146. }
  147. if(!check_empty($data['imgs']))
  148. {
  149. $this->error("请输入商品主图片");
  150. }
  151. $data['imgs'] = json_encode(array($data['imgs']),JSON_UNESCAPED_SLASHES);
  152. if(!check_empty($data['imgs_details']))
  153. {
  154. $this->error("请输入商品详情图片");
  155. }
  156. $data['imgs_details'] = json_encode(array($data['imgs_details']),JSON_UNESCAPED_SLASHES);
  157. if(SHOPPING_GOODS == 1){
  158. if(floatval($data['price']) == 0)
  159. {
  160. $this->error("请输入商品价格(人民币)");
  161. }
  162. }
  163. if(intval($data['kd_cost']) == 0)
  164. {
  165. $data['kd_cost'] = 0;
  166. }
  167. if(floatval($data['podcast_ticket']) == 0)
  168. {
  169. $data['podcast_ticket'] = 0;
  170. }
  171. if(intval($data['score']) == 0)
  172. {
  173. $data['score'] = 0;
  174. }
  175. if(intval($data['inventory']) == 0)
  176. {
  177. $this->error("请输入商品库存");
  178. }
  179. if(intval($data['sales']) == 0)
  180. {
  181. $data['sales'] = 0;
  182. }
  183. if(intval($data['number']) == 0)
  184. {
  185. $data['number'] = 0;
  186. }
  187. if(PAI_REAL_BTN == 1){
  188. if(intval($data['pai_diamonds']) == 0)
  189. {
  190. $this->error("请输入商品直播价格(钻石)");
  191. }
  192. if(intval($data['bz_diamonds']) == 0)
  193. {
  194. $this->error("请输入竞拍保证金");
  195. }
  196. if(intval($data['jj_diamonds']) == 0)
  197. {
  198. $this->error("请输入竞拍加价金额");
  199. }
  200. if(floatval($data['pai_time']) == 0)
  201. {
  202. $data['pai_time'] = 0;
  203. }
  204. }
  205. if(!check_empty($data['description']))
  206. {
  207. $this->error("请输入商品描述");
  208. }
  209. // 更新数据
  210. $log_info = $data['name'];
  211. $list=M(MODULE_NAME)->add($data);
  212. if (false !== $list) {
  213. //成功提示
  214. save_log($log_info.L("INSERT_SUCCESS"),1);
  215. $this->success(L("INSERT_SUCCESS"));
  216. } else {
  217. //错误提示
  218. save_log($log_info.L("INSERT_FAILED"),0);
  219. $this->error(L("INSERT_FAILED"));
  220. }
  221. }
  222. }
  223. ?>