Worker.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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\allwin\model;
  9. use app\common\facade\Inform;
  10. use think\Model;
  11. class Worker extends Model{
  12. protected $pk = 'id';
  13. protected $table = 'ai_allwin_user_worker';
  14. //和主用户表绑定关系
  15. public function user(){
  16. return $this->hasOne('app\common\model\SystemUser','id','uid');
  17. }
  18. /**
  19. * 把已经是员工的用户排除在外返回用户列表
  20. */
  21. public static function selects($condition,int $miniapp_id){
  22. $user = self::where(['member_miniapp_id' => $miniapp_id])->field('uid')->select()->toArray();
  23. $uid = [];
  24. if(!empty($user)){
  25. $uid = array_column($user,'uid');
  26. }
  27. return model('SystemUser')->where($condition)->whereNotIn('id',$uid)->order('id desc')->paginate(10);
  28. }
  29. /**
  30. * 添加编辑
  31. * @param array $param 数组
  32. */
  33. public static function add(int $member_miniapp_id,array $ids){
  34. $data = [];
  35. $user = self::where(['member_miniapp_id' => $member_miniapp_id,'uid' => $ids])->field('uid')->select()->toArray();
  36. $uid = [];
  37. if(!empty($user)){
  38. $uid = array_column($user,'uid');
  39. }
  40. foreach ($ids as $key => $value) {
  41. if(!in_array($value,$uid)){
  42. $data[$key]['member_miniapp_id'] = $member_miniapp_id;
  43. $data[$key]['uid'] = $value;
  44. $data[$key]['create_time'] = time();
  45. $data[$key]['is_type'] = 0;
  46. $data[$key]['is_pass'] = 1;
  47. $data[$key]['is_lock'] = 0;
  48. $data[$key]['pay_state'] = 2;
  49. }
  50. //通知申请者到微信
  51. Inform::sms($value,$member_miniapp_id,['title' =>'业务进展通知','type' => '身份变更','state' => '成功','content' =>'您的身份已变更为合伙人']);
  52. }
  53. if(empty($data)){
  54. return;
  55. }
  56. foreach ($data as $key => $value) {
  57. AllwinUser::editer($value['uid'],0);
  58. }
  59. return self::insertAll($data);
  60. }
  61. //创建订单
  62. public static function createOrder(array $param){
  63. $info = self::where(['member_miniapp_id' => $param['member_miniapp_id'],'id' => $param['id']])->find();
  64. if($info){
  65. self::where(['id' => $info['id']])->update(['order_no' => $param['order_no'],'price' => $param['price']]);
  66. return false;
  67. }
  68. $data = [
  69. 'uid' => $param['uid'],
  70. 'is_pass' => 0,
  71. 'is_lock' => 0,
  72. 'is_type' => 1,
  73. 'order_no' => $param['order_no'],
  74. 'price' => $param['price'],
  75. 'pay_state' => 0,
  76. 'create_time' => time(),
  77. 'member_miniapp_id' => $param['member_miniapp_id']
  78. ];
  79. $rel = self::insert($data);
  80. return $rel ? $info : false;
  81. }
  82. public static function isLock(int $id){
  83. $result = self::where(['id' => $id])->field('is_lock')->find();
  84. $data['is_lock'] = $result['is_lock'] ? 0 : 1;
  85. return self::where('id',$id)->update($data);
  86. }
  87. public static function isPass(int $id,$member_miniapp_id){
  88. $result = self::where(['id' => $id])->field('is_pass,uid')->find();
  89. $data['is_pass'] = $result['is_pass'] ? 0 : 1;
  90. if($data['is_pass'] == 1) {
  91. //通知申请者到微信
  92. Inform::sms($result->uid,$member_miniapp_id,['title' =>'业务进展通知','type' => '合伙人申请','content' =>'您的合伙人申请已经通过审核','state' => '成功']);
  93. }
  94. return self::where('id',$id)->update($data);
  95. }
  96. }