SellerResource.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 控制器
  10. */
  11. class SellerResource extends MobileSeller
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/seller_resource.lang.php');
  17. }
  18. /**
  19. * 资源删除
  20. */
  21. public function del_resource()
  22. {
  23. $return_json = input('param.return_json'); //是否为json 返回
  24. $file_name = input('param.file_name');
  25. $ids = input('param.id/a');
  26. if (empty($file_name) && empty($ids)) {
  27. ds_json_encode(10001, lang('param_error'));
  28. }
  29. $goods_resource_model = model('goods_resource');
  30. //删除资源
  31. $condition = array();
  32. if ($ids) {
  33. $condition[] = array('goods_resource_id', 'in', $ids);
  34. }
  35. if ($file_name) {
  36. $condition[] = array('file_name', '=', $file_name);
  37. }
  38. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  39. $return = $goods_resource_model->delGoodsResource($condition, $this->store_info['store_id']);
  40. if ($return) {
  41. ds_json_encode(10000, lang('ds_common_op_succ'));
  42. } else {
  43. ds_json_encode(10001, lang('ds_common_op_fail'));
  44. }
  45. }
  46. /**
  47. * 上传资源
  48. */
  49. public function resource_upload()
  50. {
  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. }