SellerResource.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class SellerResource extends MobileSeller {
  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', '=', $this->store_info['store_id']);
  41. $return = $goods_resource_model->delGoodsResource($condition,$this->store_info['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 = $this->store_info['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' => $this->store_info['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. ?>