TechInfo.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. class TechInfo extends MongoAr {
  3. public $_id;//使用后台用户id作为保洁师信息表主键
  4. public $name;//姓名
  5. public $desc = '';//描述
  6. public $avatar;//头像
  7. public $favourable_count=0;//好评数
  8. public $order_count=0;//服务次数
  9. public $coverage = [];//服务商圈镜像字段
  10. public $business = [];//服务商圈
  11. public $status;//状态,同User表
  12. public $weixin_userid = '';//微信企业号内ID
  13. public $mobile = '';//手机号
  14. public $weixin_info = [];//微信企业号成员信息
  15. public $scheme = 'no_scheme';//提成方案
  16. public $service_type = [];//服务类型
  17. public static $status_option = [
  18. 1 => ['name' => '正常', 'wx' => 1],
  19. 0 => ['name' => '待审核', 'wx' => 0],
  20. -1 => ['name' => '已删除', 'wx' => 0],
  21. ];
  22. public function __construct($scenario='insert') {
  23. $this->setMongoDBComponent(Yii::app()->getComponent('mongodb_o2o'));
  24. parent::__construct($scenario);
  25. }
  26. public static function model($className=__CLASS__) {
  27. return parent::model($className);
  28. }
  29. public static function get($_id) {
  30. $criteria = new EMongoCriteria();
  31. $criteria->_id('==', intval($_id));
  32. $tech = self::model()->find($criteria);
  33. return $tech;
  34. }
  35. public static function getByUserid($userid) {
  36. $criteria = new EMongoCriteria();
  37. $criteria->weixin_userid = $userid;
  38. $tech = self::model()->find($criteria);
  39. return $tech;
  40. }
  41. public static function getByMobile($mobile) {
  42. $criteria = new EMongoCriteria();
  43. $criteria->mobile = $mobile;
  44. $tech = self::model()->find($criteria);
  45. return $tech;
  46. }
  47. public static function updateWeixinStatus($_id, $status) {
  48. $tech = self::get($_id);
  49. if ($tech) {
  50. $weixin_userid = $tech->weixin_userid;
  51. if ($weixin_userid) {
  52. $weixin_enable = self::$status_option[$status]['wx'];
  53. $user_data = [
  54. 'userid' => $weixin_userid,
  55. 'enable' => $weixin_enable,
  56. ];
  57. $option = WechatConfig::getIns()->getLinkOption();
  58. $secret = WechatConfig::getIns()->getSecret('admin_dev');
  59. $wechat = new QyWechat($option);
  60. $wechat->checkAuth($option['appid'], $secret);
  61. return $wechat->updateUser($user_data);
  62. } else {
  63. return false;
  64. }
  65. } else {
  66. return false;
  67. }
  68. }
  69. public function getCollectionName() {
  70. return 'technician_info';
  71. }
  72. public function parseRow($row, $output=[]) {
  73. $newRow = [];
  74. $newRow['_id'] = intval($row['_id']);
  75. $newRow['name'] = CommonFn::get_val_if_isset($row, 'name', '');
  76. $newRow['desc'] = CommonFn::get_val_if_isset($row, 'desc', '');
  77. $newRow['avatar'] = CommonFn::get_val_if_isset($row, 'avatar', '');
  78. $newRow['favourable_count'] = CommonFn::get_val_if_isset($row, 'favourable_count', 0);
  79. $newRow['order_count'] = CommonFn::get_val_if_isset($row, 'order_count', 0);
  80. $newRow['business'] = CommonFn::get_val_if_isset($row, 'business', []);
  81. $newRow['coverage'] = CommonFn::get_val_if_isset($row, 'coverage', []);
  82. $newRow['coverage_json'] = json_encode($newRow['coverage']);
  83. $newRow['status'] = CommonFn::get_val_if_isset($row, 'status', 0);
  84. $newRow['status_str'] = self::$status_option[$newRow['status']]['name'];
  85. $newRow['weixin_userid'] = CommonFn::get_val_if_isset($row, 'weixin_userid', '');
  86. $newRow['weixin_info'] = CommonFn::get_val_if_isset($row, 'wechat_info', (object)[]);
  87. $newRow['mobile'] = CommonFn::get_val_if_isset($row, 'mobile', '');
  88. $newRow['service_type'] = CommonFn::get_val_if_isset($row, 'service_type', []);
  89. $scheme = CommonFn::get_val_if_isset($row, 'scheme', 'no_scheme');
  90. $scheme_option = Commision::$scheme_option;
  91. if ($scheme == 'no_scheme') {
  92. $newRow['scheme'] = -1;
  93. $newRow['scheme_str'] = '未选择方案';
  94. } else {
  95. foreach ($scheme_option as $key => $item) {
  96. if ($item['alias'] == $scheme) {
  97. $newRow['scheme'] = $key;
  98. $newRow['scheme_str'] = $item['name'];
  99. break;
  100. }
  101. }
  102. }
  103. return $this->output($newRow, $output);
  104. }
  105. }