Sellerspec.php 3.3 KB

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