Sellerspec.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /*
  3. * 店铺规格值
  4. * 每个店铺都有对应分类下保存的规格值
  5. */
  6. namespace app\api\controller;
  7. use think\facade\Lang;
  8. /**
  9. * ============================================================================
  10. *
  11. * ============================================================================
  12. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  13. * 网站地址: https://www.valimart.net/
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 控制器
  18. */
  19. class Sellerspec extends MobileSeller {
  20. public function initialize() {
  21. parent::initialize();
  22. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerspec.lang.php');
  23. }
  24. /**
  25. * @api {POST} api/Sellerspec/save_spec 保存规格值
  26. * @apiVersion 1.0.0
  27. * @apiGroup Sellerspec
  28. *
  29. * @apiHeader {String} X-DS-KEY 卖家授权token
  30. *
  31. * @apiParam {Int} gc_id 商品分类ID
  32. * @apiParam {Object} spec_list 规格列表
  33. *
  34. * @apiSuccess {String} code 返回码,10000为成功
  35. * @apiSuccess {String} message 返回消息
  36. * @apiSuccess {Object} result 返回数据
  37. */
  38. public function save_spec() {
  39. $spec_list = input('post.spec_list/a');
  40. $gc_id = intval(input('post.gc_id'));
  41. if (empty($spec_list) || $gc_id <= 0) {
  42. ds_json_encode(10001, lang('param_error'));
  43. }
  44. $spec_model = model('spec');
  45. foreach ($spec_list as $sp_id => $spec) {
  46. $spvalue_ids = array();
  47. $specvalue_list = array();
  48. foreach ($spec['value'] as $val) {
  49. $val['spvalue_name'] = trim($val['spvalue_name']);
  50. if (!empty($val['spvalue_name'])) {
  51. if (isset($val['spvalue_id'])) {
  52. $spvalue_ids[] = $val['spvalue_id'];
  53. $condition = array();
  54. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  55. $condition[] = array('spvalue_id', '=', $val['spvalue_id']);
  56. $update = array(
  57. 'spvalue_name' => $val['spvalue_name'],
  58. );
  59. $spec_model->editSpecvalue($update, $condition);
  60. } else {
  61. $specvalue_list[] = array(
  62. 'spvalue_name' => $val['spvalue_name'],
  63. 'sp_id' => $sp_id,
  64. 'gc_id' => $gc_id,
  65. 'store_id' => $this->store_info['store_id'],
  66. 'spvalue_color' => '',
  67. 'spvalue_sort' => 255
  68. );
  69. }
  70. }
  71. }
  72. $condition = array();
  73. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  74. $condition[] = array('sp_id', '=', $sp_id);
  75. if (!empty($spvalue_ids)) {
  76. $condition[] = array('spvalue_id', 'not in', $spvalue_ids);
  77. }
  78. $spec_model->delSpecvalue($condition);
  79. if (!empty($specvalue_list)) {
  80. $spec_model->addSpecvalueALL($specvalue_list);
  81. }
  82. }
  83. ds_json_encode(10000, lang('ds_common_op_succ'));
  84. }
  85. }
  86. ?>