SellerResource.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 控制器
  14. */
  15. class SellerResource extends MobileSeller {
  16. public function initialize() {
  17. parent::initialize();
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/seller_resource.lang.php');
  19. }
  20. /**
  21. * 资源删除
  22. */
  23. public function del_resource() {
  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', '=', $this->store_info['store_id']);
  40. $return = $goods_resource_model->delGoodsResource($condition,$this->store_info['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. $store_id = $this->store_info['store_id'];
  52. $save_name = $store_id . '_' . date('YmdHis') . rand(10000, 99999) . '.zip';
  53. $file_name = 'file';
  54. $upload_path = ATTACH_GOODS_RESOURCE . DIRECTORY_SEPARATOR . $store_id;
  55. $res = ds_upload_pic($upload_path, $file_name, $save_name, 'zip');
  56. if ($res['code']) {
  57. $save_name = $res['data']['file_name'];
  58. $data = array();
  59. $data ['url'] = goods_resource($save_name);
  60. $data ['name'] = $save_name;
  61. $goods_resource_model = model('goods_resource');
  62. $goods_resource_model->addGoodsResource(array(
  63. 'store_id' => $store_id,
  64. 'store_name' => $this->store_info['store_name'],
  65. 'file_name' => $save_name,
  66. 'file_size' => $_FILES[$file_name]['size'],
  67. 'goods_resource_name' => $_FILES[$file_name]['name'],
  68. 'goods_resource_add_time' => TIMESTAMP
  69. ));
  70. // 整理为json格式
  71. ds_json_encode(10000, lang('ds_common_op_succ'), $data);
  72. } else {
  73. ds_json_encode(10001, $res['msg']);
  74. }
  75. }
  76. }
  77. ?>