SellerResource.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class SellerResource extends BaseSeller
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/seller_resource.lang.php');
  18. }
  19. /**
  20. * 资源删除
  21. */
  22. public function del_resource()
  23. {
  24. $return_json = input('param.return_json'); //是否为json 返回
  25. $file_name = input('param.file_name');
  26. $ids = input('param.id/a');
  27. if (empty($file_name) && empty($ids)) {
  28. ds_json_encode(10001, lang('param_error'));
  29. }
  30. $goods_resource_model = model('goods_resource');
  31. //删除资源
  32. $condition = array();
  33. if ($ids) {
  34. $condition[] = array('goods_resource_id', 'in', $ids);
  35. }
  36. if ($file_name) {
  37. $condition[] = array('file_name', '=', $file_name);
  38. }
  39. $condition[] = array('store_id', '=', session('store_id'));
  40. $return = $goods_resource_model->delGoodsResource($condition, session('store_id'));
  41. if ($return) {
  42. ds_json_encode(10000, lang('ds_common_op_succ'));
  43. } else {
  44. ds_json_encode(10001, lang('ds_common_op_fail'));
  45. }
  46. }
  47. /**
  48. * 上传资源
  49. */
  50. public function resource_upload()
  51. {
  52. $store_id = session('store_id');
  53. $save_name = $store_id . '_' . date('YmdHis') . rand(10000, 99999) . '.zip';
  54. $file_name = 'file';
  55. $upload_path = ATTACH_GOODS_RESOURCE . DIRECTORY_SEPARATOR . $store_id;
  56. $res = ds_upload_pic($upload_path, $file_name, $save_name, 'zip');
  57. if ($res['code']) {
  58. $save_name = $res['data']['file_name'];
  59. $data = array();
  60. $data['url'] = goods_resource($save_name);
  61. $data['name'] = $save_name;
  62. $goods_resource_model = model('goods_resource');
  63. $goods_resource_model->addGoodsResource(array(
  64. 'store_id' => $store_id,
  65. 'store_name' => session('store_name'),
  66. 'file_name' => $save_name,
  67. 'file_size' => $_FILES[$file_name]['size'],
  68. 'goods_resource_name' => $_FILES[$file_name]['name'],
  69. 'goods_resource_add_time' => TIMESTAMP
  70. ));
  71. // 整理为json格式
  72. ds_json_encode(10000, lang('ds_common_op_succ'), $data);
  73. } else {
  74. ds_json_encode(10001, $res['msg']);
  75. }
  76. }
  77. }