MemberauthgroupController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\MemberAuthGroup;
  5. use app\model\MemberCommission;
  6. use app\model\Coupon;
  7. use app\model\Goods;
  8. class MemberauthgroupController extends Base
  9. {
  10. function index()
  11. {
  12. $weid = weid();
  13. $keyword = input('post.keyword', '', 'serach_in');
  14. $query = MemberAuthGroup::where(['weid' => $weid]);
  15. if (!empty($keyword)) {
  16. $query->where('title', 'like', '%' . $keyword . '%');
  17. }
  18. $datalist = $query->order('sort asc,id asc')->select()->toArray();
  19. $data['data'] = $datalist;
  20. return $this->json($data);
  21. }
  22. function listUpdate()
  23. {
  24. $data = only('id,is_lookprice,is_buyright,is_default,status,sort');
  25. if (!$data['id']) throw new ValidateException('参数错误');
  26. MemberAuthGroup::update($data);
  27. return $this->json(['msg' => '操作成功']);
  28. }
  29. public function update()
  30. {
  31. $id = $this->request->post('id');
  32. $data = input('post.');
  33. if (empty($id)) {
  34. $data['weid'] = weid();
  35. try {
  36. $res = MemberAuthGroup::create($data);
  37. if ($res->id && empty($data['sort'])) {
  38. MemberAuthGroup::update(['sort' => $res->id, 'id' => $res->id]);
  39. }
  40. $this->_synupdata($data);
  41. } catch (\Exception $e) {
  42. throw new ValidateException($e->getMessage());
  43. }
  44. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  45. } else {
  46. try {
  47. MemberAuthGroup::update($data);
  48. $this->_synupdata($data);
  49. } catch (\Exception $e) {
  50. throw new ValidateException($e->getMessage());
  51. }
  52. return $this->json(['msg' => '修改成功']);
  53. }
  54. }
  55. function _synupdata($data)
  56. {
  57. MemberCommission::where('mgid', $data['id'])->delete();
  58. if (!empty($data['membercommission'])) {
  59. foreach ($data['membercommission'] as $mcvo) {
  60. if ($mcvo['return_percent'] > 0) {
  61. MemberCommission::create([
  62. 'mgid' => (int) $data['id'],
  63. 'commission_method' => $data['commission_method'],
  64. 'roletype' => $mcvo['roletype'],
  65. 'return_percent' => $mcvo['return_percent']
  66. ]);
  67. }
  68. }
  69. }
  70. }
  71. function getInfo()
  72. {
  73. $id = $this->request->post('id', '', 'serach_in');
  74. if (!$id) throw new ValidateException('参数错误');
  75. $data = MemberAuthGroup::field('*')->find($id)->toArray();
  76. if (!empty($data['upgrade_goods_id'])) {
  77. $upgrade_goods = Goods::find($data['upgrade_goods_id']);
  78. if (!empty($upgrade_goods)) {
  79. $data['upgrade_goods'] = $upgrade_goods->toArray();
  80. }
  81. }
  82. $member_commission = MemberCommission::where('mgid', $id)->select()->toArray();
  83. foreach ($member_commission as $key => $vo) {
  84. $mc[$vo['roletype']] = $vo['return_percent'];
  85. }
  86. $data['membercommission'] = getCommissionType();
  87. foreach ($data['membercommission'] as &$vo) {
  88. $vo['return_percent'] = $mc[$vo['roletype']];
  89. }
  90. return $this->json(['data' => $data]);
  91. }
  92. function delete()
  93. {
  94. return $this->del(new MemberAuthGroup());
  95. }
  96. function getField()
  97. {
  98. $data['couponarray'] = Coupon::getpcarray(2);
  99. return $this->json(['data' => $data]);
  100. }
  101. function getCommissionType()
  102. {
  103. $data['membercommission'] = getCommissionType();
  104. return $this->json(['data' => $data]);
  105. }
  106. }