SellerResource.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class SellerResource extends BaseSeller {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/seller_resource.lang.php');
  20. }
  21. /**
  22. * 资源删除
  23. */
  24. public function del_resource() {
  25. $return_json = input('param.return_json'); //是否为json 返回
  26. $file_name = input('param.file_name');
  27. $ids = input('param.id/a');
  28. if (empty($file_name) && empty($ids)) {
  29. ds_json_encode(10001, lang('param_error'));
  30. }
  31. $goods_resource_model = model('goods_resource');
  32. //删除资源
  33. $condition = array();
  34. if($ids){
  35. $condition[] = array('goods_resource_id', 'in', $ids);
  36. }
  37. if($file_name){
  38. $condition[] = array('file_name', '=', $file_name);
  39. }
  40. $condition[] = array('store_id', '=', session('store_id'));
  41. $return = $goods_resource_model->delGoodsResource($condition,session('store_id'));
  42. if ($return) {
  43. ds_json_encode(10000, lang('ds_common_op_succ'));
  44. } else {
  45. ds_json_encode(10001, lang('ds_common_op_fail'));
  46. }
  47. }
  48. /**
  49. * 上传资源
  50. */
  51. public function resource_upload() {
  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. }
  78. ?>