Engineer.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 工程师管理
  7. */
  8. namespace app\bestbao\controller;
  9. use app\bestbao\model\BestbaoConfig;
  10. use app\bestbao\model\BestbaoEngineer;
  11. use app\common\model\SystemMemberBank;
  12. use app\common\model\SystemMemberBankBill;
  13. class Engineer extends Common{
  14. public function initialize(){
  15. parent::initialize();
  16. $this->assign('pathMaps',[['name'=>'售后工程师','url'=>'javascript:;']]);
  17. }
  18. /**
  19. * 列表
  20. */
  21. public function index(){
  22. $view['lists'] = BestbaoEngineer::where(['member_miniapp_id' => $this->member_miniapp_id])->order('sort desc,id desc')->paginate(20);
  23. return view()->assign($view);
  24. }
  25. /**
  26. * 编辑或添加
  27. * @return void
  28. */
  29. public function edit(){
  30. if(request()->isAjax()){
  31. $id = $this->request->param('id/d');
  32. $data = [
  33. 'uid' => $this->request->param('uid/d'),
  34. 'title' => $this->request->param('title/s'),
  35. 'occupation' => $this->request->param('occupation/s'),
  36. 'about' => $this->request->param('about/s'),
  37. 'level' => $this->request->param('level/d'),
  38. 'member_miniapp_id' => $this->member_miniapp_id,
  39. 'update_time' => time(),
  40. ];
  41. $validate = $this->validate($data,'Engineer.edit');
  42. if(true !== $validate){
  43. return json(['code'=>0,'msg'=>$validate]);
  44. }
  45. if($id > 0){
  46. $data['id'] = $id;
  47. $result = BestbaoEngineer::update($data);
  48. }else{
  49. $info = BestbaoConfig::where(['member_miniapp_id' => $this->member_miniapp_id])->find();
  50. if($this->member_miniapp->member_id > 0 && $info['type'] == 0 && !empty($info['price'])){
  51. $rel = SystemMemberBank::moneyJudge($this->member_miniapp->member_id,$info['price']); //判断余额
  52. if($rel){
  53. return enjson(0,'帐号余额不足,请联系应用服务商');
  54. }
  55. SystemMemberBankBill::create(['state' => 1,'money' => $info['price'],'member_id' => $this->member_miniapp->member_id,'message'=> '添加工程师费用','update_time' => time()]);
  56. SystemMemberBank::moneyUpdate($this->member_miniapp->member_id,-$info['price']);
  57. }
  58. $data['create_time'] = time();
  59. $result = BestbaoEngineer::create($data);
  60. }
  61. if($result){
  62. return enjson(200,'操作成功');
  63. }else{
  64. return enjson(0);
  65. }
  66. }else{
  67. $view['info'] = BestbaoEngineer::where(['id' => $this->request->param('id/d',0),'member_miniapp_id' => $this->member_miniapp_id])->find();
  68. return view()->assign($view);
  69. }
  70. }
  71. /**
  72. * 排序
  73. */
  74. public function sort(){
  75. if(request()->isAjax()){
  76. $data = [
  77. 'sort' => $this->request->param('sort/d'),
  78. 'id' => $this->request->param('id/d'),
  79. ];
  80. $validate = $this->validate($data,'Engineer.sort');
  81. if(true !== $validate){
  82. return json(['code'=>0,'msg'=>$validate]);
  83. }
  84. $result = BestbaoEngineer::update(['sort'=>$data['sort']],['id' => $data['id']]);
  85. if($result){
  86. return enjson(200);
  87. }else{
  88. return enjson(0);
  89. }
  90. }
  91. }
  92. //删除
  93. public function delete(int $id){
  94. $result = BestbaoEngineer::destroy($id);
  95. if($result){
  96. return enjson(200);
  97. }else{
  98. return enjson(403,'删除失败');
  99. }
  100. }
  101. }